diff --git a/dist/components/index.js b/dist/components/index.js index b749cec..190e4ca 100644 --- a/dist/components/index.js +++ b/dist/components/index.js @@ -12,12 +12,10 @@ function boolToStringBool(b) { } var Comments_default = ((opts) => { const Comments = ({ displayClass, fileData, cfg }) => { - const fd = fileData; - const disableComment = typeof fd.frontmatter?.comments !== "undefined" && (!fd.frontmatter?.comments || fd.frontmatter?.comments === "false"); - if (disableComment) { + const commentsOverride = fileData.frontmatter?.comments; + if (commentsOverride === false || commentsOverride === "false") { return /* @__PURE__ */ jsx(Fragment, {}); } - const c = cfg; return /* @__PURE__ */ jsx( "div", { @@ -32,7 +30,7 @@ var Comments_default = ((opts) => { "data-input-position": opts.options.inputPosition ?? "bottom", "data-light-theme": opts.options.lightTheme ?? "light", "data-dark-theme": opts.options.darkTheme ?? "dark", - "data-theme-url": opts.options.themeUrl ?? `https://${c.baseUrl ?? "example.com"}/static/giscus`, + "data-theme-url": opts.options.themeUrl ?? `https://${cfg.baseUrl ?? "example.com"}/static/giscus`, "data-lang": opts.options.lang ?? "en" } ); diff --git a/dist/components/index.js.map b/dist/components/index.js.map index 09603b9..a9eea57 100644 --- a/dist/components/index.js.map +++ b/dist/components/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../node_modules/@quartz-community/utils/src/lang.ts","../../src/components/scripts/comments.inline.ts","../../src/components/Comments.tsx"],"names":[],"mappings":";;;AAIO,SAAS,cAAc,OAAA,EAAwD;AACpF,EAAA,OAAO,OAAA,CAAQ,MAAA,CAAO,OAAO,CAAA,CAAE,KAAK,GAAG,CAAA;AACzC;;;ACNA,IAAA,uBAAA,GAAA,wlDAAA;ACyBA,SAAS,iBAAiB,CAAA,EAAoB;AAC5C,EAAA,OAAO,IAAI,GAAA,GAAM,GAAA;AACnB;AAEA,IAAO,gBAAA,IAAS,CAAC,IAAA,KAA0B;AACzC,EAAA,MAAM,WAA4B,CAAC,EAAE,YAAA,EAAc,QAAA,EAAU,KAAI,KAA4B;AAE3F,IAAA,MAAM,EAAA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AA,CAAK,OAAA,CAAQ,IAAA,IAAQ;AAAA;AAAA,KACjC;AAAA,EAEL,CAAA;AAEA,EAAA,QAAA,CAAS,cAAA,GAAiB,uBAAA;AAE1B,EAAA,OAAO,QAAA;AACT,CAAA","file":"index.js","sourcesContent":["export function capitalize(s: string): string {\n return s.substring(0, 1).toUpperCase() + s.substring(1);\n}\n\nexport function classNames(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n","var d=s=>{let e=s.detail.theme,t=document.querySelector(\"iframe.giscus-frame\");t&&t.contentWindow&&t.contentWindow.postMessage({giscus:{setConfig:{theme:c(r(e))}}},\"https://giscus.app\")},r=s=>{if(s!==\"dark\"&&s!==\"light\")return s;let e=document.querySelector(\".giscus\");if(!e)return s;let t=e.dataset.darkTheme??\"dark\",a=e.dataset.lightTheme??\"light\";return s===\"dark\"?t:a},c=s=>{let e=document.querySelector(\".giscus\");return e?`${e.dataset.themeUrl??\"https://giscus.app/themes\"}/${s}.css`:`https://giscus.app/themes/${s}.css`},n=[],u=s=>{n.push(s)};if(typeof document<\"u\"){let s=()=>{n.forEach(o=>o()),n.length=0;let e=document.querySelector(\".giscus\");if(!e)return;let t=document.createElement(\"script\");t.src=\"https://giscus.app/client.js\",t.async=!0,t.crossOrigin=\"anonymous\",t.setAttribute(\"data-loading\",\"lazy\"),t.setAttribute(\"data-emit-metadata\",\"0\"),t.setAttribute(\"data-repo\",e.dataset.repo),t.setAttribute(\"data-repo-id\",e.dataset.repoId),t.setAttribute(\"data-category\",e.dataset.category),t.setAttribute(\"data-category-id\",e.dataset.categoryId),t.setAttribute(\"data-mapping\",e.dataset.mapping),t.setAttribute(\"data-strict\",e.dataset.strict),t.setAttribute(\"data-reactions-enabled\",e.dataset.reactionsEnabled),t.setAttribute(\"data-input-position\",e.dataset.inputPosition),t.setAttribute(\"data-lang\",e.dataset.lang);let a=document.documentElement.getAttribute(\"saved-theme\");a&&t.setAttribute(\"data-theme\",c(r(a))),e.appendChild(t);let i=d;document.addEventListener(\"themechange\",i),u(()=>document.removeEventListener(\"themechange\",i))};document.addEventListener(\"nav\",s),document.addEventListener(\"render\",s)}\n","import type { QuartzComponent, QuartzComponentProps } from \"@quartz-community/types\";\nimport { classNames } from \"../util/lang\";\n// @ts-expect-error - inline script imported as string by esbuild loader\nimport script from \"./scripts/comments.inline\";\n\ntype RequiredOptsConstructor = (opts: Options) => QuartzComponent;\n\nexport type CommentsOptions = {\n provider: \"giscus\";\n options: {\n repo: `${string}/${string}`;\n repoId: string;\n category: string;\n categoryId: string;\n themeUrl?: string;\n lightTheme?: string;\n darkTheme?: string;\n mapping?: \"url\" | \"title\" | \"og:title\" | \"specific\" | \"number\" | \"pathname\";\n strict?: boolean;\n reactionsEnabled?: boolean;\n inputPosition?: \"top\" | \"bottom\";\n lang?: string;\n };\n};\n\nfunction boolToStringBool(b: boolean): string {\n return b ? \"1\" : \"0\";\n}\n\nexport default ((opts: CommentsOptions) => {\n const Comments: QuartzComponent = ({ displayClass, fileData, cfg }: QuartzComponentProps) => {\n // check if comments should be displayed according to frontmatter\n const fd = fileData as Record;\n const disableComment: boolean =\n typeof (fd.frontmatter as Record)?.comments !== \"undefined\" &&\n (!(fd.frontmatter as Record)?.comments ||\n (fd.frontmatter as Record)?.comments === \"false\");\n if (disableComment) {\n return <>;\n }\n\n const c = cfg as Record;\n return (\n \n );\n };\n\n Comments.afterDOMLoaded = script;\n\n return Comments;\n}) satisfies RequiredOptsConstructor;\n"]} \ No newline at end of file +{"version":3,"sources":["../../node_modules/@quartz-community/utils/src/lang.ts","../../src/components/scripts/comments.inline.ts","../../src/components/Comments.tsx"],"names":[],"mappings":";;;AAIO,SAAS,cAAc,OAAA,EAAwD;AACpF,EAAA,OAAO,OAAA,CAAQ,MAAA,CAAO,OAAO,CAAA,CAAE,KAAK,GAAG,CAAA;AACzC;;;ACNA,IAAA,uBAAA,GAAA,wlDAAA;ACyBA,SAAS,iBAAiB,CAAA,EAAoB;AAC5C,EAAA,O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A,QAElE,WAAA,EAAW,IAAA,CAAK,OAAA,CAAQ,IAAA,IAAQ;AAAA;AAAA,KACjC;AAAA,EAEL,CAAA;AAEA,EAAA,QAAA,CAAS,cAAA,GAAiB,uBAAA;AAE1B,EAAA,OAAO,QAAA;AACT,CAAA","file":"index.js","sourcesContent":["export function capitalize(s: string): string {\n return s.substring(0, 1).toUpperCase() + s.substring(1);\n}\n\nexport function classNames(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n","var d=s=>{let e=s.detail.theme,t=document.querySelector(\"iframe.giscus-frame\");t&&t.contentWindow&&t.contentWindow.postMessage({giscus:{setConfig:{theme:c(r(e))}}},\"https://giscus.app\")},r=s=>{if(s!==\"dark\"&&s!==\"light\")return s;let e=document.querySelector(\".giscus\");if(!e)return s;let t=e.dataset.darkTheme??\"dark\",a=e.dataset.lightTheme??\"light\";return s===\"dark\"?t:a},c=s=>{let e=document.querySelector(\".giscus\");return e?`${e.dataset.themeUrl??\"https://giscus.app/themes\"}/${s}.css`:`https://giscus.app/themes/${s}.css`},n=[],u=s=>{n.push(s)};if(typeof document<\"u\"){let s=()=>{n.forEach(o=>o()),n.length=0;let e=document.querySelector(\".giscus\");if(!e)return;let t=document.createElement(\"script\");t.src=\"https://giscus.app/client.js\",t.async=!0,t.crossOrigin=\"anonymous\",t.setAttribute(\"data-loading\",\"lazy\"),t.setAttribute(\"data-emit-metadata\",\"0\"),t.setAttribute(\"data-repo\",e.dataset.repo),t.setAttribute(\"data-repo-id\",e.dataset.repoId),t.setAttribute(\"data-category\",e.dataset.category),t.setAttribute(\"data-category-id\",e.dataset.categoryId),t.setAttribute(\"data-mapping\",e.dataset.mapping),t.setAttribute(\"data-strict\",e.dataset.strict),t.setAttribute(\"data-reactions-enabled\",e.dataset.reactionsEnabled),t.setAttribute(\"data-input-position\",e.dataset.inputPosition),t.setAttribute(\"data-lang\",e.dataset.lang);let a=document.documentElement.getAttribute(\"saved-theme\");a&&t.setAttribute(\"data-theme\",c(r(a))),e.appendChild(t);let i=d;document.addEventListener(\"themechange\",i),u(()=>document.removeEventListener(\"themechange\",i))};document.addEventListener(\"nav\",s),document.addEventListener(\"render\",s)}\n","import type { QuartzComponent, QuartzComponentProps } from \"@quartz-community/types\";\nimport { classNames } from \"../util/lang\";\n// @ts-expect-error - inline script imported as string by esbuild loader\nimport script from \"./scripts/comments.inline\";\n\ntype RequiredOptsConstructor = (opts: Options) => QuartzComponent;\n\nexport type CommentsOptions = {\n provider: \"giscus\";\n options: {\n repo: `${string}/${string}`;\n repoId: string;\n category: string;\n categoryId: string;\n themeUrl?: string;\n lightTheme?: string;\n darkTheme?: string;\n mapping?: \"url\" | \"title\" | \"og:title\" | \"specific\" | \"number\" | \"pathname\";\n strict?: boolean;\n reactionsEnabled?: boolean;\n inputPosition?: \"top\" | \"bottom\";\n lang?: string;\n };\n};\n\nfunction boolToStringBool(b: boolean): string {\n return b ? \"1\" : \"0\";\n}\n\nexport default ((opts: CommentsOptions) => {\n const Comments: QuartzComponent = ({ displayClass, fileData, cfg }: QuartzComponentProps) => {\n const commentsOverride = fileData.frontmatter?.comments;\n if (commentsOverride === false || commentsOverride === \"false\") {\n return <>;\n }\n\n return (\n \n );\n };\n\n Comments.afterDOMLoaded = script;\n\n return Comments;\n}) satisfies RequiredOptsConstructor;\n"]} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index b749cec..190e4ca 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12,12 +12,10 @@ function boolToStringBool(b) { } var Comments_default = ((opts) => { const Comments = ({ displayClass, fileData, cfg }) => { - const fd = fileData; - const disableComment = typeof fd.frontmatter?.comments !== "undefined" && (!fd.frontmatter?.comments || fd.frontmatter?.comments === "false"); - if (disableComment) { + const commentsOverride = fileData.frontmatter?.comments; + if (commentsOverride === false || commentsOverride === "false") { return /* @__PURE__ */ jsx(Fragment, {}); } - const c = cfg; return /* @__PURE__ */ jsx( "div", { @@ -32,7 +30,7 @@ var Comments_default = ((opts) => { "data-input-position": opts.options.inputPosition ?? "bottom", "data-light-theme": opts.options.lightTheme ?? "light", "data-dark-theme": opts.options.darkTheme ?? "dark", - "data-theme-url": opts.options.themeUrl ?? `https://${c.baseUrl ?? "example.com"}/static/giscus`, + "data-theme-url": opts.options.themeUrl ?? `https://${cfg.baseUrl ?? "example.com"}/static/giscus`, "data-lang": opts.options.lang ?? "en" } ); diff --git a/dist/index.js.map b/dist/index.js.map index 4f6a1b2..61544fb 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../node_modules/@quartz-community/utils/src/lang.ts","../src/components/scripts/comments.inline.ts","../src/components/Comments.tsx"],"names":[],"mappings":";;;AAIO,SAAS,cAAc,OAAA,EAAwD;AACpF,EAAA,OAAO,OAAA,CAAQ,MAAA,CAAO,OAAO,CAAA,CAAE,KAAK,GAAG,CAAA;AACzC;;;ACNA,IAAA,uBAAA,GAAA,wlDAAA;ACyBA,SAAS,iBAAiB,CAAA,EAAoB;AAC5C,EAAA,OAAO,IAAI,GAAA,GAAM,GAAA;AACnB;AAEA,IAAO,gBAAA,IAAS,CAAC,IAAA,KAA0B;AACzC,EAAA,MAAM,WAA4B,CAAC,EAAE,YAAA,EAAc,QAAA,EAAU,KAAI,KAA4B;AAE3F,IAAA,MAAM,EAAA,GAAK,QAAA;AACX,IAAA,MAAM,cAAA,GACJ,OAAQ,EAAA,CAAG,WAAA,EAAyC,QAAA,KAAa,WAAA,KAChE,CAAE,EAAA,CAAG,WAAA,EAAyC,QAAA,IAC5C,EAAA,CAAG,WAAA,EAAyC,QAAA,KAAa,OAAA,CAAA;AAC9D,IAAA,IAAI,cAAA,EAAgB;AAClB,MAAA,uBAAO,GAAA,CAAA,QAAA,EAAA,EAAE,CAAA;AAAA,IACX;AAEA,IAAA,MAAM,CAAA,GAAI,GAAA;AACV,IAAA,uBACE,GAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACC,KAAA,EAAO,UAAA,CAAW,YAAA,EAAc,QAAQ,CAAA;AAAA,QACxC,WAAA,EAAW,KAAK,OAAA,CAAQ,IAAA;AAAA,QACxB,cAAA,EAAc,KAAK,OAAA,CAAQ,MAAA;AAAA,QAC3B,eAAA,EAAe,KAAK,OAAA,CAAQ,QAAA;AAAA,QAC5B,kBAAA,EAAkB,KAAK,OAAA,CAAQ,UAAA;AAAA,QAC/B,cAAA,EAAc,IAAA,CAAK,OAAA,CAAQ,OAAA,IAAW,KAAA;AAAA,QACtC,aAAA,EAAa,gBAAA,CAAiB,IAAA,CAAK,OAAA,CAAQ,UAAU,IAAI,CAAA;AAAA,QACzD,wBAAA,EAAwB,gBAAA,CAAiB,IAAA,CAAK,OAAA,CAAQ,oBAAoB,IAAI,CAAA;AAAA,QAC9E,qBAAA,EAAqB,IAAA,CAAK,OAAA,CAAQ,aAAA,IAAiB,QAAA;AAAA,QACnD,kBAAA,EAAkB,IAAA,CAAK,OAAA,CAAQ,UAAA,IAAc,OAAA;AAAA,QAC7C,iBAAA,EAAiB,IAAA,CAAK,OAAA,CAAQ,SAAA,IAAa,MAAA;AAAA,QAC3C,kBACE,IAAA,CAAK,OAAA,CAAQ,YAAY,CAAA,QAAA,EAAY,CAAA,CAAE,WAAsB,aAAa,CAAA,cAAA,CAAA;AAAA,QAE5E,WAAA,EAAW,IAAA,CAAK,OAAA,CAAQ,IAAA,IAAQ;AAAA;AAAA,KACjC;AAAA,EAEL,CAAA;AAEA,EAAA,QAAA,CAAS,cAAA,GAAiB,uBAAA;AAE1B,EAAA,OAAO,QAAA;AACT,CAAA","file":"index.js","sourcesContent":["export function capitalize(s: string): string {\n return s.substring(0, 1).toUpperCase() + s.substring(1);\n}\n\nexport function classNames(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n","var d=s=>{let e=s.detail.theme,t=document.querySelector(\"iframe.giscus-frame\");t&&t.contentWindow&&t.contentWindow.postMessage({giscus:{setConfig:{theme:c(r(e))}}},\"https://giscus.app\")},r=s=>{if(s!==\"dark\"&&s!==\"light\")return s;let e=document.querySelector(\".giscus\");if(!e)return s;let t=e.dataset.darkTheme??\"dark\",a=e.dataset.lightTheme??\"light\";return s===\"dark\"?t:a},c=s=>{let e=document.querySelector(\".giscus\");return e?`${e.dataset.themeUrl??\"https://giscus.app/themes\"}/${s}.css`:`https://giscus.app/themes/${s}.css`},n=[],u=s=>{n.push(s)};if(typeof document<\"u\"){let s=()=>{n.forEach(o=>o()),n.length=0;let e=document.querySelector(\".giscus\");if(!e)return;let t=document.createElement(\"script\");t.src=\"https://giscus.app/client.js\",t.async=!0,t.crossOrigin=\"anonymous\",t.setAttribute(\"data-loading\",\"lazy\"),t.setAttribute(\"data-emit-metadata\",\"0\"),t.setAttribute(\"data-repo\",e.dataset.repo),t.setAttribute(\"data-repo-id\",e.dataset.repoId),t.setAttribute(\"data-category\",e.dataset.category),t.setAttribute(\"data-category-id\",e.dataset.categoryId),t.setAttribute(\"data-mapping\",e.dataset.mapping),t.setAttribute(\"data-strict\",e.dataset.strict),t.setAttribute(\"data-reactions-enabled\",e.dataset.reactionsEnabled),t.setAttribute(\"data-input-position\",e.dataset.inputPosition),t.setAttribute(\"data-lang\",e.dataset.lang);let a=document.documentElement.getAttribute(\"saved-theme\");a&&t.setAttribute(\"data-theme\",c(r(a))),e.appendChild(t);let i=d;document.addEventListener(\"themechange\",i),u(()=>document.removeEventListener(\"themechange\",i))};document.addEventListener(\"nav\",s),document.addEventListener(\"render\",s)}\n","import type { QuartzComponent, QuartzComponentProps } from \"@quartz-community/types\";\nimport { classNames } from \"../util/lang\";\n// @ts-expect-error - inline script imported as string by esbuild loader\nimport script from \"./scripts/comments.inline\";\n\ntype RequiredOptsConstructor = (opts: Options) => QuartzComponent;\n\nexport type CommentsOptions = {\n provider: \"giscus\";\n options: {\n repo: `${string}/${string}`;\n repoId: string;\n category: string;\n categoryId: string;\n themeUrl?: string;\n lightTheme?: string;\n darkTheme?: string;\n mapping?: \"url\" | \"title\" | \"og:title\" | \"specific\" | \"number\" | \"pathname\";\n strict?: boolean;\n reactionsEnabled?: boolean;\n inputPosition?: \"top\" | \"bottom\";\n lang?: string;\n };\n};\n\nfunction boolToStringBool(b: boolean): string {\n return b ? \"1\" : \"0\";\n}\n\nexport default ((opts: CommentsOptions) => {\n const Comments: QuartzComponent = ({ displayClass, fileData, cfg }: QuartzComponentProps) => {\n // check if comments should be displayed according to frontmatter\n const fd = fileData as Record;\n const disableComment: boolean =\n typeof (fd.frontmatter as Record)?.comments !== \"undefined\" &&\n (!(fd.frontmatter as Record)?.comments ||\n (fd.frontmatter as Record)?.comments === \"false\");\n if (disableComment) {\n return <>;\n }\n\n const c = cfg as Record;\n return (\n \n );\n };\n\n Comments.afterDOMLoaded = script;\n\n return Comments;\n}) satisfies RequiredOptsConstructor;\n"]} \ No newline at end of file +{"version":3,"sources":["../node_modules/@quartz-community/utils/src/lang.ts","../src/components/scripts/comments.inline.ts","../src/components/Comments.tsx"],"names":[],"mappings":";;;AAIO,SAAS,cAAc,OAAA,EAAwD;AACpF,EAAA,OAAO,OAAA,CAAQ,MAAA,CAAO,OAAO,CAAA,CAAE,KAAK,GAAG,CAAA;AACzC;;;ACNA,IAAA,uBAAA,GAAA,wlDAAA;ACyBA,SAAS,iBAAiB,CAAA,EAAoB;AAC5C,EAAA,OAAO,IAAI,GAAA,GAAM,GAAA;AACnB;AAEA,IAAO,gBAAA,IAAS,CAAC,IAAA,KAA0B;AACzC,EAAA,MAAM,WAA4B,CAAC,EAAE,YAAA,EAAc,QAAA,EAAU,KAAI,KAA4B;AAC3F,IAAA,MAAM,gBAAA,GAAmB,SAAS,WAAA,EAAa,QAAA;AAC/C,IAAA,IAAI,gBAAA,KAAqB,KAAA,IAAS,gBAAA,KAAqB,OAAA,EAAS;AAC9D,MAAA,uBAAO,GAAA,CAAA,QAAA,EAAA,EAAE,CAAA;AAAA,IACX;AAEA,IAAA,uBACE,GAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACC,KAAA,EAAO,UAAA,CAAW,YAAA,EAAc,QAAQ,CAAA;AAAA,QACxC,WAAA,EAAW,KAAK,OAAA,CAAQ,IAAA;AAAA,QACxB,cAAA,EAAc,KAAK,OAAA,CAAQ,MAAA;AAAA,QAC3B,eAAA,EAAe,KAAK,OAAA,CAAQ,QAAA;AAAA,QAC5B,kBAAA,EAAkB,KAAK,OAAA,CAAQ,UAAA;AAAA,QAC/B,cAAA,EAAc,IAAA,CAAK,OAAA,CAAQ,OAAA,IAAW,KAAA;AAAA,QACtC,aAAA,EAAa,gBAAA,CAAiB,IAAA,CAAK,OAAA,CAAQ,UAAU,IAAI,CAAA;AAAA,QACzD,wBAAA,EAAwB,gBAAA,CAAiB,IAAA,CAAK,OAAA,CAAQ,oBAAoB,IAAI,CAAA;AAAA,QAC9E,qBAAA,EAAqB,IAAA,CAAK,OAAA,CAAQ,aAAA,IAAiB,QAAA;AAAA,QACnD,kBAAA,EAAkB,IAAA,CAAK,OAAA,CAAQ,UAAA,IAAc,OAAA;AAAA,QAC7C,iBAAA,EAAiB,IAAA,CAAK,OAAA,CAAQ,SAAA,IAAa,MAAA;AAAA,QAC3C,kBACE,IAAA,CAAK,OAAA,CAAQ,YAAY,CAAA,QAAA,EAAW,GAAA,CAAI,WAAW,aAAa,CAAA,cAAA,CAAA;AAAA,QAElE,WAAA,EAAW,IAAA,CAAK,OAAA,CAAQ,IAAA,IAAQ;AAAA;AAAA,KACjC;AAAA,EAEL,CAAA;AAEA,EAAA,QAAA,CAAS,cAAA,GAAiB,uBAAA;AAE1B,EAAA,OAAO,QAAA;AACT,CAAA","file":"index.js","sourcesContent":["export function capitalize(s: string): string {\n return s.substring(0, 1).toUpperCase() + s.substring(1);\n}\n\nexport function classNames(...classes: (string | undefined | null | false)[]): string {\n return classes.filter(Boolean).join(\" \");\n}\n","var d=s=>{let e=s.detail.theme,t=document.querySelector(\"iframe.giscus-frame\");t&&t.contentWindow&&t.contentWindow.postMessage({giscus:{setConfig:{theme:c(r(e))}}},\"https://giscus.app\")},r=s=>{if(s!==\"dark\"&&s!==\"light\")return s;let e=document.querySelector(\".giscus\");if(!e)return s;let t=e.dataset.darkTheme??\"dark\",a=e.dataset.lightTheme??\"light\";return s===\"dark\"?t:a},c=s=>{let e=document.querySelector(\".giscus\");return e?`${e.dataset.themeUrl??\"https://giscus.app/themes\"}/${s}.css`:`https://giscus.app/themes/${s}.css`},n=[],u=s=>{n.push(s)};if(typeof document<\"u\"){let s=()=>{n.forEach(o=>o()),n.length=0;let e=document.querySelector(\".giscus\");if(!e)return;let t=document.createElement(\"script\");t.src=\"https://giscus.app/client.js\",t.async=!0,t.crossOrigin=\"anonymous\",t.setAttribute(\"data-loading\",\"lazy\"),t.setAttribute(\"data-emit-metadata\",\"0\"),t.setAttribute(\"data-repo\",e.dataset.repo),t.setAttribute(\"data-repo-id\",e.dataset.repoId),t.setAttribute(\"data-category\",e.dataset.category),t.setAttribute(\"data-category-id\",e.dataset.categoryId),t.setAttribute(\"data-mapping\",e.dataset.mapping),t.setAttribute(\"data-strict\",e.dataset.strict),t.setAttribute(\"data-reactions-enabled\",e.dataset.reactionsEnabled),t.setAttribute(\"data-input-position\",e.dataset.inputPosition),t.setAttribute(\"data-lang\",e.dataset.lang);let a=document.documentElement.getAttribute(\"saved-theme\");a&&t.setAttribute(\"data-theme\",c(r(a))),e.appendChild(t);let i=d;document.addEventListener(\"themechange\",i),u(()=>document.removeEventListener(\"themechange\",i))};document.addEventListener(\"nav\",s),document.addEventListener(\"render\",s)}\n","import type { QuartzComponent, QuartzComponentProps } from \"@quartz-community/types\";\nimport { classNames } from \"../util/lang\";\n// @ts-expect-error - inline script imported as string by esbuild loader\nimport script from \"./scripts/comments.inline\";\n\ntype RequiredOptsConstructor = (opts: Options) => QuartzComponent;\n\nexport type CommentsOptions = {\n provider: \"giscus\";\n options: {\n repo: `${string}/${string}`;\n repoId: string;\n category: string;\n categoryId: string;\n themeUrl?: string;\n lightTheme?: string;\n darkTheme?: string;\n mapping?: \"url\" | \"title\" | \"og:title\" | \"specific\" | \"number\" | \"pathname\";\n strict?: boolean;\n reactionsEnabled?: boolean;\n inputPosition?: \"top\" | \"bottom\";\n lang?: string;\n };\n};\n\nfunction boolToStringBool(b: boolean): string {\n return b ? \"1\" : \"0\";\n}\n\nexport default ((opts: CommentsOptions) => {\n const Comments: QuartzComponent = ({ displayClass, fileData, cfg }: QuartzComponentProps) => {\n const commentsOverride = fileData.frontmatter?.comments;\n if (commentsOverride === false || commentsOverride === \"false\") {\n return <>;\n }\n\n return (\n \n );\n };\n\n Comments.afterDOMLoaded = script;\n\n return Comments;\n}) satisfies RequiredOptsConstructor;\n"]} \ No newline at end of file diff --git a/src/components/Comments.tsx b/src/components/Comments.tsx index fd4e74f..3cd5dc5 100644 --- a/src/components/Comments.tsx +++ b/src/components/Comments.tsx @@ -29,17 +29,11 @@ function boolToStringBool(b: boolean): string { export default ((opts: CommentsOptions) => { const Comments: QuartzComponent = ({ displayClass, fileData, cfg }: QuartzComponentProps) => { - // check if comments should be displayed according to frontmatter - const fd = fileData as Record; - const disableComment: boolean = - typeof (fd.frontmatter as Record)?.comments !== "undefined" && - (!(fd.frontmatter as Record)?.comments || - (fd.frontmatter as Record)?.comments === "false"); - if (disableComment) { + const commentsOverride = fileData.frontmatter?.comments; + if (commentsOverride === false || commentsOverride === "false") { return <>; } - const c = cfg as Record; return (
{ data-light-theme={opts.options.lightTheme ?? "light"} data-dark-theme={opts.options.darkTheme ?? "dark"} data-theme-url={ - opts.options.themeUrl ?? `https://${(c.baseUrl as string) ?? "example.com"}/static/giscus` + opts.options.themeUrl ?? `https://${cfg.baseUrl ?? "example.com"}/static/giscus` } data-lang={opts.options.lang ?? "en"} >
diff --git a/test/comments.test.ts b/test/comments.test.ts index fd14684..1e36a4b 100644 --- a/test/comments.test.ts +++ b/test/comments.test.ts @@ -1,5 +1,60 @@ import { describe, it, expect } from "vitest"; +import { Fragment } from "preact"; import Comments from "../src/components/Comments"; +import type { QuartzComponent, QuartzComponentProps } from "@quartz-community/types"; + +type CommentsOptions = Parameters[0]; + +const baseOpts: CommentsOptions = { + provider: "giscus", + options: { + repo: "test/repo", + repoId: "test-id", + category: "Announcements", + categoryId: "test-cat-id", + }, +}; + +function buildProps( + overrides: Partial & { + frontmatter?: Record; + cfg?: Record; + } = {}, +): QuartzComponentProps { + const { frontmatter, cfg, ...rest } = overrides; + return { + ctx: {}, + externalResources: { css: [], js: [], additionalHead: [] }, + fileData: { frontmatter: frontmatter ?? {} } as QuartzComponentProps["fileData"], + cfg: (cfg ?? {}) as QuartzComponentProps["cfg"], + children: [], + tree: null, + allFiles: [], + ...rest, + }; +} + +function renderComments( + opts: CommentsOptions, + props: QuartzComponentProps, +): ReturnType { + const Component = Comments(opts); + return Component(props); +} + +function isFragmentOrEmpty(vnode: unknown): boolean { + if (vnode == null || vnode === false) return true; + if (typeof vnode !== "object") return false; + const v = vnode as { type?: unknown }; + return v.type === Fragment; +} + +function getDivProps(vnode: unknown): Record | null { + if (typeof vnode !== "object" || vnode == null) return null; + const v = vnode as { type?: unknown; props?: Record }; + if (v.type !== "div") return null; + return v.props ?? null; +} describe("Comments Plugin", () => { it("should export Comments component", () => { @@ -7,16 +62,128 @@ describe("Comments Plugin", () => { }); it("should create a component with options", () => { - const component = Comments({ - provider: "giscus", - options: { - repo: "test/repo", - repoId: "test-id", - category: "Announcements", - categoryId: "test-cat-id", - }, - }); + const component = Comments(baseOpts); expect(component).toBeDefined(); expect(typeof component).toBe("function"); }); }); + +describe("Comments: frontmatter.comments override", () => { + it("renders the giscus div when frontmatter.comments is undefined", () => { + const result = renderComments(baseOpts, buildProps({ frontmatter: {} })); + const props = getDivProps(result); + expect(props).not.toBeNull(); + expect(props?.["data-repo"]).toBe("test/repo"); + }); + + it("renders the giscus div when frontmatter.comments is true", () => { + const result = renderComments(baseOpts, buildProps({ frontmatter: { comments: true } })); + expect(getDivProps(result)).not.toBeNull(); + }); + + it("renders the giscus div when frontmatter.comments is the string 'true'", () => { + const result = renderComments(baseOpts, buildProps({ frontmatter: { comments: "true" } })); + expect(getDivProps(result)).not.toBeNull(); + }); + + it("suppresses comments when frontmatter.comments is false", () => { + const result = renderComments(baseOpts, buildProps({ frontmatter: { comments: false } })); + expect(isFragmentOrEmpty(result)).toBe(true); + expect(getDivProps(result)).toBeNull(); + }); + + it("suppresses comments when frontmatter.comments is the string 'false'", () => { + const result = renderComments(baseOpts, buildProps({ frontmatter: { comments: "false" } })); + expect(isFragmentOrEmpty(result)).toBe(true); + expect(getDivProps(result)).toBeNull(); + }); + + it("renders the giscus div when frontmatter.comments is the number 0", () => { + // 0 is falsy but not a documented disable value; it must not suppress comments. + const result = renderComments(baseOpts, buildProps({ frontmatter: { comments: 0 } })); + expect(getDivProps(result)).not.toBeNull(); + }); + + it("renders the giscus div when frontmatter.comments is the empty string", () => { + // Empty string is falsy but not a documented disable value; it must not suppress comments. + const result = renderComments(baseOpts, buildProps({ frontmatter: { comments: "" } })); + expect(getDivProps(result)).not.toBeNull(); + }); + + it("renders the giscus div when frontmatter.comments is null", () => { + // null is falsy but not a documented disable value; it must not suppress comments. + const result = renderComments(baseOpts, buildProps({ frontmatter: { comments: null } })); + expect(getDivProps(result)).not.toBeNull(); + }); +}); + +describe("Comments: data attribute wiring", () => { + it("propagates required giscus options", () => { + const result = renderComments(baseOpts, buildProps()); + const props = getDivProps(result); + expect(props).not.toBeNull(); + expect(props?.["data-repo"]).toBe("test/repo"); + expect(props?.["data-repo-id"]).toBe("test-id"); + expect(props?.["data-category"]).toBe("Announcements"); + expect(props?.["data-category-id"]).toBe("test-cat-id"); + }); + + it("applies default values when optional options are omitted", () => { + const result = renderComments(baseOpts, buildProps()); + const props = getDivProps(result); + expect(props?.["data-mapping"]).toBe("url"); + expect(props?.["data-strict"]).toBe("1"); + expect(props?.["data-reactions-enabled"]).toBe("1"); + expect(props?.["data-input-position"]).toBe("bottom"); + expect(props?.["data-light-theme"]).toBe("light"); + expect(props?.["data-dark-theme"]).toBe("dark"); + expect(props?.["data-lang"]).toBe("en"); + }); + + it("respects user-provided optional values", () => { + const opts: CommentsOptions = { + provider: "giscus", + options: { + ...baseOpts.options, + mapping: "pathname", + strict: false, + reactionsEnabled: false, + inputPosition: "top", + lightTheme: "catppuccin_latte", + darkTheme: "catppuccin_mocha", + lang: "nl", + }, + }; + const result = renderComments(opts, buildProps()); + const props = getDivProps(result); + expect(props?.["data-mapping"]).toBe("pathname"); + expect(props?.["data-strict"]).toBe("0"); + expect(props?.["data-reactions-enabled"]).toBe("0"); + expect(props?.["data-input-position"]).toBe("top"); + expect(props?.["data-light-theme"]).toBe("catppuccin_latte"); + expect(props?.["data-dark-theme"]).toBe("catppuccin_mocha"); + expect(props?.["data-lang"]).toBe("nl"); + }); + + it("uses cfg.baseUrl to build the default themeUrl", () => { + const result = renderComments(baseOpts, buildProps({ cfg: { baseUrl: "example.test" } })); + const props = getDivProps(result); + expect(props?.["data-theme-url"]).toBe("https://example.test/static/giscus"); + }); + + it("falls back when cfg.baseUrl is missing", () => { + const result = renderComments(baseOpts, buildProps({ cfg: {} })); + const props = getDivProps(result); + expect(props?.["data-theme-url"]).toBe("https://example.com/static/giscus"); + }); + + it("honours an explicit themeUrl override", () => { + const opts: CommentsOptions = { + provider: "giscus", + options: { ...baseOpts.options, themeUrl: "https://cdn.test/theme" }, + }; + const result = renderComments(opts, buildProps({ cfg: { baseUrl: "example.test" } })); + const props = getDivProps(result); + expect(props?.["data-theme-url"]).toBe("https://cdn.test/theme"); + }); +});