tpl/tplimpl: Modify figure shortcode to look for page resource

Closes #12244
Closes #12245
This commit is contained in:
Joe Mooring 2024-03-13 22:38:15 -07:00 committed by Bjørn Erik Pedersen
parent 9ca1de09dd
commit 48a0fea87a
2 changed files with 36 additions and 27 deletions

View file

@ -709,7 +709,7 @@ func TestPageWithShortCodeInSummary(t *testing.T) {
assertFunc := func(t *testing.T, ext string, pages page.Pages) { assertFunc := func(t *testing.T, ext string, pages page.Pages) {
p := pages[0] p := pages[0]
checkPageTitle(t, p, "Simple") checkPageTitle(t, p, "Simple")
checkPageContent(t, p, normalizeExpected(ext, "<p>Summary Next Line. <figure><img src=\"/not/real\"/> </figure> . More text here.</p><p>Some more text</p>")) checkPageContent(t, p, normalizeExpected(ext, "<p>Summary Next Line. <figure><img src=\"/not/real\"> </figure> . More text here.</p><p>Some more text</p>"))
checkPageSummary(t, p, "Summary Next Line. . More text here. Some more text") checkPageSummary(t, p, "Summary Next Line. . More text here. Some more text")
checkPageType(t, p, "page") checkPageType(t, p, "page")
} }

View file

@ -1,29 +1,38 @@
<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}> <figure{{ with .Get "class" }} class="{{ . }}"{{ end }}>
{{- if .Get "link" -}} {{- if .Get "link" -}}
<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}> <a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
{{- end -}}
{{- $u := urls.Parse (.Get "src") -}}
{{- $src := $u.String -}}
{{- if not $u.IsAbs -}}
{{- with or (.Page.Resources.Get $u.Path) (resources.Get $u.Path) -}}
{{- $src = .RelPermalink -}}
{{- end -}} {{- end -}}
<img src="{{ .Get "src" }}" {{- end -}}
{{- if or (.Get "alt") (.Get "caption") }}
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}" <img src="{{ $src }}"
{{- end -}} {{- if or (.Get "alt") (.Get "caption") }}
{{- with .Get "width" }} width="{{ . }}"{{ end -}} alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}"
{{- with .Get "height" }} height="{{ . }}"{{ end -}} {{- end -}}
{{- with .Get "loading" }} loading="{{ . }}"{{ end -}} {{- with .Get "width" }} width="{{ . }}"{{ end -}}
/><!-- Closing img tag --> {{- with .Get "height" }} height="{{ . }}"{{ end -}}
{{- if .Get "link" }}</a>{{ end -}} {{- with .Get "loading" }} loading="{{ . }}"{{ end -}}
{{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}} ><!-- Closing img tag -->
<figcaption> {{- if .Get "link" }}</a>{{ end -}}
{{ with (.Get "title") -}} {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
<h4>{{ . }}</h4> <figcaption>
{{- end -}} {{ with (.Get "title") -}}
{{- if or (.Get "caption") (.Get "attr") -}}<p> <h4>{{ . }}</h4>
{{- .Get "caption" | markdownify -}} {{- end -}}
{{- with .Get "attrlink" }} {{- if or (.Get "caption") (.Get "attr") -}}<p>
<a href="{{ . }}"> {{- .Get "caption" | markdownify -}}
{{- end -}} {{- with .Get "attrlink" }}
{{- .Get "attr" | markdownify -}} <a href="{{ . }}">
{{- if .Get "attrlink" }}</a>{{ end }}</p> {{- end -}}
{{- end }} {{- .Get "attr" | markdownify -}}
</figcaption> {{- if .Get "attrlink" }}</a>{{ end }}</p>
{{- end }} {{- end }}
</figcaption>
{{- end }}
</figure> </figure>