Skip to content

Commit

Permalink
Create render-image.html
Browse files Browse the repository at this point in the history
  • Loading branch information
gautierchomel committed Dec 19, 2023
1 parent 99733bf commit 7a47e35
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions layouts/_default/_markup/render-image.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{- $file := .Destination -}}
{{- $imagesDir := .Page.Site.Params.imagesDir -}}
{{- $alt := .Text -}}
{{- $cap := .Title -}}
{{- $scratch := newScratch -}}
{{- $scratch.Set "classes" "image_figure" -}}

{{/* Determine if page bundles are set. */}}
{{- $bundle := .Page.Site.Params.usePageBundles -}}
{{- if eq .Page.Params.usePageBundles false -}}
{{- $bundle = false -}}
{{- end -}}
{{- if eq .Page.Params.usePageBundles true -}}
{{- $bundle = true -}}
{{- end -}}

{{/* Determine source of image and get attributes. */}}
{{- $image := "" -}}
{{- if strings.HasPrefix $file "http" -}}
{{- $scratch.Add "classes" " image_external" -}}
{{- $image = resources.GetRemote $file -}}
{{- with $image }}
{{- if eq $image.MediaType.MainType "image" -}}
{{- if eq $image.MediaType.SubType "svg" -}}
{{- $image = "" -}}
{{- $scratch.Add "classes" " image_svg" -}}
{{- else -}}
{{- $file = path.Join $imagesDir $image -}}
{{- $image = $image.Content | resources.FromString $file -}}
{{- end -}}
{{- else -}}
{{- $image = "" -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- $scratch.Add "classes" " image_internal" -}}
{{ $file = (path.Clean $file) }}
{{- if eq $bundle true -}}
{{ $image = .Page.Resources.GetMatch $file }}
{{- if and (not $image) .Page.File -}}
{{ $file = path.Join .Page.RelPermalink $file }}
{{ $image = resources.Get $file }}
{{- end -}}
{{- end -}}
{{- end -}}

{{- partial "figure" (
dict
"file" $file
"image" $image
"diskPath" $.Page.File.Dir
"webPath" $.Page.RelPermalink
"alt" $alt
"cap" $cap
"classes" ($scratch.Get "classes")
"bundle" $bundle
) -}}

0 comments on commit 7a47e35

Please sign in to comment.