]> Lady’s Gitweb - x_status_git/commitdiff
Use titles in prev & next links on statuses current 0.3.2
authorLady <redacted>
Sun, 17 Dec 2023 03:36:50 +0000 (22:36 -0500)
committerLady <redacted>
Sat, 23 Dec 2023 20:17:52 +0000 (15:17 -0500)
status.html

index e1c68ad306aab8e9c17d026b9868d51f668205da..dbc899c51bde536bc40039398fe4196f78d120b5 100644 (file)
@@ -65,50 +65,60 @@ fetch(index)
     nav.appendChild(document.createTextNode("; Previous: "))
     const prevLink = nav.appendChild(document.createElement("a"))
     prevLink.href = items[n - 1]["@id"]
-    const prevText = (() => {
-      try {
-        const prevD = parser.parseFromString(items[n - 1].content, "application/xhtml+xml")
-        const div = document.createElement("div")
-        div.appendChild(document.importNode(prevD.documentElement, true))
-        Object.assign(div.style,
-          { position: "absolute"
-          , top: "-2px"
-          , height: "1px"
-          , width: "1px"
-          , overflow: "hidden" })
-        document.body.appendChild(div)
-        const text = div.innerText
-        document.body.removeChild(div)
-        return text }
-      catch { } })() ?? items[n + 1].created;
-    const prevChars = Array.from(prevText.trim().replaceAll(/\s+/gu, " "))
-    prevLink.textContent = prevChars.length > 28
-    ? "".concat(...prevChars.slice(0, 27), "…")
-    : prevText }
+    const { title: prevTitle } = items[n - 1]
+    if (prevTitle) prevLink.textContent = prevTitle.length > 28
+    ? "".concat(...prevTitle.slice(0, 27), "…")
+    : prevTitle
+    else {
+      const prevText = (() => {
+        try {
+          const prevD = parser.parseFromString(items[n - 1].content, "application/xhtml+xml")
+          const div = document.createElement("div")
+          div.appendChild(document.importNode(prevD.documentElement, true))
+          Object.assign(div.style,
+            { position: "absolute"
+            , top: "-2px"
+            , height: "1px"
+            , width: "1px"
+            , overflow: "hidden" })
+          document.body.appendChild(div)
+          const text = div.innerText
+          document.body.removeChild(div)
+          return text }
+        catch { } })() ?? items[n + 1].created;
+      const prevChars = Array.from(prevText.trim().replaceAll(/\s+/gu, " "))
+      prevLink.textContent = prevChars.length > 28
+      ? "".concat(...prevChars.slice(0, 27), "…")
+      : prevText } }
   if (n < items.length - 1) {
     nav.appendChild(document.createTextNode("; Next: "))
     const nextLink = nav.appendChild(document.createElement("a"))
     nextLink.href = items[n + 1]["@id"]
-    const nextText = (() => {
-      try {
-        const nextD = parser.parseFromString(items[n + 1].content, "application/xhtml+xml")
-        const div = document.createElement("div")
-        div.appendChild(document.importNode(nextD.documentElement, true))
-        Object.assign(div.style,
-          { position: "absolute"
-          , top: "-2px"
-          , height: "1px"
-          , width: "1px"
-          , overflow: "hidden" })
-        document.body.appendChild(div)
-        const text = div.innerText
-        document.body.removeChild(div)
-        return text }
-      catch { } })() ?? items[n + 1].created;
-    const nextChars = Array.from(nextText.trim().replaceAll(/\s+/gu, " "))
-    nextLink.textContent = nextChars.length > 28
-    ? "".concat(...nextChars.slice(0, 27), "…")
-    : nextText }
+    const { title: nextTitle } = items[n + 1]
+    if (nextTitle) nextLink.textContent = nextTitle.length > 28
+    ? "".concat(...nextTitle.slice(0, 27), "…")
+    : nextTitle
+    else {
+      const nextText = (() => {
+        try {
+          const nextD = parser.parseFromString(items[n + 1].content, "application/xhtml+xml")
+          const div = document.createElement("div")
+          div.appendChild(document.importNode(nextD.documentElement, true))
+          Object.assign(div.style,
+            { position: "absolute"
+            , top: "-2px"
+            , height: "1px"
+            , width: "1px"
+            , overflow: "hidden" })
+          document.body.appendChild(div)
+          const text = div.innerText
+          document.body.removeChild(div)
+          return text }
+        catch { } })() ?? items[n + 1].created;
+      const nextChars = Array.from(nextText.trim().replaceAll(/\s+/gu, " "))
+      nextLink.textContent = nextChars.length > 28
+      ? "".concat(...nextChars.slice(0, 27), "…")
+      : nextText } }
   nav.appendChild(document.createTextNode("."))
   if (title) {
     const wrapper = document.createElement("article")
This page took 0.0245919999999999 seconds and 4 git commands to generate.