Skip to content

Commit fa76cfe

Browse files
committed
Fix the gallery format
1 parent 2a5d272 commit fa76cfe

File tree

7 files changed

+95
-9
lines changed

7 files changed

+95
-9
lines changed

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"@primer/view-components": "^0.48.0",
1111
"autoprefixer": "^10.4.23",
1212
"dompurify": "^3.3.1",
13+
"jquery": "^3.7.1",
1314
"littlefoot": "^4.1.3",
1415
"magnific-popup": "^1.2.0",
1516
"postcss": "^8.5.6",

photos/galleries/snoqualmie-2021/captions.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
IMG_8996.png: The cloudy mountaintops from the parking lot
22
IMG_8998.png: The east entrance to the tunnel
3-
IMG_8999.png: Looking back east, with the tunnel lit by my red read light
3+
IMG_8999.png: Looking back east, with the tunnel lit by my red rear light
44
IMG_9005.png: A family walking away from me, carrying a flashlight
55
IMG_9006.png: The west end of the tunnel has a small picnic area with, I'm told, quite a view. Sometimes.
66
IMG_9009.png: The mountainside

themes/offby1/scss/offby1/_magnific-popup.scss

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,34 @@
7474
.mfp-counter {
7575
color: var(--color-mute);
7676
}
77+
78+
// EXIF details expansion
79+
.mfp-title {
80+
details.mfp-exif-details {
81+
margin-top: 0.5rem;
82+
83+
summary {
84+
cursor: pointer;
85+
color: var(--color-mute);
86+
font-size: 0.875rem;
87+
user-select: none;
88+
transition: color 0.2s ease;
89+
90+
&:hover {
91+
color: var(--color-primary);
92+
}
93+
94+
&::marker {
95+
color: var(--color-primary);
96+
}
97+
}
98+
99+
small {
100+
display: block;
101+
margin-top: 0.25rem;
102+
color: var(--color-mute);
103+
font-size: 0.75rem;
104+
line-height: 1.4;
105+
}
106+
}
107+
}

themes/offby1/static/js/gallery.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ document.addEventListener('DOMContentLoaded', function() {
3232
}
3333
});
3434

35-
// Initialize Magnific Popup on all gallery images (do this once after processing all sections)
35+
// Initialize Magnific Popup on manually created gallery images
3636
if (document.querySelectorAll('.gallery-image').length > 0) {
3737
jQuery('.gallery-image').magnificPopup({
3838
type: 'image',
@@ -46,4 +46,50 @@ document.addEventListener('DOMContentLoaded', function() {
4646
}
4747
});
4848
}
49+
50+
// Initialize Magnific Popup for photos plugin galleries
51+
// These are already created by the pelican photos plugin
52+
if (document.querySelectorAll('.gallery-item').length > 0) {
53+
jQuery('.gallery-item').magnificPopup({
54+
type: 'image',
55+
gallery: {
56+
enabled: true,
57+
navigateByImgClick: true,
58+
preload: [0, 1]
59+
},
60+
image: {
61+
titleSrc: function(item) {
62+
// Use data-caption if available, otherwise use title attribute
63+
const caption = item.el.attr('data-caption');
64+
const exif = item.el.attr('data-exif');
65+
let title = caption || item.el.attr('title') || '';
66+
67+
// Add EXIF data as an expandable details section if available
68+
if (exif && exif !== 'None') {
69+
title += '<details class="mfp-exif-details"><summary>Photo details</summary><small>' + exif + '</small></details>';
70+
}
71+
72+
return title;
73+
},
74+
markup: '<div class="mfp-figure">' +
75+
'<div class="mfp-close"></div>' +
76+
'<div class="mfp-img"></div>' +
77+
'<div class="mfp-bottom-bar">' +
78+
'<div class="mfp-title"></div>' +
79+
'<div class="mfp-counter"></div>' +
80+
'</div>' +
81+
'</div>'
82+
},
83+
callbacks: {
84+
markupParse: function(template, values, item) {
85+
// Manually set the title HTML to avoid escaping
86+
if (values.title) {
87+
setTimeout(() => {
88+
template.find('.mfp-title').html(values.title);
89+
}, 0);
90+
}
91+
}
92+
}
93+
});
94+
}
4995
});

themes/offby1/templates/article.html.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
{% for name, photo, thumb, exif, caption in gallery %}
5353
<a href="{{ SITEURL }}/{{ photo }}"
5454
class="gallery-item"
55-
title="{{ name }}"
56-
{% if exif %}data-exif="{{ exif }}"{% endif %}
57-
{% if caption %}data-caption="{{ caption }}"{% endif %}>
55+
title="{{ name }}"{% if exif %}
56+
data-exif="{{ exif }}"{% endif %}{% if caption %}
57+
data-caption="{{ caption }}"{% endif %}>
5858
<img src="{{ SITEURL }}/{{ thumb }}" alt="{{ caption or name }}" loading="lazy">
5959
{% if caption %}
6060
<div class="gallery-caption">{{ caption }}</div>

themes/offby1/templates/base.html.j2

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
{% endassets %}
4343

4444
{# Magnific Popup CSS #}
45-
{% assets output="css/magnific-popup.css", "magnific-popup/dist/magnific-popup.css" %}
45+
{% assets output="css/magnific-popup.min.css", "magnific-popup/dist/magnific-popup.css" %}
4646
<link rel="stylesheet" href="{{ SITEURL }}/{{ ASSET_URL }}" type="text/css" />
4747
{% endassets %}
4848

@@ -104,16 +104,18 @@
104104

105105
{% block scripts %}
106106
{# jQuery - required for Magnific Popup #}
107-
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
107+
{% assets output="js/jquery.min.js", "jquery/dist/jquery.min.js" %}
108+
<script src="{{ SITEURL }}/{{ ASSET_URL }}"></script>
109+
{% endassets %}
108110

109111
{# Magnific Popup for image galleries #}
110-
{% assets output="js/magnific-popup.js", "magnific-popup/dist/jquery.magnific-popup.js" %}
112+
{% assets output="js/magnific-popup.min.js", "magnific-popup/dist/jquery.magnific-popup.min.js" %}
111113
<script src="{{ SITEURL }}/{{ ASSET_URL }}"></script>
112114
{% endassets %}
113115
<script src="{{ SITEURL }}/theme/js/gallery.js"></script>
114116

115117
{# Littlefoot footnotes - loaded from node_modules via webassets #}
116-
{% assets output="js/littlefoot.js", "littlefoot/dist/littlefoot.js" %}
118+
{% assets output="js/littlefoot.min.js", "littlefoot/dist/littlefoot.js" %}
117119
<script src="{{ SITEURL }}/{{ ASSET_URL }}"></script>
118120
{% endassets %}
119121
<script type="text/javascript">

0 commit comments

Comments
 (0)