From 02b5797a7cb4a9885e9f5fda4ccb7c0f530cfe4f Mon Sep 17 00:00:00 2001 From: Stephen Tse Date: Sun, 6 Oct 2024 14:12:23 -0700 Subject: [PATCH] Fixed GLightbox not reloaded in SPA mode --- quartz/plugins/transformers/lightbox.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/quartz/plugins/transformers/lightbox.ts b/quartz/plugins/transformers/lightbox.ts index b333b48f8..2e35fe643 100644 --- a/quartz/plugins/transformers/lightbox.ts +++ b/quartz/plugins/transformers/lightbox.ts @@ -59,7 +59,14 @@ export const Lightbox: QuartzTransformerPlugin> = (userOpts) => { contentType: "inline", loadTime: "afterDOMReady", - script: `const lightbox = GLightbox(${JSON.stringify(opts)});`, + // GLightbox needs to be reloaded whenever there's a page content change + // to make sure it loads all the images in the new page content. + // Ref: https://quartz.jzhao.xyz/advanced/creating-components#scripts-and-interactivity + script: ` +document.addEventListener("nav", () => { + const lightbox = GLightbox(${JSON.stringify(opts)}); +}); +`.trim(), }, ], }