5 body{ Display: Grid; Box-Sizing: Border-Box; Margin: Auto; Padding-Inline:
1REM; Min-Block-Size:
100VH; Inline-Size:
100%; Max-Inline-Size:
45REM; Align-Content: Center; Justify-Content: Stretch; Font-Family: Sans-Serif }
6 article{ Font-Size: Larger }
7 summary{ Padding-Block:
1REM; Font-Weight: Bold }
8 details[open]
>summary{ Border-Block-End: Thin Solid }
9 header{ Border-Block-End: Thin Solid; Padding-Block:
1REM; Text-Align: Start }
10 footer{ Border-Block-Start: Thin Solid; Padding-Block:
1REM; Text-Align: End }
11 footer p{ Margin-Block:
0 .5REM }
12 footer time:Not([datetime]),
13 footer small{ Font-Size: Inherit; Font-Style: Italic }
17 const parser = new DOMParser
18 const index = `${new URL(
".", location).toString().slice(
0, -
1)}.jsonld`
22 const { items } = meta
23 if (items.find($ =
> new URL($[
"@id"]).pathname === location.pathname)) return meta
24 else return fetch(index, { cache:
"reload" }).then($ =
> $.json()) })
26 const { items, subject } = meta
27 const n = items.findIndex($ =
> new URL($[
"@id"]).pathname === location.pathname)
28 const status = items[n]
29 const src = status.content
30 const { documentElement: article } = parser.parseFromString(src,
"application/xhtml+xml")
31 const { creator, created, title } = status
32 document.title = creator
33 ? `Status by ${creator.name} @ ${status.created}`
34 : `Status @ ${created}`
35 const header = document.createElement(
"header")
36 const footer = document.createElement(
"footer")
37 const headerChildren =
41 subjectLink.textContent = subject
42 subjectLink.href = meta[
"@id"]
43 return subjectLink })(document.createElement(
"a"))
47 const authorLink = document.createElement(
"@id" in creator ?
"a" :
"span")
48 if (authorLink.localName ==
"a") authorLink.href = creator[
"@id"]
49 authorLink.textContent = creator.name
50 headerChildren.push(
" by ", authorLink,
"…") }
51 else headerChildren.push(
"…")
52 header.append(...headerChildren)
53 const timestampP = footer.appendChild(document.createElement(
"p"))
54 timestampP.appendChild(document.createElement(
"time")).textContent = created
56 .appendChild(document.createElement(
"p"))
57 .appendChild(document.createElement(
"small"))
58 .textContent = status.identifier
59 const nav = footer.appendChild(document.createElement(
"nav"))
60 nav.appendChild(document.createTextNode(
"Up: "))
61 const upLink = nav.appendChild(document.createElement(
"a"))
62 upLink.href = meta[
"@id"]
63 upLink.textContent = meta.subject || meta[
"@id"].split(
"/").pop()
65 nav.appendChild(document.createTextNode(
"; Previous: "))
66 const prevLink = nav.appendChild(document.createElement(
"a"))
67 prevLink.href = items[n -
1][
"@id"]
68 const { title: prevTitle } = items[n -
1]
69 if (prevTitle) prevLink.textContent = prevTitle.length
> 28
70 ?
"".concat(...prevTitle.slice(
0,
27),
"…")
73 const prevText = (() =
> {
75 const prevD = parser.parseFromString(items[n -
1].content,
"application/xhtml+xml")
76 const div = document.createElement(
"div")
77 div.appendChild(document.importNode(prevD.documentElement, true))
78 Object.assign(div.style,
79 { position:
"absolute"
83 , overflow:
"hidden" })
84 document.body.appendChild(div)
85 const text = div.innerText
86 document.body.removeChild(div)
88 catch { } })() ?? items[n +
1].created;
89 const prevChars = Array.from(prevText.trim().replaceAll(/\s+/gu,
" "))
90 prevLink.textContent = prevChars.length
> 28
91 ?
"".concat(...prevChars.slice(
0,
27),
"…")
93 if (n < items.length -
1) {
94 nav.appendChild(document.createTextNode(
"; Next: "))
95 const nextLink = nav.appendChild(document.createElement(
"a"))
96 nextLink.href = items[n +
1][
"@id"]
97 const { title: nextTitle } = items[n +
1]
98 if (nextTitle) nextLink.textContent = nextTitle.length
> 28
99 ?
"".concat(...nextTitle.slice(
0,
27),
"…")
102 const nextText = (() =
> {
104 const nextD = parser.parseFromString(items[n +
1].content,
"application/xhtml+xml")
105 const div = document.createElement(
"div")
106 div.appendChild(document.importNode(nextD.documentElement, true))
107 Object.assign(div.style,
108 { position:
"absolute"
112 , overflow:
"hidden" })
113 document.body.appendChild(div)
114 const text = div.innerText
115 document.body.removeChild(div)
117 catch { } })() ?? items[n +
1].created;
118 const nextChars = Array.from(nextText.trim().replaceAll(/\s+/gu,
" "))
119 nextLink.textContent = nextChars.length
> 28
120 ?
"".concat(...nextChars.slice(
0,
27),
"…")
122 nav.appendChild(document.createTextNode(
"."))
124 const wrapper = document.createElement(
"article")
125 const details = wrapper.appendChild(document.createElement(
"details"))
126 details.setAttribute(
"open",
"")
127 const summary = details.appendChild(document.createElement(
"summary"))
128 summary.textContent = title
129 details.append(...document.importNode(article, true).childNodes)
130 document.body.replaceChildren(header, wrapper, footer) }
131 else document.body.replaceChildren(header, document.importNode(article, true), footer) })