Skip to content

Commit

Permalink
harden auto-h1-description if .Content nil. figure htitles to h6. sit…
Browse files Browse the repository at this point in the history
…emap also takes page bundle images.
  • Loading branch information
yaythomas committed Sep 8, 2020
1 parent df25344 commit 2795eb0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
5 changes: 4 additions & 1 deletion layouts/partials/page-content/auto-h1-description.html
Original file line number Diff line number Diff line change
@@ -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) -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/shortcodes/figure-asset.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
<figcaption>
{{ with (.Get "title") -}}
<h4>{{ . }}</h4>
<h6>{{ . }}</h6>
{{- end -}}
{{- if or (.Get "caption") (.Get "attr") -}}<small>
{{- .Get "caption" | markdownify -}}
Expand Down
34 changes: 34 additions & 0 deletions layouts/shortcodes/figure-bundle.html
Original file line number Diff line number Diff line change
@@ -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.
*/}}
<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}>
{{- if .Get "link" -}}
<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
{{- end }}
<img src="{{ ($.Page.Resources.GetMatch (.Get "src") | fingerprint).Permalink }}"
{{- if or (.Get "alt") (.Get "caption") }}
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}"
{{- end -}}
{{- with .Get "width" }} width="{{ . }}"{{ end -}}
{{- with .Get "height" }} height="{{ . }}"{{ end -}}
/> <!-- Closing img tag -->
{{- if .Get "link" }}</a>{{ end -}}
{{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
<figcaption>
{{ with (.Get "title") -}}
<h6>{{ . }}</h6>
{{- end -}}
{{- if or (.Get "caption") (.Get "attr") -}}<small>
{{- .Get "caption" | markdownify -}}
{{- with .Get "attrlink" -}}
<a href="{{ . }}">
{{- end -}}
{{- .Get "attr" | markdownify -}}
{{- if .Get "attrlink" }}</a>{{ end }}</small>
{{- end }}
</figcaption>
{{- end }}
</figure>
12 changes: 9 additions & 3 deletions layouts/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
/>{{ end }}{{ range .Params.sitemap_images }}
<image:image>
<image:loc>{{ (resources.Get .src | fingerprint).Permalink }}</image:loc>{{ with .title }}
<image:title>{{ . }}</image:title>{{ end }}
</image:image>
{{ end }}{{ end }}
<image:title>{{ . }}</image:title>{{ end }}{{ with .caption }}
<image:caption>{{ . }}</image:caption>{{ end }}
</image:image>{{ end }}{{ range .Resources.ByType "image" }}
<image:image>
<image:loc>{{ ( . | fingerprint).Permalink }}</image:loc>{{ with .Title }}
<image:title>{{ . }}</image:title>{{ end }}{{ with .Params.caption }}
<image:caption>{{ . }}</image:caption>{{ end }}
</image:image>{{ end }}
</url>
{{ end }}
{{ end }}
</urlset>

0 comments on commit 2795eb0

Please sign in to comment.