diff options
author | Wang Chucheng <wangchucheng@outlook.com> | 2020-11-27 14:09:58 +0300 |
---|---|---|
committer | Wang Chucheng <wangchucheng@outlook.com> | 2020-11-27 14:09:58 +0300 |
commit | d998e9fa89455ac70270cb81ae7d6dded8e4e7db (patch) | |
tree | 5a7c577d2e757704c99f055698c969bf03e6b2ee /layouts | |
parent | 1f9824221d92a14ae08f03d5e57488c48bd8b537 (diff) |
fix: images cannot be named freely
Closes #13
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/partials/get_image.html | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/layouts/partials/get_image.html b/layouts/partials/get_image.html index 72c74af..31e833c 100644 --- a/layouts/partials/get_image.html +++ b/layouts/partials/get_image.html @@ -1,12 +1,15 @@ -{{ if and .keyword (.context.Resources.ByType "image") }} -{{ .context.Scratch.Set "img" ((.context.Resources.ByType "image").GetMatch .keyword).Permalink }} -{{ else if or (hasPrefix .url "http://") (hasPrefix .url "https://") }} -{{ .context.Scratch.Set "img" (.url | absURL) }} -{{ else if resources.GetMatch .url }} -{{ .context.Scratch.Set "img" (resources.GetMatch .url).Permalink }} -{{ else if .url }} -{{ .context.Scratch.Set "img" (.url | absURL) }} -{{ end }} -{{ $img := .context.Scratch.Get "img" }} -{{ .context.Scratch.Delete "img" }} -{{ return $img }}
\ No newline at end of file +{{- $img := "" }} +{{- $validKeyword := false }} +{{- if .keyword }} +{{- if (.context.Resources.ByType "image").GetMatch .keyword }} +{{- $validKeyword = true}} +{{- end }} +{{- end }} +{{- if $validKeyword }} +{{- $img = ((.context.Resources.ByType "image").GetMatch .keyword).Permalink }} +{{- else if resources.GetMatch .url }} +{{- $img = (resources.GetMatch .url).Permalink }} +{{- else if .url }} +{{- $img = (.url | absURL) }} +{{- end }} +{{- return $img }}
\ No newline at end of file |