|
| 1 | +{{ define "sidebar" }}{{ end }} |
1 | 2 | {{ define "main" }} |
2 | 3 |
|
3 | | -{{- warnf "Bib types: %v" .Site.Taxonomies.item_type -}} |
4 | | -{{ warnf "All taxonomies: %s" (.Site.Taxonomies | jsonify) }} |
5 | | -{{ range $taxName, $terms := .Site.Taxonomies }} |
6 | | - {{- $pairs := slice -}} |
7 | | - {{- range $term, $pages := $terms }} |
8 | | - {{- $pairs = $pairs | append (printf "%s(%d)" $term (len $pages)) -}} |
9 | | - {{- end }} |
10 | | - {{ warnf "Taxonomy %s: %s" $taxName (delimit $pairs ", ") }} |
11 | | -{{ end }} |
12 | | - |
13 | | -<label for="itemTypeFilter">Filter by Type:</label> |
14 | | -<select id="itemTypeFilter"> |
15 | | - <option value="all">All</option> |
16 | | - {{ range $key, $value := .Site.Taxonomies.item_type}} |
17 | | - <option value="{{ $key }}">{{ $key | title }}</option> |
18 | | - {{ end }} |
19 | | -</select> |
20 | | - |
21 | | - |
22 | | - {{ .Content }} |
23 | | - |
24 | | - <style> |
25 | | - /* Publication list styling */ |
26 | | - ul.pub-list { |
27 | | - list-style: none; |
28 | | - margin: 0; |
29 | | - padding: 0; |
30 | | - } |
31 | | - ul.pub-list > li { |
32 | | - margin: 0; |
33 | | - padding: .75rem 0; |
34 | | - border-bottom: 1px solid #e2e2e2; |
35 | | - } |
36 | | - ul.pub-list > li:last-child { |
37 | | - border-bottom: none; |
38 | | - } |
39 | | - </style> |
| 4 | +<header class="bib-header"> |
| 5 | + <h1 class="bib-title">{{ or .Params.heading .Title }}</h1> |
| 6 | + |
| 7 | + <div class="bib-filter"> |
| 8 | + <label for="itemTypeFilter">Filter by Type:</label> |
| 9 | + <select id="itemTypeFilter"> |
| 10 | + <option value="all">All</option> |
| 11 | + {{ range $key, $value := .Site.Taxonomies.item_type }} |
| 12 | + <option value="{{ $key }}">{{ $key | title }}</option> |
| 13 | + {{ end }} |
| 14 | + </select> |
| 15 | + </div> |
| 16 | +</header> |
| 17 | + |
| 18 | +{{ .Content }} |
| 19 | + |
| 20 | +<style> |
| 21 | + .bib-header { |
| 22 | + display: flex; |
| 23 | + align-items: baseline; |
| 24 | + justify-content: space-between; |
| 25 | + gap: 1rem; |
| 26 | + flex-wrap: wrap; |
| 27 | + margin-bottom: 1rem; |
| 28 | + } |
| 29 | + .bib-title { margin: 0; } |
| 30 | + ul.pub-list { list-style: none; margin: 0; padding: 0; } |
| 31 | + ul.pub-list > li { margin: 0; padding: .75rem 0; border-bottom: 1px solid #e2e2e2; } |
| 32 | + ul.pub-list > li:last-child { border-bottom: none; } |
| 33 | +</style> |
40 | 34 |
|
41 | 35 | {{ $pages := .RegularPages }} |
42 | | - |
43 | | - {{- warnf "Pages: %v" (len $pages) -}} |
44 | | - |
45 | | - {{ if not (gt (len $pages) 0) }} |
46 | | - <p>No publications found.</p> |
47 | | - {{ end }} |
48 | | - |
49 | 36 | {{- /* Sort by date descending, then title ascending */ -}} |
50 | 37 | {{- $pages = sort $pages "Date" "desc" -}} |
51 | 38 | {{- $pages = sort $pages "Title" "asc" -}} |
52 | 39 |
|
53 | 40 | {{- /* Render the list of publications */ -}} |
54 | 41 |
|
55 | | - <ul class="pub-list" id="bibliographyList"> |
56 | | - {{ range $pages }} |
57 | | - <li data-type> |
58 | | - {{- $rawTitle := or .Params.title .Title -}} |
59 | | - {{- $rendered := replaceRE "^<p>(.*)</p>$" "$1" $rawTitle -}} |
60 | | - {{- $rendered = $rendered | plainify | htmlEscape -}} |
61 | | - <a href="{{ .RelPermalink }}"><span><strong>{{- $rendered | safeHTML -}}</strong></span></a><br> |
62 | | - |
63 | | - {{- /* warnf "Parameters %v " .Params */ -}} |
64 | | - |
65 | | - {{- /* Safe date: use front matter date only if non-empty & matches basic pattern */ -}} |
66 | | - {{- $d := .Date -}} |
67 | | - {{- with .Params.date -}} |
68 | | - {{- $datestr := trim . " " -}} |
69 | | - {{- if and (ne $datestr "") (findRE `^\d{4}-\d{2}-\d{2}` $datestr) -}} |
70 | | - {{- $d = time $datestr -}} |
71 | | - {{- end -}} |
72 | | - {{- end }} |
73 | | - <time datetime="{{ $d.Format "2006-01-02" }}">{{ $d.Format "2006-01-02" }}</time><br> |
74 | | - |
75 | | - {{ with .Params.abstract -}}config/_default |
76 | | - {{- $plain := . | plainify | htmlEscape | replaceRE `\s+` " " -}} |
77 | | - {{- $words := split $plain " " -}} |
78 | | - {{- $previewWords := cond (gt (len $words) 24) (first 24 $words) $words -}} |
79 | | - {{- $preview := delimit $previewWords " " -}} |
80 | | - <br> |
81 | | - <div>{{ $preview | safeHTML }}{{ if gt (len $words) 24 }}…{{ end }}</div> |
82 | | - <br> |
| 42 | +<ul class="pub-list" id="bibliographyList"> |
| 43 | + {{ range $pages }} |
| 44 | + {{- /* Collect item_type terms as a comma-separated, lowercased string */ -}} |
| 45 | + {{- $types := "" -}} |
| 46 | + {{- with .Params.item_type -}} |
| 47 | + {{- if reflect.IsSlice . -}} |
| 48 | + {{- $types = delimit (apply . "lower" ".") "," -}} |
| 49 | + {{- else -}} |
| 50 | + {{- $types = (lower .) -}} |
| 51 | + {{- end -}} |
| 52 | + {{- end -}} |
| 53 | + |
| 54 | + <li class="pub-item" data-type="{{ $types }}"> |
| 55 | + {{- $rawTitle := or .Params.title .Title -}} |
| 56 | + {{- $rendered := replaceRE "^<p>(.*)</p>$" "$1" $rawTitle -}} |
| 57 | + {{- $rendered = $rendered | plainify | htmlEscape -}} |
| 58 | + <a href="{{ .RelPermalink }}"><span><strong>{{- $rendered | safeHTML -}}</strong></span></a><br> |
| 59 | + |
| 60 | + {{- /* Safe date: use front matter date only if non-empty & matches basic pattern */ -}} |
| 61 | + {{- $d := .Date -}} |
| 62 | + {{- with .Params.date -}} |
| 63 | + {{- $datestr := trim . " " -}} |
| 64 | + {{- if and (ne $datestr "") (findRE `^\d{4}-\d{2}-\d{2}` $datestr) -}} |
| 65 | + {{- $d = time $datestr -}} |
| 66 | + {{- end -}} |
| 67 | + {{- end -}} |
| 68 | + <time datetime="{{ $d.Format "2006-01-02" }}">{{ $d.Format "2006-01-02" }}</time><br> |
| 69 | + |
| 70 | + {{ with .Params.abstract -}} |
| 71 | + {{- $plain := . | plainify | htmlEscape | replaceRE `\s+` " " -}} |
| 72 | + {{- $words := split $plain " " -}} |
| 73 | + {{- $previewWords := cond (gt (len $words) 24) (first 24 $words) $words -}} |
| 74 | + {{- $preview := delimit $previewWords " " -}} |
| 75 | + <br> |
| 76 | + <div>{{ $preview | safeHTML }}{{ if gt (len $words) 24 }}…{{ end }}</div> |
| 77 | + <br> |
83 | 78 | {{- end -}} |
84 | 79 |
|
85 | | - {{- $authors := .Params.authors -}} |
86 | | - {{- /* warnf "authors: %v" $authors */ -}} |
| 80 | + {{- $authors := .Params.authors -}} |
87 | 81 | {{- if $authors -}} |
88 | 82 | {{- if reflect.IsSlice $authors -}} |
89 | 83 | {{ delimit $authors "; " " and " }}<br> |
90 | 84 | {{- else -}} |
91 | 85 | {{ $authors }}<br> |
92 | 86 | {{- end -}} |
93 | 87 | {{- end -}} |
94 | | - </li> |
95 | | - {{ end }} |
96 | | - </ul> |
97 | | -{{ end }} |
| 88 | + </li> |
| 89 | + {{ end }} |
| 90 | +</ul> |
| 91 | + |
| 92 | +<script> |
| 93 | +document.addEventListener('DOMContentLoaded', function () { |
| 94 | + const sel = document.getElementById('itemTypeFilter'); |
| 95 | + const items = Array.from(document.querySelectorAll('#bibliographyList > li')); |
| 96 | + |
| 97 | + function applyFilter() { |
| 98 | + const val = sel.value; // taxonomy term key (lowercase) |
| 99 | + items.forEach(li => { |
| 100 | + const raw = (li.dataset.type || '').trim(); |
| 101 | + const types = raw ? raw.split(',').map(s => s.trim()) : []; |
| 102 | + const show = (val === 'all') || types.includes(val); |
| 103 | + li.style.display = show ? '' : 'none'; |
| 104 | + }); |
| 105 | + } |
| 106 | + |
| 107 | + // Preselect from URL (?item_type=term) |
| 108 | + const params = new URLSearchParams(window.location.search); |
| 109 | + const q = (params.get('item_type') || '').toLowerCase(); |
| 110 | + if (q && sel.querySelector(`option[value="${q}"]`)) { |
| 111 | + sel.value = q; |
| 112 | + } |
| 113 | + |
| 114 | + sel.addEventListener('change', applyFilter); |
| 115 | + applyFilter(); |
| 116 | +}); |
| 117 | +</script> |
98 | 118 |
|
| 119 | +{{ end }} |
99 | 120 |
|
0 commit comments