Files
hugo-theme-stack/layouts/_partials/article/components/photoswipe.html
T

32 lines
1.2 KiB
HTML
Raw Normal View History

2026-01-25 23:13:34 +01:00
{{- $opts := dict "minify" hugo.IsProduction "format" "esm" -}}
{{- $galleryScript := resources.Get "ts/gallery.ts" | js.Build $opts -}}
2020-08-22 13:20:08 +02:00
2026-01-25 23:13:34 +01:00
{{ $style := .Site.Data.external.PhotoSwipe.Style }}
{{ $core := .Site.Data.external.PhotoSwipe.Core }}
{{ $lightbox := .Site.Data.external.PhotoSwipe.Lightbox }}
2020-08-22 13:20:08 +02:00
2026-01-25 23:13:34 +01:00
<script type="module">
import gallery from '{{ $galleryScript.RelPermalink }}';
2020-08-22 13:20:08 +02:00
2026-01-25 23:13:34 +01:00
const articleContent = document.querySelector('.article-content');
const shouldLoad = articleContent && (articleContent.querySelectorAll('figure').length > 0 || articleContent.querySelectorAll('img.gallery-image').length > 0);
if (shouldLoad) {
gallery(articleContent);
2026-01-25 23:13:34 +01:00
const PhotoSwipeLightbox = (await import("{{ $lightbox | safeJS }}")).default;
const styleHref = "{{ $style | safeJS }}";
2026-01-25 23:13:34 +01:00
const styleTag = document.createElement('link');
styleTag.rel = 'stylesheet';
styleTag.href = styleHref;
document.head.appendChild(styleTag);
2026-01-25 23:13:34 +01:00
const lightbox = new PhotoSwipeLightbox({
gallerySelector: '.article-content',
childSelector: 'figure a.image-link',
pswpModule: () => import("{{ $core | safeJS }}")
});
lightbox.init();
}
</script>