From 48a7c9a3299dcae5e59345fa7d2e2961cb5a63ab Mon Sep 17 00:00:00 2001 From: TaurusXin Date: Mon, 11 Dec 2023 11:17:39 +0800 Subject: [PATCH] exp*: test remote image gallery --- config.yaml | 8 ++- layouts/_default/_markup/render-image.html | 58 ++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 layouts/_default/_markup/render-image.html diff --git a/config.yaml b/config.yaml index 888b691..0263a79 100644 --- a/config.yaml +++ b/config.yaml @@ -185,7 +185,13 @@ params: cover: enabled: true content: - enabled: true + enabled: false + + render: + image: + externalLink: + enabled: true + ### Custom menu ### See https://docs.stack.jimmycai.com/configuration/custom-menu.html diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html new file mode 100644 index 0000000..d2dc6a2 --- /dev/null +++ b/layouts/_default/_markup/render-image.html @@ -0,0 +1,58 @@ +{{- $Permalink := .Destination | safeURL -}} +{{- $image := "" -}} + +{{- if and (hasPrefix $Permalink "http") (default false .Page.Site.Params.render.image.externalLink.enabled) -}} + {{- with resources.GetRemote $Permalink -}} + {{- with .Err -}} + {{- $warnMsg := printf "%s" $Permalink -}} + {{- warnf "%s.\nPlease check the link: %s\n" . $warnMsg -}} + {{- else -}} + {{- $image = . -}} + {{- end -}} + {{- else -}} + {{- warnf "Unable to get remote resource %q" $Permalink -}} + {{- end -}} +{{- else -}} + {{- $image = .Page.Resources.GetMatch (printf "%s" $Permalink) -}} + {{- if $image -}} + {{- $Permalink = $image.RelPermalink -}} + {{- end -}} +{{- end -}} +{{- $alt := .PlainText | safeHTML -}} +{{- $Width := 0 -}} +{{- $Height := 0 -}} +{{- $Srcset := "" -}} + +{{/* SVG and external images won't work with gallery layout, because their width and height attributes are unknown */}} +{{- $galleryImage := false -}} + +{{- if $image -}} + {{- $notSVG := ne (path.Ext .Destination) ".svg" -}} + + {{- if $notSVG -}} + {{- $Width = $image.Width -}} + {{- $Height = $image.Height -}} + {{- $galleryImage = true -}} + + {{- if (default true .Page.Site.Params.imageProcessing.content.enabled) -}} + {{- $small := $image.Resize `480x` -}} + {{- $big := $image.Resize `1024x` -}} + {{- $Srcset = printf `%s 480w, %s 1024w` $small.RelPermalink $big.RelPermalink -}} + {{- end -}} + {{- end -}} +{{- end -}} + +{{ . }}