Skip to content

Commit 92b7232

Browse files
committed
Taxonomy support for filtering bibliographical entries
Add bibliographical support for item_type (the type of bibliographic entry) and author. Provide support for filtering bibliographic list by both types of tags.
1 parent 6e84cf9 commit 92b7232

File tree

9 files changed

+150
-348
lines changed

9 files changed

+150
-348
lines changed

.github/workflows/gh-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ defaults:
4343
env:
4444
# ----------------------------------------------------------------------------
4545
# Specify the deployment environment: staging or production
46-
HUGO_ENVIRONMENT: staging
46+
HUGO_ENVIRONMENT: production
4747
HUGO_VERSION: 0.144.2
4848

4949
jobs:

config/_default/hugo.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ defaultContentLanguageInSubdir: false
3535
enableMissingTranslationPlaceholders: true
3636

3737
# Disable rendering of the specified page kinds
38-
disableKinds:
39-
- term
38+
#disableKinds:
39+
# - term
40+
# Note terms are needed for taxonomies to work
4041

4142
outputs:
4243
home:

config/_default/params.yaml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,26 @@ links:
104104
# icon: "fa fa-envelope"
105105
# desc: "Discuss development issues around the project"
106106

107-
related:
108-
threshold: 80
109-
includeNewer: true
110-
toLower: true
111-
indices:
112-
- name: tags
113-
weight: 100
114-
- name: categories
115-
weight: 70
107+
taxonomy:
108+
taxonomyCloud:
109+
- authors
110+
taxonomyCloudTitle:
111+
- Authors
112+
taxonomyPageHeader:
113+
- authors
114+
- item_type
115+
116+
#related:
117+
# threshold: 80
118+
# includeNewer: true
119+
# toLower: true
120+
# indices:
121+
# - name: item_type
122+
# weight: 5
123+
# - name: tags
124+
# weight: 100
125+
# - name: categories
126+
# weight: 70
116127

117128
# Nothing defined
118129

@@ -159,7 +170,7 @@ ui:
159170
sidebar_cache_limit: 100
160171

161172
# We have almost 200 attributes; don't truncate the sidebar to max 50 contents.
162-
sidebar_menu_truncate: 1000
173+
sidebar_menu_truncate: 0
163174

164175
# Set to true to disable breadcrumb navigation.
165176
breadcrumb_disable: false

config/_default/taxonomies.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
taxonomies:
2-
tag: tags
3-
category: categories
4-
author: authors
5-
item_type: item_type
1+
tag: tags
2+
category: categories
3+
author: authors
4+
item_type: item_type
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: Bibliography
3+
heading: Interlisp Bibliography
34
type: bibliography
45
cascade:
56
type: bibliography
@@ -8,7 +9,4 @@ aliases:
89
- /bibliography/
910

1011
---
11-
12-
# Interlisp Bibliography
13-
1412
(This bibliography is kept in sync with our [Zotero](https://www.zotero.org/) collection [Library](https://www.zotero.org/groups/2914042/interlisp/library).

layouts/bibliography/baseof.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
<div class="container-fluid td-outer">
1414
<div class="td-main" {{- .Section | safeHTMLAttr }}>
1515
<div class="row flex-xl-nowrap">
16-
<aside class="col-12 col-md-3 col-xl-2 td-sidebar d-print-none">
17-
{{ partial "sidebar.html" . }}
18-
</aside>
1916
<aside class="d-none d-xl-block col-xl-2 td-sidebar-toc d-print-none">
2017
{{ partial "page-meta-links.html" . }}
2118
{{ partial "toc.html" . }}

layouts/bibliography/list.html

Lines changed: 99 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,120 @@
1+
{{ define "sidebar" }}{{ end }}
12
{{ define "main" }}
23

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>
4034

4135
{{ $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-
4936
{{- /* Sort by date descending, then title ascending */ -}}
5037
{{- $pages = sort $pages "Date" "desc" -}}
5138
{{- $pages = sort $pages "Title" "asc" -}}
5239

5340
{{- /* Render the list of publications */ -}}
5441

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>
8378
{{- end -}}
8479

85-
{{- $authors := .Params.authors -}}
86-
{{- /* warnf "authors: %v" $authors */ -}}
80+
{{- $authors := .Params.authors -}}
8781
{{- if $authors -}}
8882
{{- if reflect.IsSlice $authors -}}
8983
{{ delimit $authors "; " " and " }}<br>
9084
{{- else -}}
9185
{{ $authors }}<br>
9286
{{- end -}}
9387
{{- 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>
98118

119+
{{ end }}
99120

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{{ $context := .context -}}
2+
{{ $taxo := .taxo -}}
3+
{{ $title := .title -}}
4+
5+
{{ if eq $context.Type "bibliography" }}
6+
{{ if isset $context.Site.Taxonomies (lower $taxo) -}}
7+
{{ $taxonomy := index $context.Site.Taxonomies (lower $taxo) -}}
8+
{{ if (gt (len $taxonomy) 0) -}}
9+
<div class="taxonomy taxonomy-terms-cloud taxo-{{ urlize $taxo }}">
10+
{{ with $title -}}
11+
<h5 class="taxonomy-title">{{ . }}</h5>
12+
{{ end -}}
13+
<ul class="taxonomy-terms">
14+
{{ range $taxonomy -}}
15+
<li><a class="taxonomy-term" href="{{ .Page.Permalink }}" data-taxonomy-term="{{ urlize .Page.Title }}"><span class="taxonomy-label">{{ .Page.Title }}</span><span class="taxonomy-count">{{ .Count }}</span></a></li>
16+
{{ end -}}
17+
</ul>
18+
</div>
19+
{{ end -}}
20+
{{ end -}}
21+
{{ end }}

0 commit comments

Comments
 (0)