From 6ab1964e22be395d7941ef8a4c341c64e1c87cc4 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sun, 25 May 2025 23:29:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20encapsulat?= =?UTF-8?q?es=20functions=20in=20render-image.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layouts/_default/_markup/render-image.html | 89 +++++++++++----------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 93353e94..c308c6b3 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -1,49 +1,50 @@ +{{ define "inline-image-simple" -}} + {{ .alt }} +{{- end }} + +{{ define "inline-image-responsive" -}} + {{ .alt }} +{{- end }} + +{{ define "inline-image-caption" -}} + {{- with .caption }} +
{{ . | markdownify }}
+ {{- end }} +{{- end }} + {{- $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} {{- $url := urls.Parse .Destination }} {{- $altText := .Text }} {{- $caption := .Title }} -{{- if findRE "^https?" $url.Scheme }} -
- {{ $altText }} - {{ with $caption }}
{{ . | markdownify }}
{{ end }} -
-{{- else }} - {{- $resource := "" }} - {{- if $.Page.Resources.GetMatch ($url.String) }} - {{- $resource = $.Page.Resources.GetMatch ($url.String) }} - {{- else if resources.GetMatch ($url.String) }} - {{- $resource = resources.Get ($url.String) }} - {{- end }} - {{- with $resource }} -
- {{- if or $disableImageOptimization (eq .MediaType.SubType "svg")}} - {{ $altText }} - {{- else }} - {{ $altText }} - {{- end }} - {{ with $caption }}
{{ . | markdownify }}
{{ end }} -
- {{- else }} -
- {{ $altText }} - {{ with $caption }}
{{ . | markdownify }}
{{ end }} -
- {{- end }} +{{- $isRemote := findRE "^https?" $url.Scheme }} +{{- $resource := "" }} + +{{- if not $isRemote }} + {{- $resource = or ($.Page.Resources.GetMatch $url.String) (resources.Get $url.String) }} {{- end }} + +
+ {{- if $isRemote }} + {{ template "inline-image-simple" (dict "src" $url.String "alt" $altText) }} + {{- else if $resource }} + {{- $isSVG := eq $resource.MediaType.SubType "svg" }} + {{- $shouldOptimize := and (not $disableImageOptimization) (not $isSVG) }} + {{- if $shouldOptimize }} + {{ template "inline-image-responsive" (dict "resource" $resource "alt" $altText) }} + {{- else }} + {{ template "inline-image-simple" (dict "src" $resource.RelPermalink "alt" $altText) }} + {{- end }} + {{- else }} + {{ template "inline-image-simple" (dict "src" $url.String "alt" $altText) }} + {{- end }} + + {{ template "inline-image-caption" (dict "caption" $caption) }} +
From 86fa25f27f9c537f4157584d17ce915b88286ab3 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Mon, 26 May 2025 00:21:37 +0800 Subject: [PATCH 2/2] chore: unify variable naming conventions --- layouts/_default/_markup/render-image.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index c308c6b3..74000b80 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -1,8 +1,8 @@ -{{ define "inline-image-simple" -}} +{{ define "RenderImageSimple" -}} {{ .alt }} {{- end }} -{{ define "inline-image-responsive" -}} +{{ define "RenderImageResponsive" -}} {{ .alt }}{{ . | markdownify }} {{- end }} @@ -33,18 +33,18 @@
{{- if $isRemote }} - {{ template "inline-image-simple" (dict "src" $url.String "alt" $altText) }} + {{ template "RenderImageSimple" (dict "src" $url.String "alt" $altText) }} {{- else if $resource }} {{- $isSVG := eq $resource.MediaType.SubType "svg" }} {{- $shouldOptimize := and (not $disableImageOptimization) (not $isSVG) }} {{- if $shouldOptimize }} - {{ template "inline-image-responsive" (dict "resource" $resource "alt" $altText) }} + {{ template "RenderImageResponsive" (dict "resource" $resource "alt" $altText) }} {{- else }} - {{ template "inline-image-simple" (dict "src" $resource.RelPermalink "alt" $altText) }} + {{ template "RenderImageSimple" (dict "src" $resource.RelPermalink "alt" $altText) }} {{- end }} {{- else }} - {{ template "inline-image-simple" (dict "src" $url.String "alt" $altText) }} + {{ template "RenderImageSimple" (dict "src" $url.String "alt" $altText) }} {{- end }} - {{ template "inline-image-caption" (dict "caption" $caption) }} + {{ template "RenderImageCaption" (dict "caption" $caption) }}