Welcome to mirror list, hosted at ThFree Co, Russian Federation.

image.html « partials « layouts - github.com/chipzoller/hugo-clarity.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8aed4b6b701b62043262c5f6fc65485ebadc9c26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{{- $file := .file -}}
{{- $alt := .alt -}}
{{- if not $alt -}}
  {{- $alt = .Text -}}
{{- end -}}
{{- $cap := .Title -}}
{{- $scratch := newScratch -}}
{{- $scratch.Set "classes" "image_figure" -}}

{{/* Add classes for image type */}}
{{- $typeClass := "" -}}
{{- with .type -}}
  {{- $typeClass = printf "%s" . | printf "%s%s" " image_" | printf "%s" -}}
{{- end -}}
{{- $scratch.Add "classes" $typeClass -}}

{{/* 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 -}}
  {{- $file = path.Join "images" $image -}}
  {{- $image = $image.Content | resources.FromString $file -}}
{{- else -}}
  {{- $scratch.Add "classes" " image_internal" -}}
  {{ $file = (path.Join "/" $file) }}
  {{- if eq $bundle true -}}
    {{ $image = .Resources.GetMatch $file }}
  {{- end -}}
{{- end -}}

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