mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
theme: modularize render image hook #373
This commit is contained in:
parent
4934d58624
commit
54df05b91d
2 changed files with 21 additions and 11 deletions
|
@ -1,11 +1,6 @@
|
||||||
{{- $dest_url := urls.Parse .Destination }}
|
{{- partial "shortcodes/image.html" (dict
|
||||||
{{- $dest_path := $dest_url.Path }}
|
"context" .Page
|
||||||
{{- $image := .Page.Resources.GetMatch $dest_path }}
|
"url" .Destination
|
||||||
{{- $url := .Destination | relURL }}
|
"title" .Title
|
||||||
{{- if $image }}
|
"alt" .Text
|
||||||
{{- $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 }}>
|
|
15
layouts/partials/shortcodes/image.html
Normal file
15
layouts/partials/shortcodes/image.html
Normal file
|
@ -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 }}>
|
Loading…
Reference in a new issue