mirror of
https://gitdab.com/cadence/breezewiki.git
synced 2026-03-05 13:40:27 -05:00
Better theme, better errors
This commit is contained in:
@@ -34,6 +34,20 @@ window.proxy = new Proxy(jsonpData, {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// *** Page theme
|
||||||
|
|
||||||
|
// Try to make it a bit more accurate. Normally this is done server-side by sending a `theme=x` cookie with the parse request. But that's not possible in jsonp mode, and there's no equivalent URL query string to set the theme.
|
||||||
|
// Helps on Minecraft wiki. Might not be complete on some wikis.
|
||||||
|
cookieStore.get("theme").then(cookie => {
|
||||||
|
if (cookie && cookie.value !== "default") {
|
||||||
|
document.body.classList.remove("theme-fandomdesktop-light")
|
||||||
|
document.body.classList.remove("theme-fandomdesktop-dark")
|
||||||
|
document.body.removeAttribute("data-theme")
|
||||||
|
document.body.classList.add(`theme-fandomdesktop-${cookie.value}`)
|
||||||
|
document.body.setAttribute("data-theme", cookie.value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// *** Data upload and download
|
// *** Data upload and download
|
||||||
|
|
||||||
async function cont() {
|
async function cont() {
|
||||||
@@ -45,6 +59,19 @@ async function cont() {
|
|||||||
|
|
||||||
const uploadFraction = 0.7
|
const uploadFraction = 0.7
|
||||||
|
|
||||||
|
const pkg = {
|
||||||
|
url: "/api/render/wiki",
|
||||||
|
init: {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({
|
||||||
|
data: jsonpData.wikipage,
|
||||||
|
siteinfo: jsonpData.siteinfo,
|
||||||
|
wikiname: BWData.wikiname,
|
||||||
|
path: BWData.path
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Upload progress
|
// Upload progress
|
||||||
xhr.upload.addEventListener("progress", event => {
|
xhr.upload.addEventListener("progress", event => {
|
||||||
if (event.lengthComputable) {
|
if (event.lengthComputable) {
|
||||||
@@ -61,8 +88,11 @@ async function cont() {
|
|||||||
|
|
||||||
xhr.addEventListener("load", () => {
|
xhr.addEventListener("load", () => {
|
||||||
console.log(xhr)
|
console.log(xhr)
|
||||||
|
if (xhr.status === 500) return fetch(pkg.url, pkg.init).then(res => res.text()).then(error)
|
||||||
|
// page -> #content
|
||||||
const imported = document.importNode(xhr.responseXML.getElementById("content"), true)
|
const imported = document.importNode(xhr.responseXML.getElementById("content"), true)
|
||||||
document.getElementById("content").replaceWith(imported)
|
document.getElementById("content").replaceWith(imported)
|
||||||
|
// <head>
|
||||||
document.title = xhr.responseXML.title
|
document.title = xhr.responseXML.title
|
||||||
for (const e of xhr.responseXML.head.children) {
|
for (const e of xhr.responseXML.head.children) {
|
||||||
const alreadyImported = [...document.querySelectorAll("link[href]")].map(e => e.href)
|
const alreadyImported = [...document.querySelectorAll("link[href]")].map(e => e.href)
|
||||||
@@ -71,6 +101,7 @@ async function cont() {
|
|||||||
document.head.appendChild(imported)
|
document.head.appendChild(imported)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Redirects
|
||||||
const redirectTo = document.querySelector("#content .redirectMsg a")
|
const redirectTo = document.querySelector("#content .redirectMsg a")
|
||||||
if (redirectTo) {
|
if (redirectTo) {
|
||||||
redirectTo.click()
|
redirectTo.click()
|
||||||
@@ -78,28 +109,20 @@ async function cont() {
|
|||||||
loaded.value = true
|
loaded.value = true
|
||||||
})
|
})
|
||||||
|
|
||||||
xhr.open("POST", "/api/render/wiki")
|
xhr.open(pkg.init.method, pkg.url)
|
||||||
xhr.responseType = "document"
|
xhr.responseType = "document"
|
||||||
xhr.send(JSON.stringify({
|
xhr.send(pkg.init.body);
|
||||||
data: jsonpData.wikipage,
|
|
||||||
siteinfo: jsonpData.siteinfo,
|
|
||||||
wikiname: BWData.wikiname,
|
|
||||||
path: BWData.path
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function error(data) {
|
function error(data) {
|
||||||
const eContent = document.getElementById("content")
|
const eContent = document.getElementById("content")
|
||||||
while (eContent.childNodes[0] !== undefined) eContent.childNodes[0].remove() // clear out loading indicators
|
while (eContent.childNodes[0] !== undefined) eContent.childNodes[0].remove() // clear out loading indicators
|
||||||
document.title = `Error | BreezeWiki`
|
document.title = `Error | BreezeWiki`
|
||||||
render(html`
|
if (typeof data === "string") {
|
||||||
${data.error.code === "missingtitle"
|
render(html`<p><strong>BreezeWiki ran into an error on this page.</strong></p><p>Try reloading the page.</p><p>If this keeps happening, you could <a href="mailto:~cadence/breezewiki-discuss@lists.sr.ht">send a public bug report</a>. Please include the following information:</p><pre>URL: ${window.location.href}${"\n"}${data}</pre>`, eContent)
|
||||||
? html`<p><strong>This page doesn't exist on Fandom.</strong></p>`
|
} else if (data.error.code === "missingtitle") {
|
||||||
: html`
|
render(html`<p><strong>This page doesn't exist on Fandom.</strong></p><p><small><a href="/${BWData.wikiname}/wiki/Main_Page">Return to the homepage?</a></small></p>`, eContent)
|
||||||
<p>BreezeWiki wasn't able to load this page.</p>
|
} else {
|
||||||
<p><strong>${data.error.code}: ${data.error.info}</strong></p>
|
render(html`<p>BreezeWiki wasn't able to load this page.</p><p><strong>${data.error.code}: ${data.error.info}</strong></p>`, eContent)
|
||||||
`
|
}
|
||||||
}
|
|
||||||
<p><small><a href="/${BWData.wikiname}/wiki/Main_Page">Return to the homepage?</a></small></p>
|
|
||||||
`, eContent)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user