Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/wangchucheng/hugo-eureka.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWang Chucheng <wangchucheng@outlook.com>2020-11-27 14:09:58 +0300
committerWang Chucheng <wangchucheng@outlook.com>2020-11-27 14:09:58 +0300
commitd998e9fa89455ac70270cb81ae7d6dded8e4e7db (patch)
tree5a7c577d2e757704c99f055698c969bf03e6b2ee
parent1f9824221d92a14ae08f03d5e57488c48bd8b537 (diff)
fix: images cannot be named freely
Closes #13
-rw-r--r--layouts/partials/get_image.html27
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