Skip to content

Instantly share code, notes, and snippets.

@mitcdh
Last active January 12, 2024 20:32
Show Gist options
  • Save mitcdh/5f90aedb02c76077c0c666cc248d3e0f to your computer and use it in GitHub Desktop.
Save mitcdh/5f90aedb02c76077c0c666cc248d3e0f to your computer and use it in GitHub Desktop.
Autogeneration of Flickr galleries in hugo
<div class="photo-box">
<a href="https://www.flickr.com/photos/83515912@N03/53444202842" target="_blank">
<img src="https://c1.staticflickr.com/66/65535/53444202842_2286302d06_b.jpg" alt="R0000560" loading="lazy">
</a>
<a href="https://www.flickr.com/photos/83515912@N03/53444202807" target="_blank">
<img src="https://c1.staticflickr.com/66/65535/53444202807_4f2452d4f7_b.jpg" alt="R0000561" loading="lazy">
</a>
<a href="https://www.flickr.com/photos/83515912@N03/53444202782" target="_blank">
<img src="https://c1.staticflickr.com/66/65535/53444202782_41f0b5171f_b.jpg" alt="R0000568" loading="lazy">
</a>
<a href="https://www.flickr.com/photos/83515912@N03/53445263598" target="_blank">
<img src="https://c1.staticflickr.com/66/65535/53445263598_89f8870916_b.jpg" alt="R0000575" loading="lazy">
</a>
<a href="https://www.flickr.com/photos/83515912@N03/53445538565" target="_blank">
<img src="https://c1.staticflickr.com/66/65535/53445538565_85d6bc6566_b.jpg" alt="20231203_153608" loading="lazy">
</a>
<a href="https://www.flickr.com/photos/83515912@N03/53444202542" target="_blank">
<img src="https://c1.staticflickr.com/66/65535/53444202542_97dcc85d1c_b.jpg" alt="R0000579" loading="lazy">
</a>
<a href="https://www.flickr.com/photos/83515912@N03/53444202507" target="_blank">
<img src="https://c1.staticflickr.com/66/65535/53444202507_50e6bf7740_b.jpg" alt="R0000585" loading="lazy">
</a>
<a href="https://www.flickr.com/photos/83515912@N03/53445447724" target="_blank">
<img src="https://c1.staticflickr.com/66/65535/53445447724_60f74acbd6_b.jpg" alt="R0000590" loading="lazy">
</a>
<a href="https://www.flickr.com/photos/83515912@N03/53445263418" target="_blank">
<img src="https://c1.staticflickr.com/66/65535/53445263418_aa59539309_b.jpg" alt="R0000593" loading="lazy">
</a>
<a href="https://www.flickr.com/photos/83515912@N03/53445263428" target="_blank">
<img src="https://c1.staticflickr.com/66/65535/53445263428_2d7b2b230e_b.jpg" alt="R0000596" loading="lazy">
</a>
<a href="https://www.flickr.com/photos/83515912@N03/53444202257" target="_blank">
<img src="https://c1.staticflickr.com/66/65535/53444202257_2ae198bf86_b.jpg" alt="R0000597" loading="lazy">
</a>
<a href="https://www.flickr.com/photos/83515912@N03/53445538525" target="_blank">
<img src="https://c1.staticflickr.com/66/65535/53445538525_1e1b43e44e_b.jpg" alt="20231203_164707" loading="lazy">
</a>
<a href="https://www.flickr.com/photos/83515912@N03/53445538235" target="_blank">
<img src="https://c1.staticflickr.com/66/65535/53445538235_bcd7f6d1a6_b.jpg" alt="R0000604" loading="lazy">
</a>
</div>
{{ $url := . }}
{{ $photoset_id := "" }}
{{ $user_id := "" }}
{{ $regex := `https:\/\/w+?\.?flickr\.com\/photos\/([a-zA-Z0-9_@]+)\/(albums|sets|photosets)\/([0-9]+)\/?` }}
{{ $matches := findRE $regex $url }}
{{ if $matches }}
{{ $user_id = replaceRE $regex "$1" $url }}
{{ $photoset_id = replaceRE $regex "$3" $url }}
{{ end }}
{{ with site.Params.flickr.flickrApiKey }}
{{ $api_key := . }}
{{ $api_url := printf "%s%s%s%s%s" "https://api.flickr.com/services/rest/?format=json&method=flickr.photosets.getPhotos&photoset_id=" $photoset_id "&page=1&api_key=" $api_key "&nojsoncallback=1" }}
{{ $flickr := getJSON $api_url }}
{{ if $flickr }}
<div class="photo-box">
{{ with $flickr.photoset }}
{{ range .photo }}
<a href="https://www.flickr.com/photos/{{ $user_id }}/{{ .id }}" target="_blank">
<img src="https://c1.staticflickr.com/{{ .farm }}/{{ .server }}/{{ .id }}_{{ .secret }}_b.jpg" alt="{{ .title }}" loading="lazy">
</a>
{{ end }}
{{ end }}
</div>
{{ end }}
{{ end }}
---
title: Freezing Layover in Zurich, Switzerland
description: "Grounded in Zürich after some bad weather but my heart's up in the clouds. Unexpected layovers lead to unexpected friendships—particularly when you'd rather be airborne-shoutout to my new seagull (snowgull?) mates!"
date: 2023-12-03 01:00:00 +0000
flickr_embed: 'https://www.flickr.com/photos/83515912@N03/sets/72177720313855068'
image: '/images/freezing-layover-in-zurich-switzerland.jpg'
tags: [Album]
---
<!-- this should be embedded within single.html at the right place -->
{{ if .Params.flickr_embed }}
{{ partial "flickr-embed.html" .Params.flickr_embed }}
{{ end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment