Reorganize partials
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
22
layouts/partials/components/image/index.html
Normal file
22
layouts/partials/components/image/index.html
Normal file
@@ -0,0 +1,22 @@
|
||||
{{ $imageData := partial "components/image/reflect.html" . }}
|
||||
{{- with $imageData.image -}}
|
||||
<figure class="captioned-image lightbox">
|
||||
<a
|
||||
href="{{- .RelPermalink -}}"
|
||||
data-pswp-width="{{- .Width -}}"
|
||||
data-pswp-height="{{- .Height -}}"
|
||||
>
|
||||
<img
|
||||
src="{{- .RelPermalink -}}"
|
||||
width="{{- .Width -}}"
|
||||
height="{{- .Height -}}"
|
||||
loading="lazy"
|
||||
{{ with $imageData.title }}title="{{- . -}}"{{ end }}
|
||||
{{ with $imageData.alt }}alt="{{- . -}}"{{ end }}
|
||||
/>
|
||||
</a>
|
||||
{{ with $imageData.caption }}
|
||||
<figcaption>{{ . }}</figcaption>
|
||||
{{ end }}
|
||||
</figure>
|
||||
{{- end -}}
|
31
layouts/partials/components/image/reflect.html
Normal file
31
layouts/partials/components/image/reflect.html
Normal file
@@ -0,0 +1,31 @@
|
||||
{{- $input := . -}}
|
||||
|
||||
{{- $src := $input -}}
|
||||
{{- $caption := "" -}}
|
||||
{{- $title := "" -}}
|
||||
{{- $alt := "" -}}
|
||||
|
||||
{{- if reflect.IsMap $input -}}
|
||||
{{- $src = $input.src | default "" -}}
|
||||
{{- $caption = $input.caption | default "" -}}
|
||||
{{- $title = $input.title | default $caption | default "" -}}
|
||||
{{- $alt = $input.alt | default $title | default "" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{ $result := dict "image" nil "caption" $caption "title" $title "alt" $alt }}
|
||||
|
||||
{{- if $src -}}
|
||||
{{- $isRemote := strings.HasPrefix $src "http" -}}
|
||||
{{- $image := "" -}}
|
||||
|
||||
{{- if $isRemote -}}
|
||||
{{- $remote := resources.GetRemote $src -}}
|
||||
{{- $image = resources.Copy (printf "static/3rd-party/%s" $remote.Name) $remote -}}
|
||||
{{- else -}}
|
||||
{{- $image = resources.Get $src -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $result = (dict "image" $image "caption" $caption "title" $title "alt" $alt) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- return $result -}}
|
Reference in New Issue
Block a user