feat(helper/image): customize field used to get featured image
This commit is contained in:
parent
a2662603df
commit
2acd380e98
@ -13,6 +13,7 @@ DefaultContentLanguage = "en" # Theme i18n support
|
|||||||
[params]
|
[params]
|
||||||
mainSections = ["post"]
|
mainSections = ["post"]
|
||||||
favicon = ""
|
favicon = ""
|
||||||
|
featuredImageField = "image"
|
||||||
[params.dateFormat]
|
[params.dateFormat]
|
||||||
published = "Jan 02, 2006"
|
published = "Jan 02, 2006"
|
||||||
lastUpdated = "Jan 02, 2006 15:04 MST"
|
lastUpdated = "Jan 02, 2006 15:04 MST"
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
{{ $result := dict "exists" false "permalink" nil "resource" nil "isDefault" false }}
|
{{ $result := dict "exists" false "permalink" nil "resource" nil "isDefault" false }}
|
||||||
{{ $imageField := .Context.Params.image }}
|
{{ $imageField := default "image" .Context.Site.Params.featuredImageField }}
|
||||||
|
{{ $imageValue := index .Context.Params $imageField }}
|
||||||
|
|
||||||
{{ if $imageField }}
|
{{ if $imageValue }}
|
||||||
<!-- If page has `image` field set -->
|
<!-- If page has `image` field set -->
|
||||||
{{ $result = merge $result (dict "exists" true) }}
|
{{ $result = merge $result (dict "exists" true) }}
|
||||||
|
|
||||||
{{ $url := urls.Parse $imageField }}
|
{{ $url := urls.Parse $imageValue }}
|
||||||
{{ if or (eq $url.Scheme "http") (eq $url.Scheme "https") }}
|
{{ if or (eq $url.Scheme "http") (eq $url.Scheme "https") }}
|
||||||
<!-- Is a external image -->
|
<!-- Is a external image -->
|
||||||
{{ $result = merge $result (dict "permalink" $imageField) }}
|
{{ $result = merge $result (dict "permalink" $imageValue) }}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ $pageResourceImage := .Context.Resources.GetMatch (printf "%s" ($imageField | safeURL)) }}
|
{{ $pageResourceImage := .Context.Resources.GetMatch (printf "%s" ($imageValue | safeURL)) }}
|
||||||
{{ $siteResourceImage := resources.GetMatch (printf "%s" ($imageField | safeURL)) }}
|
{{ $siteResourceImage := resources.GetMatch (printf "%s" ($imageValue | safeURL)) }}
|
||||||
|
|
||||||
{{ if $pageResourceImage }}
|
{{ if $pageResourceImage }}
|
||||||
<!-- If image is found under page bundle -->
|
<!-- If image is found under page bundle -->
|
||||||
@ -23,7 +24,7 @@
|
|||||||
{{ $result = merge $result (dict "resource" $siteResourceImage) }}
|
{{ $result = merge $result (dict "resource" $siteResourceImage) }}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<!-- Can not find the image -->
|
<!-- Can not find the image -->
|
||||||
{{ errorf "Failed loading image: %q" $imageField }}
|
{{ errorf "Failed loading image: %q" $imageValue }}
|
||||||
{{ $result = merge $result (dict "exists" false) }}
|
{{ $result = merge $result (dict "exists" false) }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
Loading…
Reference in New Issue
Block a user