Add photoswipe captions
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,14 +1,41 @@
|
|||||||
import PhotoSwipeLightbox from "photoswipe/lightbox";
|
import PhotoSwipeLightbox from "photoswipe/lightbox";
|
||||||
import Masonry from "masonry-layout";
|
import Masonry from "masonry-layout";
|
||||||
|
|
||||||
new PhotoSwipeLightbox({
|
const lightboxCaptionHeight = 5 * parseFloat(getComputedStyle(document.documentElement).fontSize);
|
||||||
|
|
||||||
|
const lightbox = new PhotoSwipeLightbox({
|
||||||
gallery: ".lightbox",
|
gallery: ".lightbox",
|
||||||
children: "a",
|
children: ".pswp-image",
|
||||||
showAnimationDuration: 300,
|
showAnimationDuration: 300,
|
||||||
hideAnimationDuration: 300,
|
hideAnimationDuration: 300,
|
||||||
initialZoomLevel: "fit",
|
initialZoomLevel: "fit",
|
||||||
pswpModule: () => import("photoswipe"),
|
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");
|
const masonryContainers = document.querySelectorAll(".masonry");
|
||||||
masonryContainers.forEach((container) => {
|
masonryContainers.forEach((container) => {
|
||||||
|
@@ -12,6 +12,10 @@ a {
|
|||||||
color: var(--text-600);
|
color: var(--text-600);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
color: var(--text-700);
|
||||||
|
}
|
||||||
|
|
||||||
h1,
|
h1,
|
||||||
h2,
|
h2,
|
||||||
h3,
|
h3,
|
||||||
|
@@ -16,12 +16,11 @@
|
|||||||
color: color-mix(in srgb, var(--text) 30%, var(--background));
|
color: color-mix(in srgb, var(--text) 30%, var(--background));
|
||||||
|
|
||||||
a {
|
a {
|
||||||
text-decoration: none;
|
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:hover {
|
a:hover {
|
||||||
color: var(--text-900);
|
color: var(--text-800);
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer-nav {
|
.footer-nav {
|
||||||
|
@@ -12,12 +12,11 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
a {
|
a {
|
||||||
text-decoration: none;
|
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:hover {
|
a:hover {
|
||||||
color: var(--text-900);
|
color: var(--text-800);
|
||||||
}
|
}
|
||||||
|
|
||||||
.site-title {
|
.site-title {
|
||||||
@@ -83,7 +82,7 @@
|
|||||||
gap: 2rem;
|
gap: 2rem;
|
||||||
|
|
||||||
li a {
|
li a {
|
||||||
font-size: 1.25rem;
|
font-size: 1.5rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -56,7 +56,6 @@ main.with-meta {
|
|||||||
.post {
|
.post {
|
||||||
display: block;
|
display: block;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
text-decoration: none;
|
|
||||||
|
|
||||||
&:not(:first-child) {
|
&:not(:first-child) {
|
||||||
margin-top: 4rem;
|
margin-top: 4rem;
|
||||||
@@ -81,7 +80,7 @@ main.with-meta {
|
|||||||
|
|
||||||
.post:hover .title,
|
.post:hover .title,
|
||||||
.post:hover .summary {
|
.post:hover .summary {
|
||||||
color: var(--text-900);
|
color: var(--text-800);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,3 +9,29 @@
|
|||||||
var(--background)
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -3,8 +3,10 @@
|
|||||||
<figure class="captioned-image lightbox">
|
<figure class="captioned-image lightbox">
|
||||||
<a
|
<a
|
||||||
href="{{- .RelPermalink -}}"
|
href="{{- .RelPermalink -}}"
|
||||||
|
data-pswp-src="{{- .RelPermalink -}}"
|
||||||
data-pswp-width="{{- .Width -}}"
|
data-pswp-width="{{- .Width -}}"
|
||||||
data-pswp-height="{{- .Height -}}"
|
data-pswp-height="{{- .Height -}}"
|
||||||
|
class="pswp-image"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
src="{{- .RelPermalink -}}"
|
src="{{- .RelPermalink -}}"
|
||||||
|
@@ -2,13 +2,16 @@
|
|||||||
<div class="grid-sizer"></div>
|
<div class="grid-sizer"></div>
|
||||||
{{ range sort .Pages "Date" "desc" }}
|
{{ range sort .Pages "Date" "desc" }}
|
||||||
{{ if not .Params.private }}
|
{{ if not .Params.private }}
|
||||||
|
{{ $page := . }}
|
||||||
{{ $imageData := partial "components/image/reflect.html" .Params.hero }}
|
{{ $imageData := partial "components/image/reflect.html" .Params.hero }}
|
||||||
{{ with $imageData.image }}
|
{{ with $imageData.image }}
|
||||||
<div class="image grid-item">
|
<div class="image grid-item">
|
||||||
<a
|
<a
|
||||||
href="{{- .RelPermalink -}}"
|
href="{{- $page.RelPermalink -}}"
|
||||||
|
data-pswp-src="{{- .RelPermalink -}}"
|
||||||
data-pswp-width="{{- .Width -}}"
|
data-pswp-width="{{- .Width -}}"
|
||||||
data-pswp-height="{{- .Height -}}"
|
data-pswp-height="{{- .Height -}}"
|
||||||
|
class="pswp-image"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
src="{{- .RelPermalink -}}"
|
src="{{- .RelPermalink -}}"
|
||||||
@@ -19,6 +22,16 @@
|
|||||||
{{ with $imageData.alt }}alt="{{- . -}}"{{ end }}
|
{{ with $imageData.alt }}alt="{{- . -}}"{{ end }}
|
||||||
/>
|
/>
|
||||||
</a>
|
</a>
|
||||||
|
<div class="pswp-caption-content">
|
||||||
|
<div>
|
||||||
|
{{ upper $page.Title }}
|
||||||
|
<div class="meta">
|
||||||
|
{{ $page.Date | time.Format ":date_medium" }}
|
||||||
|
·
|
||||||
|
<a href="{{- $page.RelPermalink -}}">View Post</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
Reference in New Issue
Block a user