From 54df05b91d51a4e329f3c00614a7c4b1d56dcc29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sun, 6 Nov 2022 10:03:18 +0100 Subject: [PATCH] theme: modularize render image hook #373 --- layouts/_default/_markup/render-image.html | 17 ++++++----------- layouts/partials/shortcodes/image.html | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 layouts/partials/shortcodes/image.html diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 44d9597a96..500fc908ed 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -1,11 +1,6 @@ -{{- $dest_url := urls.Parse .Destination }} -{{- $dest_path := $dest_url.Path }} -{{- $image := .Page.Resources.GetMatch $dest_path }} -{{- $url := .Destination | relURL }} -{{- if $image }} - {{- $url = $image.RelPermalink }} - {{- if $dest_url.RawQuery }} - {{- $url = printf "%s?%s" $url $dest_url.RawQuery }} - {{- end }} -{{- end }} -{{ .Text }} +{{- partial "shortcodes/image.html" (dict + "context" .Page + "url" .Destination + "title" .Title + "alt" .Text +) }} \ No newline at end of file diff --git a/layouts/partials/shortcodes/image.html b/layouts/partials/shortcodes/image.html new file mode 100644 index 0000000000..bc7e1a8b38 --- /dev/null +++ b/layouts/partials/shortcodes/image.html @@ -0,0 +1,15 @@ +{{- $context := .context }} +{{- $url := .url }} +{{- $title := .title }} +{{- $alt := .alt }} +{{- $dest_url := urls.Parse $url }} +{{- $dest_path := $dest_url.Path }} +{{- $image := $context.Resources.GetMatch $dest_path }} +{{- $url = $url | relURL }} +{{- if $image }} + {{- $url = $image.RelPermalink }} + {{- if $dest_url.RawQuery }} + {{- $url = printf "%s?%s" $url $dest_url.RawQuery }} + {{- end }} +{{- end }} +{{ $alt }}