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

github.com/WingLim/hugo-tania.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWingLim <winglim@qq.com>2021-08-12 11:26:07 +0300
committerWingLim <winglim@qq.com>2021-08-12 11:26:58 +0300
commit08a430ac7eba3f3ddac7f7b1f8bb8035aadcecc9 (patch)
tree7d4b98066bd0b7325d663ac5adb1ff769774af1d
parent8435d771b55b26385a378fdba6644cee803816b0 (diff)
feat: support image in post folderv1.7.0
Now image can be put in post folder or site root static folder. Fix #28
-rw-r--r--layouts/_default/_markup/render-image.html22
1 files changed, 20 insertions, 2 deletions
diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html
index 38f2487..0719e1a 100644
--- a/layouts/_default/_markup/render-image.html
+++ b/layouts/_default/_markup/render-image.html
@@ -1,5 +1,23 @@
{{- if strings.HasPrefix .Destination "http" -}}
- <img loading="lazy" src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title}} title="{{ . }}"{{ end }} />
+ <img loading="lazy"
+ src="{{ .Destination | safeURL }}"
+ alt="{{ .Text }}"
+ {{ with .Title}} title="{{ . }}"{{ end }} />
{{- else -}}
- <img loading="lazy" src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title}} title="{{ . }}"{{ end }} {{ with imageConfig ( printf "static/%s" .Destination ) }} width={{ .Width }} height="{{ .Height }}" {{ end }} />
+ {{- $image := .Page.Resources.GetMatch (printf "%s" (.Destination | safeURL)) -}}
+ {{- $permalink := "" -}}
+
+ {{- if ne $image nil -}}
+ {{- $permalink = $image.RelPermalink -}}
+ {{- else -}}
+ {{- $image = imageConfig (printf "static/%s" (.Destination | safeURL)) -}}
+ {{- $permalink = (printf "/%s" (.Destination | safeURL)) -}}
+ {{- end -}}
+
+ <img loading="lazy"
+ src="{{ $permalink }}"
+ alt="{{ .Text }}"
+ {{ with .Title}} title="{{ . }}"{{ end }}
+ width={{ $image.Width }}
+ height="{{ $image.Height }}" />
{{- end -}} \ No newline at end of file