Support External images gallery.

This commit is contained in:
GHBJayce 2023-12-05 10:30:39 +08:00
parent 21da06e448
commit 2c01c82e80
2 changed files with 25 additions and 2 deletions

View File

@ -26,6 +26,12 @@ categories:
## 图片
External images:
![Photo by Florian Klauer on Unsplash](https://raw.githubusercontent.com/CaiJimmy/hugo-theme-stack/master/exampleSite/content/post/chinese-test/florian-klauer-nptLmg6jqDo-unsplash.jpg) ![Photo by Helena Hertz on Unsplash](https://raw.githubusercontent.com/CaiJimmy/hugo-theme-stack/master/exampleSite/content/post/chinese-test/helena-hertz-wWZzXlDpMog-unsplash.jpg)
Internal images:
![Photo by Florian Klauer on Unsplash](florian-klauer-nptLmg6jqDo-unsplash.jpg) ![Photo by Luca Bravo on Unsplash](luca-bravo-alS7ewQ41M8-unsplash.jpg)
![Photo by Helena Hertz on Unsplash](helena-hertz-wWZzXlDpMog-unsplash.jpg) ![Photo by Hudai Gayiran on Unsplash](hudai-gayiran-3Od_VKcDEAA-unsplash.jpg)

View File

@ -1,5 +1,23 @@
{{- $image := .Page.Resources.GetMatch (printf "%s" (.Destination | safeURL)) -}}
{{- $Permalink := .Destination | relURL | safeURL -}}
{{- $image := "" -}}
{{- if hasPrefix $Permalink "http" -}}
{{- with resources.GetRemote $Permalink -}}
{{- with .Err -}}
{{- $warnMsg := printf "%s" $Permalink -}}
{{- warnf "%s.\nPlease check the link: %s\n" . $warnMsg -}}
{{- else -}}
{{- $image = resources.GetRemote $Permalink -}}
{{- end -}}
{{- else -}}
{{- errorf "Unable to get remote resource %q" $Permalink -}}
{{- end -}}
{{- else -}}
{{- $image := .Page.Resources.GetMatch (printf "%s" (.Destination | safeURL)) -}}
{{- if $image -}}
{{- $Permalink = $image.RelPermalink -}}
{{- end -}}
{{- end -}}
{{- $alt := .PlainText | safeHTML -}}
{{- $Width := 0 -}}
{{- $Height := 0 -}}
@ -10,7 +28,6 @@
{{- if $image -}}
{{- $notSVG := ne (path.Ext .Destination) ".svg" -}}
{{- $Permalink = $image.RelPermalink -}}
{{- if $notSVG -}}
{{- $Width = $image.Width -}}