-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tpl: Allow using page resources on the images page parameter for `ope…
…ngraph`, `schema` and `twitter_cards` templates The page images selection order as follows: 1. Page's images parameter, image resources are supported. 2. Page's image resources that naming in *feature*, *cover* or *thumbnail* pattern. 3. If no page images specified, then the first one of site's images will be used as the fallback, supports site resources.
- Loading branch information
Showing
6 changed files
with
75 additions
and
51 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
47 changes: 47 additions & 0 deletions
47
tpl/tplimpl/embedded/templates/partials/_funcs/get-page-images.html
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{{- $imgs := slice }} | ||
{{- $imgParams := .Params.images }} | ||
{{- $resources := .Resources.ByType "image" -}} | ||
{{/* Find featured image resources if the images parameter is empty. */}} | ||
{{- if not $imgParams }} | ||
{{- $featured := $resources.GetMatch "*feature*" -}} | ||
{{- if not $featured }}{{ $featured = $resources.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} | ||
{{- with $featured }} | ||
{{- $imgs = $imgs | append (dict | ||
"Image" . | ||
"RelPermalink" .RelPermalink | ||
"Permalink" .Permalink) }} | ||
{{- end }} | ||
{{- end }} | ||
{{/* Use the first one of site images as the fallback. */}} | ||
{{- if and (not $imgParams) (not $imgs) }} | ||
{{- with site.Params.images }} | ||
{{- $imgParams = first 1 . }} | ||
{{- end }} | ||
{{- end }} | ||
{{/* Parse page's images parameter. */}} | ||
{{- range $imgParams }} | ||
{{- $img := . }} | ||
{{- $url := urls.Parse $img }} | ||
{{- if eq $url.Scheme "" }} | ||
{{/* Internal image. */}} | ||
{{- with $resources.GetMatch $img -}} | ||
{{/* Image resource. */}} | ||
{{- $imgs = $imgs | append (dict | ||
"Image" . | ||
"RelPermalink" .RelPermalink | ||
"Permalink" .Permalink) }} | ||
{{- else }} | ||
{{- $imgs = $imgs | append (dict | ||
"RelPermalink" (relURL $img) | ||
"Permalink" (absURL $img) | ||
) }} | ||
{{- end }} | ||
{{- else }} | ||
{{/* External image */}} | ||
{{- $imgs = $imgs | append (dict | ||
"RelPermalink" $img | ||
"Permalink" $img | ||
) }} | ||
{{- end }} | ||
{{- end }} | ||
{{- return $imgs }} |
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