]> Lady’s Gitweb - x_status_git/blob - status.html
Fix index.html to only fetch topics once
[x_status_git] / status.html
1 <!dOcTyPe hTmL>
2 <HTML Lang=en>
3 <TITLE>Status</TITLE>
4 <STYLE>
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 }
14 </STYLE>
15 <BODY>
16 <SCRIPT Type=module>
17 const parser = new DOMParser
18 fetch(`${new URL(".", location).toString().slice(0, -1)}.jsonld`)
19 .then($ => $.json())
20 .then(meta => {
21 const { items, subject } = meta
22 const n = items.findIndex($ => new URL($["@id"]).pathname === location.pathname)
23 const status = items[n]
24 const src = status.content
25 const { documentElement: article } = parser.parseFromString(src, "application/xhtml+xml")
26 const { creator, created, title } = status
27 document.title = creator
28 ? `Status by ${creator.name} @ ${status.created}`
29 : `Status @ ${created}`
30 const header = document.createElement("header")
31 const footer = document.createElement("footer")
32 const headerChildren =
33 [ "A(n) "
34 , subject
35 ? (subjectLink => {
36 subjectLink.textContent = subject
37 subjectLink.href = meta["@id"]
38 return subjectLink })(document.createElement("a"))
39 : "status"
40 , " update" ]
41 if (creator) {
42 const authorLink = document.createElement("@id" in creator ? "a" : "span")
43 if (authorLink.localName == "a") authorLink.href = creator["@id"]
44 authorLink.textContent = creator.name
45 headerChildren.push(" by ", authorLink, "…") }
46 else headerChildren.push("…")
47 header.append(...headerChildren)
48 const timestampP = footer.appendChild(document.createElement("p"))
49 timestampP.appendChild(document.createElement("time")).textContent = created
50 footer
51 .appendChild(document.createElement("p"))
52 .appendChild(document.createElement("small"))
53 .textContent = status.identifier
54 const nav = footer.appendChild(document.createElement("nav"))
55 nav.appendChild(document.createTextNode("Up: "))
56 const upLink = nav.appendChild(document.createElement("a"))
57 upLink.href = meta["@id"]
58 upLink.textContent = meta.subject || meta["@id"].split("/").pop()
59 if (n > 0) {
60 nav.appendChild(document.createTextNode("; Previous: "))
61 const prevLink = nav.appendChild(document.createElement("a"))
62 prevLink.href = items[n - 1]["@id"]
63 const prevText = (() => {
64 try {
65 const prevD = parser.parseFromString(items[n - 1].content, "application/xhtml+xml")
66 const div = document.createElement("div")
67 div.appendChild(document.importNode(prevD.documentElement, true))
68 Object.assign(div.style,
69 { position: "absolute"
70 , top: "-2px"
71 , height: "1px"
72 , width: "1px"
73 , overflow: "hidden" })
74 document.body.appendChild(div)
75 const text = div.innerText
76 document.body.removeChild(div)
77 return text }
78 catch { } })() ?? items[n + 1].created;
79 const prevChars = Array.from(prevText.trim().replaceAll(/\s+/gu, " "))
80 prevLink.textContent = prevChars.length > 28
81 ? "".concat(...prevChars.slice(0, 27), "…")
82 : prevText }
83 if (n < items.length - 1) {
84 nav.appendChild(document.createTextNode("; Next: "))
85 const nextLink = nav.appendChild(document.createElement("a"))
86 nextLink.href = items[n + 1]["@id"]
87 const nextText = (() => {
88 try {
89 const nextD = parser.parseFromString(items[n + 1].content, "application/xhtml+xml")
90 const div = document.createElement("div")
91 div.appendChild(document.importNode(nextD.documentElement, true))
92 Object.assign(div.style,
93 { position: "absolute"
94 , top: "-2px"
95 , height: "1px"
96 , width: "1px"
97 , overflow: "hidden" })
98 document.body.appendChild(div)
99 const text = div.innerText
100 document.body.removeChild(div)
101 return text }
102 catch { } })() ?? items[n + 1].created;
103 const nextChars = Array.from(nextText.trim().replaceAll(/\s+/gu, " "))
104 nextLink.textContent = nextChars.length > 28
105 ? "".concat(...nextChars.slice(0, 27), "…")
106 : nextText }
107 nav.appendChild(document.createTextNode("."))
108 if (title) {
109 const wrapper = document.createElement("article")
110 const details = wrapper.appendChild(document.createElement("details"))
111 details.setAttribute("open", "")
112 const summary = details.appendChild(document.createElement("summary"))
113 summary.textContent = title
114 details.append(...document.importNode(article, true).childNodes)
115 document.body.replaceChildren(header, wrapper, footer) }
116 else document.body.replaceChildren(header, document.importNode(article, true), footer) })
117 </SCRIPT>
This page took 0.073924 seconds and 5 git commands to generate.