From f28cf4615c896e75251d79eb7ec12856f8ee4697 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Mon, 28 Dec 2020 10:03:41 +0200 Subject: [PATCH] layouts: Make featured posts configurable For now it gets the first three posts with "featured: true" in their frontmatter and displays them in a random order (so no control over the placement of large feature or two smaller features). TODO: gracefully handle the case where there are no pages with the "featured: true" frontmatter so new users don't see a super weird and broken front page. --- layouts/_default/home.html | 2 +- layouts/partials/featured.html | 4 +- layouts/shortcodes/figure.html | 92 ---------------------------------- 3 files changed, 3 insertions(+), 95 deletions(-) delete mode 100644 layouts/shortcodes/figure.html diff --git a/layouts/_default/home.html b/layouts/_default/home.html index eb32e9f..1ab1353 100644 --- a/layouts/_default/home.html +++ b/layouts/_default/home.html @@ -39,7 +39,7 @@ {{ $truncate := default true .Site.Params.truncate }} -{{ $paginator := .Paginate (where .Site.RegularPages "Section" "in" .Site.Params.mainSections) }} +{{ $paginator := .Paginate (where .Site.RegularPages "Params.featured" "ne" true) }} {{ range $paginator.Pages }} {{ if $truncate }} {{ .Render "summary" }} diff --git a/layouts/partials/featured.html b/layouts/partials/featured.html index d38f718..50af808 100644 --- a/layouts/partials/featured.html +++ b/layouts/partials/featured.html @@ -1,6 +1,6 @@ {{ $dateFormat := default "Mon Jan 2, 2006" (index .Site.Params "date_format") }} -{{/* get three random posts: 1 for large feature, 2 for small features */}} -{{ range $index, $element := first 3 (where .Site.RegularPages "Section" "in" .Site.Params.mainSections) | shuffle }} +{{/* get three random featured posts: 1 for large feature, 2 for small features */}} +{{ range $index, $element := first 3 (where .Site.RegularPages "Params.featured" true) | shuffle }} {{ if eq $index 0 }}
diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html deleted file mode 100644 index e66e322..0000000 --- a/layouts/shortcodes/figure.html +++ /dev/null @@ -1,92 +0,0 @@ -{{/* - -figure with auto-resizing and srcset v2020-11-30 - -Drop-in replacement for Hugo's figure shortcode as of 2020-05-02 that uses img srcset -to enable browsers to download only the resolution that they need. - -The resizing and srcset magic only works for images that are part of the page -bundle. It will fall back to stock Hugo figure behaviour otherwise. - -Improvements that were initially out of reach of my Hugo template programming "skills" -but have now been taken care of: -- [x] gracefully handle images that are not in page bundle, i.e. no image processing available -- [x] use a single configurable sizes array, and derive everything from there - -See https://cpbotha.net/2020/05/02/drop-in-replacement-for-hugo-figure-shortcode-with-img-srcset-support/ - -- original srcset img shortcode from: https://laurakalbag.com/processing-responsive-images-with-hugo/ -- original hugo figure shortcode from: https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/shortcodes/figure.html -- no unnecessary resizes and more nudges by Stéfan van der Walt https://mentat.za.net/ -- mashing together and srcset logic fixes by Charl P. Botha https://cpbotha.net/ - -Changes: -- 2020-11-30 handle images that are rotated 90 degrees (should handle more eventually) -- 2020-05-10 fall back to stock Hugo behaviour when no page bundle found -- 2020-05-04 no unnecessary resizes, sizes in array -- 2020-05-02 initial release - -*/}} - -{{/* hugo will resize to all of these sizes that are smaller than your original. configure if you like! */}} -{{ $sizes := (slice "480" "800" "1200" "1500") }} - -{{/* get file that matches the filename as specified as src="" in shortcode */}} -{{ $src := .Page.Resources.GetMatch (printf "*%s*" (.Get "src")) }} - - - {{- if .Get "link" -}} - - {{- end }} - {{ with .Get - {{- if .Get "link" }}{{ end -}} - {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}} -
- {{ with (.Get "title") -}} -

{{ . }}

- {{- end -}} - {{- if or (.Get "caption") (.Get "attr") -}}

- {{- .Get "caption" | markdownify -}} - {{- with .Get "attrlink" }} - - {{- end -}} - {{- .Get "attr" | markdownify -}} - {{- if .Get "attrlink" }}{{ end }}

- {{- end }} -
- {{- end }} -