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

render-image.html « _markup « _default « layouts - github.com/chipzoller/hugo-clarity.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8be264cf1d6ba0dd16725791b98afe73b684441c (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
51
{{- $file := .Destination -}}
{{- $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 -}}
  {{- if eq $image.MediaType.MainType "image" -}}
    {{- if eq $image.MediaType.SubType "svg" -}}
      {{- $image = "" -}}
      {{- $scratch.Add "classes" " image_svg" -}}
    {{- else -}}
      {{- $file = path.Join "images" $image -}}
      {{- $image = $image.Content | resources.FromString $file -}}
    {{- 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
    "dir" $.Page.RelPermalink
    "alt" $alt
    "cap" $cap
    "classes" ($scratch.Get "classes")
    "bundle" $bundle
) -}}