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

list.html « _default « layouts - github.com/kc0bfv/autophugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f5fe0b3a0b12e1342632c7ec3a85660810b1dc0a (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
{{ define "main" }}

    {{- /* Things in site config */}}
    {{- $thumb_width := default 480 ($.Param "thumb_width") }}
    {{- $full_width := default 960 ($.Param "full_width") }}
    {{- $thumb_quality := default 50 ($.Param "thumb_quality") }}
    {{- $full_quality := default 90 ($.Param "full_quality") }}
    {{- $filename_as_phototitle := default false ($.Param "filename_as_phototitle") }}

    {{- /* Calculate thumb_ and full_size from params, unless one is provided in the config. */}}
    {{- $thumb_size := default (printf "%dx q%d" $thumb_width $thumb_quality) ($.Param "thumb_size") }}
    {{- $full_resize_method := lower (default "resize" ($.Param "full_resize_method")) -}}
    {{- $full_size := default (printf "%dx q%d" $full_width $full_quality) ($.Param "full_size") }}

    {{- /* Build the list of sections and thumbnails */}}
    {{- $.Scratch.Set "sections" (slice) }}
    {{- range .Sections.ByDate }}
        {{- $title := .Title }}
        {{- $link := .RelPermalink }}
        {{- $weight := default 0 (.Param "weight") }}

        {{- partial "scratch_set_retalbumthumb.html" . }}
        {{- /* Note that the Scratch below must come from . context, not $ */}}
        {{- $image := .Scratch.Get "retalbumthumb" }}

        {{- if not $image }}
            {{- errorf (printf "When processing '%s', no thumbnail image found for: %s" $.Page.File.Path $title) }}
        {{- else }}
            {{- $.Scratch.Set "orientation" 1 }}
            {{- with $image.Exif }}
                {{- $.Scratch.Set "orientation" .Tags.Orientation }}
            {{- end }}
            {{- $orientation := $.Scratch.Get "orientation" }}
            {{- /* TODO: handle flipped orientations */}}
            {{- $.Scratch.Set "rotation" "" }}
            {{- if (eq $orientation 1) }}
                {{- $.Scratch.Set "rotation" "" }}
            {{- else if (eq $orientation 8) }}
                {{- $.Scratch.Set "rotation" " r90" }}
            {{- else if (eq $orientation 3) }}
                {{- $.Scratch.Set "rotation" " r180" }}
            {{- else if (eq $orientation 6) }}
                {{- $.Scratch.Set "rotation" " r270" }}
            {{- end }}
            {{- $rotation := $.Scratch.Get "rotation" }}
            {{- $resize_cmd := printf "%s%s" $thumb_size $rotation }}
            {{- $thumb := $image.Resize $resize_cmd }}
            {{- $new_sect := dict "type" "link" "title" $title "link" $link "thumb" $thumb "weight" $weight }}

            {{- $sections := $.Scratch.Get "sections" }}
            {{- $sections := $sections | append $new_sect }}
            {{- $.Scratch.Set "sections" $sections }}
        {{- end }}
    {{- end }}
    {{- /* Section list is complete, now resort */}}
    {{- $.Scratch.Set "sections" (sort ($.Scratch.Get "sections") "weight") }}
    {{- $sections := $.Scratch.Get "sections" }}

    {{- /* Get and reorder the list of images */}}
    {{- if .File }}
        {{- $imgglob := printf "%s" (path.Join .File.Dir "*") }}
        {{- $.Scratch.Set "imgglob" $imgglob }}
    {{- end }}
    {{- $imgglob := default "*" ($.Scratch.Get "imgglob") }}
    {{- $imageresources := where (resources.Match $imgglob) "ResourceType" "image" }}

    {{- /* Build some image objects */}}
    {{- $.Scratch.Set "images" (slice) }}
    {{- range $elem_index, $elem_val := $imageresources }}

        {{- /* Build some scratch for upcoming search... */}}
        {{- $img_dat := newScratch }}
        {{- $img_dat.Set "alt" "" }}
        {{- $img_dat.Set "description" "" }}
        {{- $img_dat.Set "weight" 0 }}
        {{- $img_dat.Set "taxonomies" dict }}

        {{- if $filename_as_phototitle }}
            {{- $filename := replace (path.Base $elem_val.Name) (path.Ext $elem_val.Name) "" }}
            {{- $img_dat.Set "phototitle" (humanize $filename) }}
        {{- else }}
            {{- $img_dat.Set "phototitle" "" }}
        {{- end }}

        {{- /* Search the resources for a matching image src, save off details */}}
        {{- $img_path := $elem_val.Name }}
        {{- with $.Params.resources }}
            {{- range first 1 (where . "src" $img_path) }}
                {{- $found := . }}
                {{- if isset . "alt" }}{{ $img_dat.Set "alt" .alt }}{{ end }}
                {{- if isset . "phototitle" }}{{ $img_dat.Set "phototitle" .phototitle }}{{ end }}
                {{- if isset . "description" }}{{ $img_dat.Set "description" .description }}{{ end }}
                {{- if isset . "weight" }}{{ $img_dat.Set "weight" .weight }}{{ end }}
                
                {{- /* Build an dict of arrays - the keys are taxonomy name, values are an array of terms in that taxonomy */}}
                {{- range $taxname, $taxterms := $.Site.Taxonomies }}
                    {{- if isset $found $taxname }}
                        {{- $newentry := dict $taxname (index $found $taxname) }}
                        {{- $newvals := merge ($img_dat.Get "taxonomies") $newentry }}
                        {{- $img_dat.Set "taxonomies" $newvals }}
                    {{- end }}
                {{- end }}
            {{- end }}
        {{- end }}

        {{- $.Scratch.Set "orientation" 1 }}
        {{- with $elem_val.Exif }}
            {{- $.Scratch.Set "orientation" .Tags.Orientation }}
        {{- end }}
        {{- $orientation := $.Scratch.Get "orientation" }}
        {{- /* TODO: handle flipped orientations */}}
        {{- $.Scratch.Set "rotation" "" }}
        {{- if (eq $orientation 1) }}
            {{- $.Scratch.Set "rotation" "" }}
        {{- else if (eq $orientation 8) }}
            {{- $.Scratch.Set "rotation" " r90" }}
        {{- else if (eq $orientation 3) }}
            {{- $.Scratch.Set "rotation" " r180" }}
        {{- else if (eq $orientation 6) }}
            {{- $.Scratch.Set "rotation" " r270" }}
        {{- end }}
        {{- $rotation := $.Scratch.Get "rotation" }}
        {{- $thumb_resize_cmd := printf "%s%s" $thumb_size $rotation }}
        {{- $full_resize_cmd := printf "%s%s" $full_size $rotation }}

        {{- /* Save off the image object */}}
        {{- $alt := $img_dat.Get "alt" }}
        {{- $phototitle := $img_dat.Get "phototitle" }}
        {{- $description := $img_dat.Get "description" }}
        {{- $weight := $img_dat.Get "weight" }}
        {{- $taxonomies := $img_dat.Get "taxonomies" }}
        {{- $thumb := $elem_val.Resize $thumb_resize_cmd }}

        {{- $.Scratch.Set "full_resized" $thumb }}
        {{- if (eq $full_resize_method "resize") }}
            {{- $.Scratch.Set "full_resized" ($elem_val.Resize $full_resize_cmd) }}
        {{- else if (eq $full_resize_method "fit") }}
            {{- $.Scratch.Set "full_resized" ($elem_val.Fit $full_resize_cmd) }}
        {{- else if (eq $full_resize_method "none") }}
            {{- $.Scratch.Set "full_resized" $elem_val }}
        {{- else }}
            {{- errorf "Invalid 'full_resize_method' specified!  Must be resize or fit." }}
        {{- end }}
        {{- $full := $.Scratch.Get "full_resized" }}

        {{- $new_img := dict "type" "image" "index" $elem_index "image" $elem_val "thumb" $thumb "full" $full "alt" $alt "phototitle" $phototitle "description" $description "weight" $weight  "orig" $elem_val "taxonomies" $taxonomies }}

        {{- $images := $.Scratch.Get "images" }}
        {{- $images := $images | append $new_img }}
        {{- $.Scratch.Set "images" $images }}
    {{- end }}
    {{- /* Image list is complete, now resort */}}
    {{- $.Scratch.Set "images" (sort ($.Scratch.Get "images") "weight") }}
    {{- $images := $.Scratch.Get "images" }}

    {{- $.Scratch.Set "content" ($sections | append $images) }}
    {{- partial "render_img_column_flexrow.html" $ }}

{{ end }}