From 2795eb0eabf307ca1fa746a9b3aa66c5f081bb3e Mon Sep 17 00:00:00 2001 From: thomas <18520168+yaythomas@users.noreply.github.com> Date: Tue, 8 Sep 2020 18:23:40 +0100 Subject: [PATCH] harden auto-h1-description if .Content nil. figure htitles to h6. sitemap also takes page bundle images. --- .../page-content/auto-h1-description.html | 5 ++- layouts/shortcodes/figure-asset.html | 2 +- layouts/shortcodes/figure-bundle.html | 34 +++++++++++++++++++ layouts/sitemap.xml | 12 +++++-- 4 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 layouts/shortcodes/figure-bundle.html diff --git a/layouts/partials/page-content/auto-h1-description.html b/layouts/partials/page-content/auto-h1-description.html index f9d1d14..3b9b9ca 100644 --- a/layouts/partials/page-content/auto-h1-description.html +++ b/layouts/partials/page-content/auto-h1-description.html @@ -1,4 +1,7 @@ -{{- $isEmptyContent := eq (len .Content) 0 -}} {{/* (not .File) */}} +{{- $isEmptyContent := true -}} +{{- with .Content -}} {{/* avoid nil pointer err on (len .Content). this happens if a shortcode malfunctions and hides real error info. */}} + {{- $isEmptyContent = eq (len .) 0 -}} {{/* (not .File) */}} +{{- end -}} {{- $showOnlyOnEmpty := .Param "show_auto_heading_only_on_empty_content" | default true -}} {{- if eq $isEmptyContent $showOnlyOnEmpty -}} {{- $showListTitle := and .IsNode (.Param "list_show_auto_title" | default true) -}} diff --git a/layouts/shortcodes/figure-asset.html b/layouts/shortcodes/figure-asset.html index 19c572e..9cc08a9 100644 --- a/layouts/shortcodes/figure-asset.html +++ b/layouts/shortcodes/figure-asset.html @@ -18,7 +18,7 @@ {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
{{ with (.Get "title") -}} -

{{ . }}

+
{{ . }}
{{- end -}} {{- if or (.Get "caption") (.Get "attr") -}} {{- .Get "caption" | markdownify -}} diff --git a/layouts/shortcodes/figure-bundle.html b/layouts/shortcodes/figure-bundle.html new file mode 100644 index 0000000..355f5b5 --- /dev/null +++ b/layouts/shortcodes/figure-bundle.html @@ -0,0 +1,34 @@ +{{/* + code copies entire from hugo built-in figure template, with grateful thanks. + only addition is on .src, to get get image from page bundle with + fingerprint rather than just a straight string input. also small rather + than p for caption. +*/}} + + {{- 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 }} + \ No newline at end of file diff --git a/layouts/sitemap.xml b/layouts/sitemap.xml index 8840d72..1b8adc4 100644 --- a/layouts/sitemap.xml +++ b/layouts/sitemap.xml @@ -20,9 +20,15 @@ />{{ end }}{{ range .Params.sitemap_images }} {{ (resources.Get .src | fingerprint).Permalink }}{{ with .title }} - {{ . }}{{ end }} - - {{ end }}{{ end }} + {{ . }}{{ end }}{{ with .caption }} + {{ . }}{{ end }} + {{ end }}{{ range .Resources.ByType "image" }} + + {{ ( . | fingerprint).Permalink }}{{ with .Title }} + {{ . }}{{ end }}{{ with .Params.caption }} + {{ . }}{{ end }} + {{ end }} {{ end }} + {{ end }} \ No newline at end of file