Skip to content

Commit

Permalink
theme: modularize render image hook #373
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Nov 6, 2022
1 parent 4934d58 commit 54df05b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
17 changes: 6 additions & 11 deletions 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 }}
<img src="{{ $url }}" alt="{{ .Text }}"{{ with .Title}} title="{{ . }}"{{ end }}>
{{- partial "shortcodes/image.html" (dict
"context" .Page
"url" .Destination
"title" .Title
"alt" .Text
) }}
15 changes: 15 additions & 0 deletions 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 }}
<img src="{{ $url }}" alt="{{ $alt }}"{{ with $title}} title="{{ . }}"{{ end }}>

0 comments on commit 54df05b

Please sign in to comment.