-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99733bf
commit 7a47e35
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) -}} |