feat: refactor static paths and photoswipe on blog page, move script to base layout
All checks were successful
test-build / guarddog (push) Successful in 31s
renovate / renovate (push) Successful in 39s
test-build / build (push) Successful in 1m39s

This commit is contained in:
2026-03-15 21:44:40 -05:00
parent a6c889f76a
commit 93a53cab3d
4 changed files with 97 additions and 72 deletions

View File

@@ -120,6 +120,48 @@ const normalizeTitle = !title ? global.name : `${title} | ${global.name}`;
});
</script>
<script>
import PhotoSwipeLightbox from 'photoswipe/lightbox';
import PhotoSwipe from "photoswipe";
let lightbox: PhotoSwipeLightbox | null = null;
function initPhotoSwipe() {
const links = document.querySelectorAll<HTMLAnchorElement>('a.pswp-link');
links.forEach((link) => {
const img = link.querySelector('img');
if (img) {
const applyDimensions = () => {
link.dataset.pswpWidth = (img.naturalWidth || 1920).toString();
link.dataset.pswpHeight = (img.naturalHeight || 1080).toString();
};
if (img.complete) {
applyDimensions();
} else {
img.addEventListener('load', applyDimensions);
}
}
});
if (lightbox) {
lightbox.destroy();
}
lightbox = new PhotoSwipeLightbox({
gallery: '.prose',
children: 'a.pswp-link',
pswpModule: PhotoSwipe,
allowPanToNext: true,
});
lightbox.init();
}
initPhotoSwipe();
document.addEventListener('swup:page:view', initPhotoSwipe);
</script>
<script>
const animateContent = () => {
const smoothReveal = document.querySelectorAll('.smooth-reveal');