]> Lady’s Gitweb - x_status_git/blob - topic.html
Add backnavigation to various listings
[x_status_git] / topic.html
1 <!dOcTyPe html>
2 <META Charset=utf-8>
3 <TITLE>Topic Feed</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 </STYLE>
7 <H1>Topic Feed</H1>
8 <NAV><P><A HRef=/>Home</A></P><DL></DL></NAV>
9 <SCRIPT Type=module>
10 const nav = document.body.querySelector("nav")
11 const dl = nav.querySelector("dl")
12 const parser = new DOMParser
13 if (location.pathname.startsWith("/topics/")) {
14 const a = nav
15 .insertBefore(document.createElement("p"), dl)
16 .appendChild(document.createElement("a"))
17 a.href = "/topics/"
18 a.textContent = "Topics" }
19 fetch(`${location}.jsonld`)
20 .then($ => $.json())
21 .then(meta => {
22 const topic = meta.subject || meta["@id"].split("/").pop()
23 document.title = topic
24 document.body.querySelector("h1").textContent = "subject" in meta
25 ? `#${topic}`
26 : `@${topic}`
27 const { first, prev, next, current, items } = meta
28 if (first && first != location && first != prev) {
29 const a = nav
30 .insertBefore(document.createElement("p"), dl)
31 .appendChild(document.createElement("a"))
32 a.href = first
33 a.textContent = "First Page" }
34 if (prev) {
35 const a = nav
36 .insertBefore(document.createElement("p"), dl)
37 .appendChild(document.createElement("a"))
38 a.href = prev
39 a.textContent = "Previous Page" }
40 let prevDate = undefined
41 for (const status of items) {
42 if (status.created != prevDate) dl.appendChild(document.createElement("dt")).textContent = status.created
43 const a = dl
44 .appendChild(document.createElement("dd"))
45 .appendChild(document.createElement("a"))
46 a.href = status["@id"]
47 const summaryText = (() => {
48 try {
49 const d = parser.parseFromString(status.content, "application/xhtml+xml")
50 const div = document.createElement("div")
51 div.appendChild(document.importNode(d.documentElement, true))
52 Object.assign(div.style,
53 { position: "absolute"
54 , top: "-2px"
55 , height: "1px"
56 , width: "1px"
57 , overflow: "hidden" })
58 document.body.appendChild(div)
59 const text = div.innerText
60 document.body.removeChild(div)
61 return text }
62 catch { } })() || "";
63 const chars = Array.from(summaryText.trim().replaceAll(/\s+/gu, " "))
64 a.textContent = chars.length > 28
65 ? "".concat(...chars.slice(0, 27), "…")
66 : summaryText || status.identifier }
67 if (next) {
68 const a = nav
69 .appendChild(document.createElement("p"))
70 .appendChild(document.createElement("a"))
71 a.href = next
72 a.textContent = "Next Page" }
73 if (current && current != location && current != next) {
74 const a = nav
75 .appendChild(document.createElement("p"))
76 .appendChild(document.createElement("a"))
77 a.href = current
78 a.textContent = "Latest Page" } })
79 </SCRIPT>
This page took 0.064751 seconds and 5 git commands to generate.