]> Lady’s Gitweb - x_status_git/blob - status.html
Use titles in prev & next links on statuses
[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 const index = `${new URL(".", location).toString().slice(0, -1)}.jsonld`
19 fetch(index)
20 .then($ => $.json())
21 .then(meta => {
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()) })
25 .then(meta => {
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 =
38 [ "A(n) "
39 , subject
40 ? (subjectLink => {
41 subjectLink.textContent = subject
42 subjectLink.href = meta["@id"]
43 return subjectLink })(document.createElement("a"))
44 : "status"
45 , " update" ]
46 if (creator) {
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
55 footer
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()
64 if (n > 0) {
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), "…")
71 : prevTitle
72 else {
73 const prevText = (() => {
74 try {
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"
80 , top: "-2px"
81 , height: "1px"
82 , width: "1px"
83 , overflow: "hidden" })
84 document.body.appendChild(div)
85 const text = div.innerText
86 document.body.removeChild(div)
87 return text }
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), "…")
92 : prevText } }
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), "…")
100 : nextTitle
101 else {
102 const nextText = (() => {
103 try {
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"
109 , top: "-2px"
110 , height: "1px"
111 , width: "1px"
112 , overflow: "hidden" })
113 document.body.appendChild(div)
114 const text = div.innerText
115 document.body.removeChild(div)
116 return text }
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), "…")
121 : nextText } }
122 nav.appendChild(document.createTextNode("."))
123 if (title) {
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) })
132 </SCRIPT>
This page took 0.112343 seconds and 5 git commands to generate.