]> Lady’s Gitweb - x_status_git/blob - index.html
Fix index.html to only fetch topics once
[x_status_git] / index.html
1 <!dOcTyPe html>
2 <HTML Lang=en>
3 <TITLE>Index</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 #status{ Font-Size: Larger }
7 #topics{ Display: Grid; Margin-Block: 1REM; Grid: Auto-Flow / 1FR 1FR; Gap: 0 1REM }
8 #topics h2{ Margin-Block-End: 0; Grid-Column: 1 / Span 2; Text-Align: Center }
9 #topics h2:Last-Child{ Display: None }
10 div.STATUS{ Border: Thin Solid; Padding-Inline: 1REM; Border-Radius: .5REM }
11 summary{ Padding-Block: 1REM; Font-Weight: Bold }
12 details[open]>summary{ Border-Block-End: Thin Solid }
13 footer{ Border-Block-Start: Thin Solid; Padding-Block: 1REM; Font-Size: Smaller; Text-Align: End }
14 footer p{ Margin-Block: 0 .5REM }
15 footer time:Not([datetime]),
16 footer small{ Font-Size: Inherit; Font-Style: Italic }
17 </STYLE>
18 <H1>Index</H1>
19 <DIV Class=STATUS ID=status>
20 </DIV>
21 <SECTION ID=topics>
22 <H2>Topics</H2>
23 </SECTION>
24 <SCRIPT Type=module>
25 const parser = new DOMParser
26 document.title = location.hostname
27 document.documentElement.querySelector("body>h1").textContent = location.hostname
28 const renderLatest = (meta, container) => {
29 const { feed, items } = meta
30 const status = items.pop()
31 const src = status.content
32 const { documentElement: article } = parser.parseFromString(src, "application/xhtml+xml")
33 const footer = document.createElement("footer")
34 const authorshipP = footer.appendChild(document.createElement("p"))
35 const { creator, title } = status
36 if (creator) {
37 const authorLink = authorshipP.appendChild(document.createElement("a"))
38 authorLink.href = creator["@id"]
39 authorLink.textContent = creator.name
40 authorshipP.appendChild(document.createTextNode(" @ ")) }
41 authorshipP.appendChild(document.createElement("time")).textContent = status.created
42 const nav = footer.appendChild(document.createElement("nav"))
43 const permalink = nav.appendChild(document.createElement("a"))
44 permalink.href = status["@id"]
45 permalink.textContent = "Permalink."
46 nav.appendChild(document.createTextNode(" "))
47 const upLink = nav.appendChild(document.createElement("a"))
48 upLink.href = meta["@id"]
49 upLink.textContent = `See more ${ status.subject ? `“${status.subject}” posts` : "statuses" }.`
50 if (title) {
51 const wrapper = document.createElement("article")
52 const details = wrapper.appendChild(document.createElement("details"))
53 details.setAttribute("open", "")
54 const summary = details.appendChild(document.createElement("summary"))
55 summary.textContent = title
56 details.append(...document.importNode(article, true).childNodes)
57 container.replaceChildren(wrapper, footer) }
58 else container.replaceChildren(document.importNode(article, true), footer) }
59 fetch("statuses.jsonld")
60 .then($ => $.json())
61 .then(meta => fetch(`${meta.current}.jsonld`))
62 .then($ => $.json())
63 .then(meta => renderLatest(meta, document.getElementById("status")))
64 fetch("topics.jsonld")
65 .then($ => $.json())
66 .then(meta => {
67 const topics = document.getElementById("topics")
68 for (const topicID of meta.items.map($ => $["@id"] ?? $)) {
69 const section = topics.appendChild(document.createElement("section"))
70 fetch(`${topicID}.jsonld`)
71 .then($ => $.json())
72 .then(topic => {
73 section.appendChild(document.createElement("h3")).textContent = topic.subject
74 const div = section.appendChild(document.createElement("div"))
75 div.className = "STATUS"
76 renderLatest(topic, div) }) } })
77 </SCRIPT>
This page took 0.059116 seconds and 5 git commands to generate.