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

sect_and_img_content.html « partials « layouts - github.com/kc0bfv/autophugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 02c7ce50228ca3fcd703ab3a9def00117ddf4cdb (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<div id="main">
    <div class="flexrow">

    {{- /* Things in site config */}}
    {{- $column_count := default 2 ($.Param "column_count") }}
    {{- $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") }}
    {{- $downloadable := default true ($.Param "images_downloadable") }}
    {{- $orig_download := default false ($.Param "images_downloadable_use_orig") }}

    {{- /* 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_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 }}
            {{- $thumb := $image.Resize $thumb_size }}
            {{- $new_sect := dict "type" "sect" "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" }}
    {{- $TODO_DELETE_images := $imageresources }}

    {{- /* 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 }}

        {{- 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) }}
                {{- 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 }}
            {{- end }}
        {{- end }}

        {{- /* 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" }}
        {{- $thumb := $elem_val.Resize $thumb_size }}
        {{- $full := $elem_val.Resize $full_size }}

        {{- $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 }}

        {{- $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" }}

    {{- /* Initialize the column storage */}}
    {{- range $column_ind := seq $column_count }}
        {{- $st_name := printf "col-%d" $column_ind }}
        {{- $st_height_name := printf "col-height-%d" $column_ind }}
        {{- $.Scratch.Set $st_name (slice) }}
        {{- $.Scratch.Set $st_height_name 0 }}
    {{- end }}


    {{- /* Add the sections into the columns followed by images */}}
    {{- range $elem_index, $elem_val := ($sections | append $images)}}
        {{- /* Find the least-filled column */}}
        {{- $.Scratch.Set "min_height" -1 }}
        {{- $.Scratch.Set "min_col" -1 }}
        {{- range $column_ind := seq $column_count }}
            {{- $st_height_name := printf "col-height-%d" $column_ind }}
            {{- $col_height := $.Scratch.Get $st_height_name }}
            {{- $min_height := $.Scratch.Get "min_height" }}
            {{- if (or (eq $min_height -1) (lt $col_height $min_height)) }}
                {{- $.Scratch.Set "min_height" $col_height }}
                {{- $.Scratch.Set "min_col" $column_ind }}
            {{- end }}
        {{- end }}

        {{- /* column_ind becomes the least-filled column */}}
        {{- $column_ind := $.Scratch.Get "min_col" }}
        {{- if eq $column_ind -1 }}
            {{- errorf (printf "When processing '%s', failed to find a least-filled column!" $.Page.File.Path) }}
        {{- end }}
        {{- $st_name := printf "col-%d" $column_ind }}
        {{- $st_height_name := printf "col-height-%d" $column_ind }}

        {{- $column := $.Scratch.Get $st_name }}
        {{- $column := $column | append $elem_val }}
        {{- $.Scratch.Set $st_name $column }}

        {{- $.Scratch.Set $st_height_name (add ($.Scratch.Get $st_height_name) $elem_val.thumb.Height) }}
    {{- end }}

    {{- /* Output the images in columns */}}
    {{- range $column_ind := seq $column_count }}
        {{- $st_name := printf "col-%d" $column_ind }}
        {{- $column := $.Scratch.Get $st_name }}
        <div class="flexcol">
        {{- range $column }}
            {{- $filename := path.Base .image.Name }}
            <article class="thumb">
                {{- if (eq .type "sect") }}
                    <a href="{{ .link }}" class="link" tabindex="0"><img src="{{ .thumb.RelPermalink }}" alt="{{ .title }}" /></a>
                    <h2>{{ .title }}</h2>
                {{- else }}
                    <a class="gallery-item" phototitle="{{ .phototitle }}"
                            description="{{ .description }}"
                            gallery_index="{{ .index }}"
                            id="{{ md5 $filename }}"
                            downloadable="{{ cond $downloadable "true" "false" }}"
                            {{- if $downloadable }}
                                download_file="{{ (cond $orig_download .orig .full).RelPermalink }}"
                            {{- end }}
                            orig_name="{{ $filename }}"
                            href="{{ .full.RelPermalink }}">
                        <div id="image_number_{{ .index }}" class="gallery-item-marker"></div>
                        <img src="{{ .thumb.RelPermalink }}"
                            {{ with .alt }} alt="{{ . }}"{{ end }}>
                    </a>
                    <h2>{{ .phototitle }}</h2>
                {{- end }}
            </article>
        {{- end }}
        </div>
    {{- end }}
    </div>
</div>