From 3468b955d11c799c2a8f680ea7fabd9674ad4499 Mon Sep 17 00:00:00 2001 From: bfahrenfort Date: Sun, 10 Sep 2023 13:46:02 -0500 Subject: [PATCH] Quartz sync: Sep 10, 2023, 1:46 PM --- quartz/plugins/transformers/remark42.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/quartz/plugins/transformers/remark42.ts b/quartz/plugins/transformers/remark42.ts index 50c710b17..1a5a38ade 100644 --- a/quartz/plugins/transformers/remark42.ts +++ b/quartz/plugins/transformers/remark42.ts @@ -29,6 +29,10 @@ export const Remark42: QuartzTransformerPlugin = (opts?: Options) => { configAsString += "}" scripts.push({script:configAsString, loadTime: "afterDOMReady", contentType: "inline"}) + // Modify the config based on the client sided theme + const dynamicTheme : string = `remark_config.theme = document.documentElement.getAttribute('saved-theme')` + scripts.push({script:dynamicTheme, loadTime: "afterDOMReady", contentType: "inline"}) + // Put the embeddable components into window scope function getComment(e : Array) { for (var o = 0; o < e.length; o++) @@ -38,6 +42,26 @@ export const Remark42: QuartzTransformerPlugin = (opts?: Options) => { } } getComment(opts?.components || ["embed"]) + + // Allow SPA mode + const spaRouting : string = ` +document.addEventListener("nav", () => { + ;(function () { + var host = // Your remark42 host + var components = ['embed'] // Your choice of remark42 components + + ;(function(c) { + for (let i = 0; i < c.length; i++) { + const d = document + const s = d.createElement('script') + s.src = remark_config.host + '/web/' + c[i] + '.js' + s.defer = true + ;(d.head || d.body).appendChild(s) + } + })(components) +}) + })` + return { name: "Remark42", options: opts,