From e21f0f9bb97cbc4bd59f6bce0e0fce451b6d2b01 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Wed, 09 Aug 2023 04:28:09 +0000
Subject: [PATCH] change reading time to content meta

---
 quartz/plugins/transformers/ofm.ts |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/quartz/plugins/transformers/ofm.ts b/quartz/plugins/transformers/ofm.ts
index 70155e0..e7438aa 100644
--- a/quartz/plugins/transformers/ofm.ts
+++ b/quartz/plugins/transformers/ofm.ts
@@ -96,7 +96,7 @@
 
 function canonicalizeCallout(calloutName: string): keyof typeof callouts {
   let callout = calloutName.toLowerCase() as keyof typeof calloutMapping
-  return calloutMapping[callout]
+  return calloutMapping[callout] ?? calloutName
 }
 
 const capitalize = (s: string): string => {
@@ -184,7 +184,7 @@
 
               // embed cases
               if (value.startsWith("!")) {
-                const ext: string | undefined = path.extname(fp).toLowerCase()
+                const ext: string = path.extname(fp).toLowerCase()
                 const url = slugifyFilePath(fp as FilePath) + ext
                 if ([".png", ".jpg", ".jpeg", ".gif", ".bmp", ".svg"].includes(ext)) {
                   const dims = alias ?? ""
@@ -218,14 +218,13 @@
                     type: "html",
                     value: `<iframe src="${url}"></iframe>`,
                   }
-                } else {
-                  // TODO: this is the node embed case
+                } else if (ext === "") {
+                  // TODO: note embed
                 }
                 // otherwise, fall through to regular link
               }
 
               // internal link
-              // const url = transformInternalLink(fp + anchor)
               const url = fp + anchor
               return {
                 type: "link",
@@ -414,7 +413,17 @@
         js.push({
           script: `
           import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
-          mermaid.initialize({ startOnLoad: true });
+          const darkMode = document.documentElement.getAttribute('saved-theme') === 'dark'
+          mermaid.initialize({ 
+            startOnLoad: false,
+            securityLevel: 'loose',
+            theme: darkMode ? 'dark' : 'default'
+          });
+          document.addEventListener('nav', async () => {
+            await mermaid.run({
+              querySelector: '.mermaid'
+            })
+          });
           `,
           loadTime: "afterDOMReady",
           moduleType: "module",

--
Gitblit v1.10.0