Skip to content

Commit a0adf31

Browse files
committed
Add exif info as an option
1 parent aa5c978 commit a0adf31

File tree

7 files changed

+113
-1
lines changed

7 files changed

+113
-1
lines changed

‎README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ Also See the annotated [index.html](exampleSite/layouts/index.html) for a brief
4444
shuffle = false
4545

4646
# Reverse the order of the images in the gallery.
47-
reverse = true
47+
reverse = false
48+
49+
# Enable Exif data in the gallery.
50+
# See https://gohugo.io/content-management/image-processing/#exif-data for how to filter tags.
51+
enable_exif = false
4852
```
4953

5054

‎assets/css/gallerydeluxe/styles.css‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,43 @@
4848
opacity: 0;
4949
}
5050

51+
.gd-modal-exif {
52+
position: absolute;
53+
z-index: 20;
54+
bottom: 10px;
55+
right: 10px;
56+
color: #fff;
57+
background-color: #8a8a8a;
58+
padding: 0.75rem;
59+
opacity: 0.75;
60+
filter: drop-shadow(-1px -1px 2px #ccc);
61+
}
62+
63+
.gd-modal-exif-ontimeout {
64+
transition: opacity 2s ease-out;
65+
opacity: 0;
66+
}
67+
68+
.gd-modal-exif:hover {
69+
opacity: 1;
70+
cursor: pointer;
71+
}
72+
73+
.gd-modal-exif dl dd {
74+
display: inline;
75+
margin: 0;
76+
}
77+
78+
.gd-modal-exif dl dd:after {
79+
display: block;
80+
content: "";
81+
}
82+
83+
.gd-modal-exif dl dt {
84+
display: inline-block;
85+
min-width: 100px;
86+
}
87+
5188
.gd-modal-close {
5289
position: absolute;
5390
z-index: 20;

‎assets/js/gallerydeluxe/src/index.js‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,40 @@ let GalleryDeluxe = {
111111
if (activeImage) {
112112
let modal = document.getElementById('gd-modal');
113113

114+
if (params.enable_exif) {
115+
let exif = document.getElementById('gd-modal-exif');
116+
const onTimeOutClass = 'gd-modal-exif-ontimeout';
117+
exif.classList.remove(onTimeOutClass);
118+
let child = exif.lastElementChild;
119+
while (child) {
120+
exif.removeChild(child);
121+
child = exif.lastElementChild;
122+
}
123+
let dl = document.createElement('dl');
124+
exif.appendChild(dl);
125+
126+
const addTag = (tag, value) => {
127+
let dt = document.createElement('dt');
128+
dt.innerText = camelToTitle(tag);
129+
dl.appendChild(dt);
130+
let dd = document.createElement('dd');
131+
dd.innerText = value;
132+
dl.appendChild(dd);
133+
};
134+
135+
let date = new Date(activeImage.exif.Date);
136+
var dateString = new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString().split('T')[0];
137+
addTag('Date', dateString);
138+
let tags = activeImage.exif.Tags;
139+
for (const tag in tags) {
140+
addTag(tag, tags[tag]);
141+
}
142+
143+
setTimeout(() => {
144+
exif.classList.add(onTimeOutClass);
145+
}, 1000);
146+
}
147+
114148
let thumbnail = new Image();
115149
thumbnail.classList.add('gd-modal-content');
116150
thumbnail.width = activeImage.width;
@@ -208,4 +242,10 @@ let GalleryDeluxe = {
208242
},
209243
};
210244

245+
function camelToTitle(text) {
246+
return text.replace(/([A-Z])/g, ' $1').replace(/^./, function (str) {
247+
return str.toUpperCase();
248+
});
249+
}
250+
211251
export default GalleryDeluxe;

‎exampleSite/assets/css/styles.css‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ body {
44
margin: 0;
55
padding: 0;
66
background-color: #101010;
7+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
8+
Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
9+
font-size: 14px;
710
}
811

912
.logo {

‎exampleSite/config.toml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ disableKinds = ["section", "taxonomy", "term"]
1010
# Reverse the order of the images in the gallery.
1111
reverse = true
1212

13+
# Enable Exif data in the gallery.
14+
# See https://gohugo.io/content-management/image-processing/#exif-data for how to filter tags.
15+
enable_exif = true
16+
1317
[caches]
1418
[caches.images]
1519
dir = ':cacheDir/gallerydeluxe'
@@ -19,6 +23,10 @@ disableKinds = ["section", "taxonomy", "term"]
1923
resampleFilter = "CatmullRom"
2024
quality = 71
2125
anchor = "smart"
26+
[imaging.exif]
27+
disableDate = false
28+
disableLatLong = true
29+
includeFields = 'Artist|LensModel|FNumber|ExposureTime'
2230

2331
[server]
2432
[[server.headers]]

‎exampleSite/layouts/index.html‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616

1717
{{/* 'images' is a path to a leaf bundle with a index.md file and lots of JPG images. */}}
1818
{{ $gallery := partial "gallerydeluxe/init.html" (dict "sourcePath" "images") }}
19+
{{ $params := site.Params.gallerydeluxe }}
1920
{{/* We currently only support 1 gallery per page, which is create4 by an element with id 'gallerydeluxe',
2021
and a valid data url.
2122
*/}}
2223
<body id="gallerydeluxe" data-gd-image-data-url="{{ $gallery.imageDataUrl }}">
2324
<div id="gd-modal" class="gd-modal">
2425
<span id="gd-modal-close" class="gd-modal-close">&times;</span>
26+
{{ if $params.enable_exif }}
27+
<div id="gd-modal-exif" class="gd-modal-exif"></div>
28+
{{ end }}
2529
</div>
2630
</body>
2731
</html>

‎layouts/partials/gallerydeluxe/init.html‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,35 @@
22
{{ $gallery := site.GetPage $sourcePath }}
33
{{ $imageDataUrl := "" }}
44
{{ $s := slice }}
5+
{{ $params := site.Params.gallerydeluxe }}
56
{{ with $gallery }}
67
{{ $images := $gallery.Resources.Match "**.jpg" }}
78
{{ range $images }}
89
{{ $thumbs := partial "gallerydeluxe/create-thumbs.html" . }}
910
{{ $20 := (index $thumbs "20") }}
1011
{{ $colors := slice }}
12+
{{ $exif := dict }}
13+
{{ if $params.enable_exif }}
14+
{{/* Workaround for https://github.com/gohugoio/hugo/issues/10345 */}}
15+
{{ $tags := newScratch }}
16+
{{ range $k, $v := .Exif.Tags }}
17+
{{ $tags.Set $k $v }}
18+
{{ end }}
19+
{{ $exif = dict
20+
"Tags" $tags.Values
21+
"Date" .Exif.Date
22+
"Lat" .Exif.Lat
23+
"Long" .Exif.Long
24+
}}
25+
{{ end }}
1126
{{ if (ge hugo.Version "0.104") }}
1227
{{/* .Colors method was added in Hugo 0.104.0 */}}
1328
{{ $colors = $20.Colors }}
1429
{{ end }}
1530
{{ $m := dict
1631
"name" .Name
1732
"full" .RelPermalink
33+
"exif" $exif
1834
"width" .Width
1935
"height" .Height
2036
"colors" $colors

0 commit comments

Comments
 (0)