diff --git a/exampleSite/content/post/chinese-test/index.zh-cn.md b/exampleSite/content/post/chinese-test/index.zh-cn.md index 5249ef8..dacf4fd 100644 --- a/exampleSite/content/post/chinese-test/index.zh-cn.md +++ b/exampleSite/content/post/chinese-test/index.zh-cn.md @@ -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) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 0ed5584..ae8ae21 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -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 -}}