]> Lady’s Gitweb - GitWikiWeb/blobdiff - build.js
Fix old recently changed files
[GitWikiWeb] / build.js
index 4f996a3232cf7bf195035813e872a8d05111140e..df9c016600b3fdf9539de47d162d7ff944fc9dc9 100644 (file)
--- a/build.js
+++ b/build.js
@@ -53,6 +53,8 @@ const READ_ONLY = {
   writable: false,
 };
 
+const NIL = Object.preventExtensions(Object.create(null));
+
 const rawBlock = (strings, ...substitutions) => ({
   tag: "raw_block",
   format: "html",
@@ -171,7 +173,7 @@ const listOfInternalLinks = (references, wrapper = ($) => $) => ({
   ),
 });
 
-const diffReferences = async (hash) => {
+const diffReferences = async (hash, againstHead = false) => {
   const diff = new Deno.Command("git", {
     args: [
       "diff-tree",
@@ -180,7 +182,7 @@ const diffReferences = async (hash) => {
       "--name-only",
       "--no-renames",
       "--diff-filter=AM",
-      hash,
+      ...(againstHead ? [hash, "HEAD"] : [hash]),
     ],
     stdout: "piped",
     stderr: "piped",
@@ -238,7 +240,7 @@ class GitWikiWebPage {
               );
               if (internalLinks.size) {
                 links_section.push(
-                  rawBlock`<details>`,
+                  rawBlock`<details open="">`,
                   rawBlock`<summary>on this wiki</summary>`,
                   listOfInternalLinks(internalLinks),
                   rawBlock`</details>`,
@@ -248,7 +250,7 @@ class GitWikiWebPage {
               }
               if (externalLinks.size) {
                 links_section.push(
-                  rawBlock`<details>`,
+                  rawBlock`<details open="">`,
                   rawBlock`<summary>elsewhere on the Web</summary>`,
                   {
                     tag: "bullet_list",
@@ -295,6 +297,29 @@ class GitWikiWebPage {
             e.children.push(...links_section);
           },
         },
+        emph: {
+          enter: (_) => {},
+          exit: (e) => {
+            const attributes = e.attributes ?? NIL;
+            const { as } = attributes;
+            if (as) {
+              delete attributes.as;
+              if (
+                as == "b" || as == "cite" || as == "i" || as == "u"
+              ) {
+                return [
+                  rawInline`<${as}>`,
+                  ...e.children,
+                  rawInline`</${as}>`,
+                ];
+              } else {
+                /* do nothing */
+              }
+            } else {
+              /* do nothing */
+            }
+          },
+        },
         hard_break: {
           enter: (_) => {
             if (titleSoFar != null) {
@@ -446,6 +471,35 @@ class GitWikiWebPage {
           },
           exit: (_) => {},
         },
+        symb: {
+          enter: (e) => {
+            const { alias } = e;
+            const codepoint = /^U\+([0-9A-Fa-f]+)$/u.exec(alias)?.[1];
+            if (codepoint) {
+              return str`${
+                String.fromCodePoint(parseInt(codepoint, 16))
+              }`;
+            } else {
+              return {
+                "--8": str`${"—\u2060:\u202F"}`, // reverse puppyprick
+                "8--": str`${"\u202F:\u2060—"}`, // forward puppyprick
+                sp: rawInline` `, // space
+                nbsp: str`${"\xA0"}`, // no‐break space
+                cgj: str`${"\u034F"}`, // combining grapheme joiner
+                ensp: str`${"\u2002"}`, // enspace
+                emsp: str`${"\u2003"}`, // emspace
+                figsp: str`${"\u2007"}`, // figure space
+                zwsp: str`${"\u200B"}`, // zero‐width space
+                zwnj: str`${"\u200C"}`, // zero‐width nonjoiner
+                zwj: str`${"\u200D"}`, // zero‐width joiner
+                nnbsp: str`${"\u202F"}`, // narrow no‐break space
+                mathsp: str`${"\u205F"}`, // math space
+                wj: str`${"\u2060"}`, // word joiner
+                fwsp: str`${"\u3000"}`, // fullwidth space
+              }[alias] ?? e;
+            }
+          },
+        },
       };
     });
     Object.defineProperties(this, {
@@ -638,7 +692,9 @@ class GitWikiWebPage {
           ]).then(logErrorsAndCollectResults);
           const refs = [];
           current = hash;
-          for (const ref of (await diffReferences(current))) {
+          for (
+            const ref of (await diffReferences(current, !recency))
+          ) {
             if (seen.has(ref)) {
               /* do nothing */
             } else {
@@ -646,7 +702,7 @@ class GitWikiWebPage {
               seen.add(ref);
             }
           }
-          results[recency] = { dateTime, humanReadable, refs };
+          results[recency] = { dateTime, hash, humanReadable, refs };
         } while (recency-- > 0 && current && current != commit);
         return results;
       })(),
@@ -707,14 +763,16 @@ class GitWikiWebPage {
                             refs,
                           } = result;
                           yield* listOfInternalLinks(refs, (link) => ({
-                            tag: index ? "strong" : "span",
+                            tag: index == 0 ? "span" : "strong",
                             attributes: { "data-recency": `${index}` },
                             children: [
                               link,
-                              str` `,
-                              rawInline`<small>(<time dateTime="${dateTime}">`,
-                              str`${humanReadable}`,
-                              rawInline`</time>)</small>`,
+                              ...(index == 0 ? [] : [
+                                str` `,
+                                rawInline`<small>(<time dateTime="${dateTime}">`,
+                                str`${humanReadable}`,
+                                rawInline`</time>)</small>`,
+                              ]),
                             ],
                           })).children;
                         } else {
@@ -740,7 +798,9 @@ class GitWikiWebPage {
                     },
                     rawBlock`<details id="navigation-about" open="">`,
                     rawBlock`<summary>about this listing</summary>`,
+                    rawBlock`<article>`,
                     ...e.children,
+                    rawBlock`</article>`,
                     rawBlock`</details>`,
                   ],
                   navigation: [
@@ -761,7 +821,7 @@ class GitWikiWebPage {
           },
           heading: {
             enter: (e) => {
-              const attributes = e.attributes ?? Object.create(null);
+              const attributes = e.attributes ?? NIL;
               if (
                 isNavigationPage && e.level == 1 &&
                 attributes?.class == "main"
@@ -804,8 +864,7 @@ class GitWikiWebPage {
                 }
                 if (children.length == 0) {
                   const section =
-                    pages.get(reference)?.sections?.main ??
-                      Object.create(null);
+                    pages.get(reference)?.sections?.main ?? NIL;
                   const { v } = attributes;
                   if (v == null) {
                     children.push(
This page took 0.027307 seconds and 4 git commands to generate.