From 140a6b938eb396cfb3fdec2cfd6198c885066700 Mon Sep 17 00:00:00 2001 From: Nikolaos Karaolidis Date: Thu, 14 Aug 2025 19:30:36 +0300 Subject: [PATCH] Add photoswipe captions Signed-off-by: Nikolaos Karaolidis --- assets/js/main.js | 33 ++++++++++++++++++-- assets/sass/common.scss | 4 +++ assets/sass/footer.scss | 3 +- assets/sass/header.scss | 5 ++- assets/sass/list.scss | 3 +- assets/sass/photoswipe.scss | 26 +++++++++++++++ layouts/partials/components/image/index.html | 2 ++ layouts/partials/gallery/list.html | 15 ++++++++- 8 files changed, 80 insertions(+), 11 deletions(-) diff --git a/assets/js/main.js b/assets/js/main.js index fb821ae..aabbdfe 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -1,14 +1,41 @@ import PhotoSwipeLightbox from "photoswipe/lightbox"; import Masonry from "masonry-layout"; -new PhotoSwipeLightbox({ +const lightboxCaptionHeight = 5 * parseFloat(getComputedStyle(document.documentElement).fontSize); + +const lightbox = new PhotoSwipeLightbox({ gallery: ".lightbox", - children: "a", + children: ".pswp-image", showAnimationDuration: 300, hideAnimationDuration: 300, initialZoomLevel: "fit", pswpModule: () => import("photoswipe"), -}).init(); + padding: { + top: lightboxCaptionHeight, + bottom: lightboxCaptionHeight, + left: 0, + right: 0, + } +}); + +lightbox.on("uiRegister", function () { + lightbox.pswp.ui.registerElement({ + name: "caption", + order: 9, + isButton: false, + appendTo: "root", + onInit: (el, _) => { + lightbox.pswp.on("change", () => { + const element = lightbox.pswp.currSlide.data.element; + el.innerHTML = + element?.parentElement.querySelector(".pswp-caption-content") + ?.innerHTML || ""; + }); + }, + }); +}); + +lightbox.init(); const masonryContainers = document.querySelectorAll(".masonry"); masonryContainers.forEach((container) => { diff --git a/assets/sass/common.scss b/assets/sass/common.scss index c2d997f..91609d1 100644 --- a/assets/sass/common.scss +++ b/assets/sass/common.scss @@ -12,6 +12,10 @@ a { color: var(--text-600); } +a:hover { + color: var(--text-700); +} + h1, h2, h3, diff --git a/assets/sass/footer.scss b/assets/sass/footer.scss index cbca1fd..d7aa6ff 100644 --- a/assets/sass/footer.scss +++ b/assets/sass/footer.scss @@ -16,12 +16,11 @@ color: color-mix(in srgb, var(--text) 30%, var(--background)); a { - text-decoration: none; color: inherit; } a:hover { - color: var(--text-900); + color: var(--text-800); } .footer-nav { diff --git a/assets/sass/header.scss b/assets/sass/header.scss index 4478da8..a6ed663 100644 --- a/assets/sass/header.scss +++ b/assets/sass/header.scss @@ -12,12 +12,11 @@ align-items: center; a { - text-decoration: none; color: inherit; } a:hover { - color: var(--text-900); + color: var(--text-800); } .site-title { @@ -83,7 +82,7 @@ gap: 2rem; li a { - font-size: 1.25rem; + font-size: 1.5rem; } } } diff --git a/assets/sass/list.scss b/assets/sass/list.scss index 93098a7..d9ae6ef 100644 --- a/assets/sass/list.scss +++ b/assets/sass/list.scss @@ -56,7 +56,6 @@ main.with-meta { .post { display: block; color: inherit; - text-decoration: none; &:not(:first-child) { margin-top: 4rem; @@ -81,7 +80,7 @@ main.with-meta { .post:hover .title, .post:hover .summary { - color: var(--text-900); + color: var(--text-800); } } diff --git a/assets/sass/photoswipe.scss b/assets/sass/photoswipe.scss index aa62fe7..1fab5e5 100644 --- a/assets/sass/photoswipe.scss +++ b/assets/sass/photoswipe.scss @@ -9,3 +9,29 @@ var(--background) ); } + +.pswp-caption-content { + display: none; +} + +.pswp__caption { + position: fixed; + bottom: 0; + width: 100%; + height: 5rem; + padding: 1rem 2rem; + text-align: center; + line-height: 1.5rem; + + .meta { + font-size: 0.7rem; + } + + a { + color: inherit; + } + + a:hover { + color: var(--text-800); + } +} diff --git a/layouts/partials/components/image/index.html b/layouts/partials/components/image/index.html index e5683a5..c5e8cd5 100644 --- a/layouts/partials/components/image/index.html +++ b/layouts/partials/components/image/index.html @@ -3,8 +3,10 @@