forked from kc0bfv/autophugo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.html
105 lines (88 loc) · 4.14 KB
/
list.html
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
{{ define "main" }}
{{- /* Things in site config */}}
{{- $column_count := default 2 ($.Param "column_count") }}
{{- $thumb_width := default 480 ($.Param "thumb_width") }}
{{- $thumb_quality := default 50 ($.Param "thumb_quality") }}
{{- $thumb_size := printf "%dx q%d" $thumb_width $thumb_quality }}
{{- /* Build the list of sections and thumbnails */}}
{{- $.Scratch.Set "sections" (slice) }}
{{- range (where .Site.Pages "Kind" "section").ByDate }}
{{- $title := .Title }}
{{- $link := .Permalink }}
{{- /* The path we need under the assets directory */}}
{{- $imgpath := path.Join .File.Dir .Params.albumthumb }}
{{- $.Scratch.Delete "image" }}
{{- /* If no albumthumb is set, get the first image*/}}
{{- if or (not (isset .Params "albumthumb")) (eq .Params.albumthumb "") }}
{{- $imgglob := printf "*%s" (path.Join .File.Dir "**") }}
{{- $imageresources := where (resources.Match $imgglob) "ResourceType" "image" }}
{{- $.Scratch.Set "image" (index $imageresources 0) }}
{{- end }}
{{- /* Otherwise get the albumthumb*/}}
{{- with .Params.albumthumb }}
{{- $image := resources.Get $imgpath }}
{{- $.Scratch.Set "image" $image }}
{{- end }}
{{- $image := $.Scratch.Get "image" }}
{{- if not $image }}
{{- errorf (printf "No thumbnail image found for: %s" $title) }}
{{- else }}
{{- $thumb := $image.Resize $thumb_size }}
{{- $new_sect := dict "title" $title "link" $link "thumb" $thumb }}
{{- $sections := $.Scratch.Get "sections" }}
{{- $sections := $sections | append $new_sect }}
{{- $.Scratch.Set "sections" $sections }}
{{- end }}
{{- end }}
{{- $sections := $.Scratch.Get "sections" }}
{{- /* 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 }}
{{- /* Set the columns */}}
{{- range $elem_index, $elem_val := $sections}}
{{- /* 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 "Failed to find a least-filled column!"}}
{{- 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 }}
<div id="main">
<div class="flexrow">
{{- /* 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 }}
<article class="thumb">
<a href="{{ .link }}" class="link" tabindex="0"><img src="{{ .thumb.RelPermalink }}" alt="{{ .title }}" /></a>
<h2>{{ .title }}</h2>
</article>
{{- end }}
</div>
{{- end }}
</div>
</div>
{{ end }}