From 57947282ce3a63b23d4b83b942c46c3840a83a8a Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 30 Oct 2022 11:31:47 -0700 Subject: [PATCH] Add a shortcode to embed a photo post in a blog post --- layouts/partials/images/photo_thumbnail.html | 8 ++++++++ layouts/shortcodes/photo.html | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 layouts/partials/images/photo_thumbnail.html create mode 100644 layouts/shortcodes/photo.html diff --git a/layouts/partials/images/photo_thumbnail.html b/layouts/partials/images/photo_thumbnail.html new file mode 100644 index 0000000..16940a3 --- /dev/null +++ b/layouts/partials/images/photo_thumbnail.html @@ -0,0 +1,8 @@ +{{- $thumbnailResource := .Resources.GetMatch (index .Page.Params "thumbnail") + | default (index (.Page.Resources.ByType "image") 0) -}} +{{- if not $thumbnailResource -}} + {{- errorf "No thumbnail available for %s" .Page.Permalink }} +{{- end -}} +{{- $orientation := partial "images/orientation_angle.html" $thumbnailResource -}} +{{- $thumbnail := $thumbnailResource.Fit (printf "%dx%d r%d" .Width .Height (sub 360 $orientation)) -}} +{{ return $thumbnail }} diff --git a/layouts/shortcodes/photo.html b/layouts/shortcodes/photo.html new file mode 100644 index 0000000..f5e0937 --- /dev/null +++ b/layouts/shortcodes/photo.html @@ -0,0 +1,8 @@ +{{- with $photoPage := $.Page.GetPage (printf "photos/%s" (.Get 0)) -}} + {{- $thumbnail := partial "images/photo_thumbnail.html" (dict "Page" . "Width" 1280 "Height" 1280) -}} + + + +{{- else -}} + {{- errorf "No page matching '%s'" (.Get 0) -}} +{{- end -}}