-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make figure SC insert absolute links in the src attribute
- Fixes #4562 - So now the figure shortcode inserted images work fine on list pages and on sites with baseURL containing subdir too. - Support figure SC src attribute with protocol or two leading slashes - Update the figure shortcode + src attr tests to use BaseURL - Add tests for all of the above. Other: - White-space change syncup between figure SC and tests - Consistency edits: {{.}} -> {{ . }}, {{else}} -> {{ else }}, and similar
- Loading branch information
1 parent
ceaff7c
commit 384b350
Showing
5 changed files
with
131 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,36 @@ | ||
<!-- image --> | ||
<figure{{ with .Get "class" }} class="{{.}}"{{ end }}> | ||
{{ $image := .Get "src" }} | ||
<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="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}{{ end }}" {{ end }}{{ with .Get "width" }}width="{{.}}" {{ end }}{{ with .Get "height" }}height="{{.}}" {{ end }}/> | ||
{{ if .Get "link"}}</a>{{ end }} | ||
{{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}} | ||
<figcaption>{{ if isset .Params "title" }} | ||
<h4>{{ .Get "title" }}</h4>{{ end }} | ||
{{ if or (.Get "caption") (.Get "attr")}}<p> | ||
{{ .Get "caption" }} | ||
{{ with .Get "attrlink"}}<a href="{{.}}"> {{ end }} | ||
{{ .Get "attr" }} | ||
{{ if .Get "attrlink"}}</a> {{ end }} | ||
</p> {{ end }} | ||
</figcaption> | ||
{{ end }} | ||
{{ if (findRE "(^|:)//" $image) -}} <!-- If image link is a URL with protocol or two leading slashes, use just that unmodified. --> | ||
<img src="{{ $image }}" | ||
{{- else if (findRE "^/" $image) -}} <!-- If image link has one leading slash --> | ||
{{- /* Cannot use absURL below because it doesn't work as expected if baseURL has a subdir. */ -}} | ||
{{- $baseurl_no_trailing_slash := $.Site.BaseURL | replaceRE "/$" "" -}} | ||
<img src="{{ (printf "%s%s" $baseurl_no_trailing_slash $image) }}" | ||
{{- else -}} | ||
{{- /* Below variable will always have a trailing slash, even with uglyURLs enabled. */ -}} | ||
{{- $permalink_pretty := $.Page.Permalink | replaceRE "\\.html$" "/" -}} | ||
<img src="{{ (printf "%s%s" $permalink_pretty $image) }}" | ||
{{- end -}} | ||
{{- with (or (.Get "alt") (.Get "caption")) -}} | ||
{{- printf " alt=\"%s\"" . | safeHTMLAttr -}} | ||
{{- 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> | ||
{{ if isset .Params "title" }} | ||
<h4>{{ .Get "title" }}</h4> | ||
{{ end }} | ||
{{ if or (.Get "caption") (.Get "attr") }}<p> | ||
{{ .Get "caption" }} | ||
{{ with .Get "attrlink" }}<a href="{{ . }}"> {{ end }} | ||
{{ .Get "attr" }} | ||
{{ if .Get "attrlink" }}</a>{{ end }}</p> | ||
{{ end }} | ||
</figcaption> | ||
{{- end -}} | ||
</figure> | ||
<!-- image --> | ||
<!-- image --> |