X-Git-Url: https://git.ladys.computer/x_status_git/blobdiff_plain/3394dfeb4194ca630becdb4d34538a3370d47ca8..7ecd84bf3f8e1f7c9b3f3780a3083e5151f455b8:/status.html?ds=inline diff --git a/status.html b/status.html index e1cbaee..dbc899c 100644 --- a/status.html +++ b/status.html @@ -6,6 +6,7 @@ body{ Display: Grid; Box-Sizing: Border-Box; Margin: Auto; Padding-Inline: 1REM; article{ Font-Size: Larger } summary{ Padding-Block: 1REM; Font-Weight: Bold } details[open]>summary{ Border-Block-End: Thin Solid } +header{ Border-Block-End: Thin Solid; Padding-Block: 1REM; Text-Align: Start } footer{ Border-Block-Start: Thin Solid; Padding-Block: 1REM; Text-Align: End } footer p{ Margin-Block: 0 .5REM } footer time:Not([datetime]), @@ -14,10 +15,15 @@ footer small{ Font-Size: Inherit; Font-Style: Italic } <BODY> <SCRIPT Type=module> const parser = new DOMParser -fetch(`${new URL(".", location).toString().slice(0, -1)}.jsonld`) +const index = `${new URL(".", location).toString().slice(0, -1)}.jsonld` +fetch(index) .then($ => $.json()) .then(meta => { const { items } = meta + if (items.find($ => new URL($["@id"]).pathname === location.pathname)) return meta + else return fetch(index, { cache: "reload" }).then($ => $.json()) }) +.then(meta => { + const { items, subject } = meta const n = items.findIndex($ => new URL($["@id"]).pathname === location.pathname) const status = items[n] const src = status.content @@ -26,14 +32,26 @@ fetch(`${new URL(".", location).toString().slice(0, -1)}.jsonld`) document.title = creator ? `Status by ${creator.name} @ ${status.created}` : `Status @ ${created}` + const header = document.createElement("header") const footer = document.createElement("footer") - const authorshipP = footer.appendChild(document.createElement("p")) + const headerChildren = + [ "A(n) " + , subject + ? (subjectLink => { + subjectLink.textContent = subject + subjectLink.href = meta["@id"] + return subjectLink })(document.createElement("a")) + : "status" + , " update" ] if (creator) { - const authorLink = authorshipP.appendChild(document.createElement("a")) - authorLink.href = creator["@id"] + const authorLink = document.createElement("@id" in creator ? "a" : "span") + if (authorLink.localName == "a") authorLink.href = creator["@id"] authorLink.textContent = creator.name - authorshipP.appendChild(document.createTextNode(" @ ")) } - authorshipP.appendChild(document.createElement("time")).textContent = created + headerChildren.push(" by ", authorLink, "…") } + else headerChildren.push("…") + header.append(...headerChildren) + const timestampP = footer.appendChild(document.createElement("p")) + timestampP.appendChild(document.createElement("time")).textContent = created footer .appendChild(document.createElement("p")) .appendChild(document.createElement("small")) @@ -47,50 +65,60 @@ fetch(`${new URL(".", location).toString().slice(0, -1)}.jsonld`) nav.appendChild(document.createTextNode("; Previous: ")) const prevLink = nav.appendChild(document.createElement("a")) prevLink.href = items[n - 1]["@id"] - const prevText = (() => { - try { - const prevD = parser.parseFromString(items[n - 1].content, "application/xhtml+xml") - const div = document.createElement("div") - div.appendChild(document.importNode(prevD.documentElement, true)) - Object.assign(div.style, - { position: "absolute" - , top: "-2px" - , height: "1px" - , width: "1px" - , overflow: "hidden" }) - document.body.appendChild(div) - const text = div.innerText - document.body.removeChild(div) - return text } - catch { } })() ?? items[n + 1].created; - const prevChars = Array.from(prevText.trim().replaceAll(/\s+/gu, " ")) - prevLink.textContent = prevChars.length > 28 - ? "".concat(...prevChars.slice(0, 27), "…") - : prevText } + const { title: prevTitle } = items[n - 1] + if (prevTitle) prevLink.textContent = prevTitle.length > 28 + ? "".concat(...prevTitle.slice(0, 27), "…") + : prevTitle + else { + const prevText = (() => { + try { + const prevD = parser.parseFromString(items[n - 1].content, "application/xhtml+xml") + const div = document.createElement("div") + div.appendChild(document.importNode(prevD.documentElement, true)) + Object.assign(div.style, + { position: "absolute" + , top: "-2px" + , height: "1px" + , width: "1px" + , overflow: "hidden" }) + document.body.appendChild(div) + const text = div.innerText + document.body.removeChild(div) + return text } + catch { } })() ?? items[n + 1].created; + const prevChars = Array.from(prevText.trim().replaceAll(/\s+/gu, " ")) + prevLink.textContent = prevChars.length > 28 + ? "".concat(...prevChars.slice(0, 27), "…") + : prevText } } if (n < items.length - 1) { nav.appendChild(document.createTextNode("; Next: ")) const nextLink = nav.appendChild(document.createElement("a")) nextLink.href = items[n + 1]["@id"] - const nextText = (() => { - try { - const nextD = parser.parseFromString(items[n + 1].content, "application/xhtml+xml") - const div = document.createElement("div") - div.appendChild(document.importNode(nextD.documentElement, true)) - Object.assign(div.style, - { position: "absolute" - , top: "-2px" - , height: "1px" - , width: "1px" - , overflow: "hidden" }) - document.body.appendChild(div) - const text = div.innerText - document.body.removeChild(div) - return text } - catch { } })() ?? items[n + 1].created; - const nextChars = Array.from(nextText.trim().replaceAll(/\s+/gu, " ")) - nextLink.textContent = nextChars.length > 28 - ? "".concat(...nextChars.slice(0, 27), "…") - : nextText } + const { title: nextTitle } = items[n + 1] + if (nextTitle) nextLink.textContent = nextTitle.length > 28 + ? "".concat(...nextTitle.slice(0, 27), "…") + : nextTitle + else { + const nextText = (() => { + try { + const nextD = parser.parseFromString(items[n + 1].content, "application/xhtml+xml") + const div = document.createElement("div") + div.appendChild(document.importNode(nextD.documentElement, true)) + Object.assign(div.style, + { position: "absolute" + , top: "-2px" + , height: "1px" + , width: "1px" + , overflow: "hidden" }) + document.body.appendChild(div) + const text = div.innerText + document.body.removeChild(div) + return text } + catch { } })() ?? items[n + 1].created; + const nextChars = Array.from(nextText.trim().replaceAll(/\s+/gu, " ")) + nextLink.textContent = nextChars.length > 28 + ? "".concat(...nextChars.slice(0, 27), "…") + : nextText } } nav.appendChild(document.createTextNode(".")) if (title) { const wrapper = document.createElement("article") @@ -99,6 +127,6 @@ fetch(`${new URL(".", location).toString().slice(0, -1)}.jsonld`) const summary = details.appendChild(document.createElement("summary")) summary.textContent = title details.append(...document.importNode(article, true).childNodes) - document.body.replaceChildren(wrapper, footer) } - else document.body.replaceChildren(document.importNode(article, true), footer) }) + document.body.replaceChildren(header, wrapper, footer) } + else document.body.replaceChildren(header, document.importNode(article, true), footer) }) </SCRIPT>