Skip to content

Commit 86d61c2

Browse files
committed
Merge remote-tracking branch 'origin/bs1_bibliography' into bs1_bibliography
2 parents 92b7232 + 6596148 commit 86d61c2

File tree

5 files changed

+132
-37
lines changed

5 files changed

+132
-37
lines changed

layouts/bibliography/list.html

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ <h1 class="bib-title">{{ or .Params.heading .Title }}</h1>
3232
ul.pub-list > li:last-child { border-bottom: none; }
3333
</style>
3434

35+
{{- $previewWordLimit := 24 -}}
36+
37+
{{- /* Get all regular pages in this section */ -}}
3538
{{ $pages := .RegularPages }}
3639
{{- /* Sort by date descending, then title ascending */ -}}
3740
{{- $pages = sort $pages "Date" "desc" -}}
@@ -54,37 +57,70 @@ <h1 class="bib-title">{{ or .Params.heading .Title }}</h1>
5457
<li class="pub-item" data-type="{{ $types }}">
5558
{{- $rawTitle := or .Params.title .Title -}}
5659
{{- $rendered := replaceRE "^<p>(.*)</p>$" "$1" $rawTitle -}}
57-
{{- $rendered = $rendered | plainify | htmlEscape -}}
60+
{{- /* The plainify corrupts values that look like HTML but aren't: "Special files on <Test>ARs>" */ -}}
61+
{{- /* $rendered = $rendered | plainify | htmlEscape */ -}}
62+
{{- $rendered = $rendered | htmlEscape -}}
5863
<a href="{{ .RelPermalink }}"><span><strong>{{- $rendered | safeHTML -}}</strong></span></a><br>
5964

6065
{{- /* Safe date: use front matter date only if non-empty & matches basic pattern */ -}}
66+
{{- $authors := .Params.authors -}}
67+
{{- $editors := .Params.editors -}}
68+
{{- $isPatent := eq .Params.item_type "patent" -}}
69+
{{- /* warnf "authors: %v" $authors */ -}}
70+
{{- if or $authors $editors -}}
71+
{{- if $authors -}}
72+
{{- if reflect.IsSlice $authors -}}
73+
{{- if $isPatent }}
74+
Inventors:
75+
{{ end }}
76+
{{ delimit $authors "; " "; and " }}
77+
{{- else -}}
78+
{{- if $isPatent }}
79+
Inventor:
80+
{{ end }}
81+
{{ $authors }}
82+
{{- end -}}
83+
{{- else -}}
84+
Edited by:
85+
{{ if reflect.IsSlice $editors -}}
86+
{{ delimit $editors "; " "; and " }}
87+
{{- else -}}
88+
{{ $editors }}
89+
{{- end -}}
90+
{{- end -}}
91+
<br>
92+
{{- end -}}
93+
6194
{{- $d := .Date -}}
6295
{{- with .Params.date -}}
6396
{{- $datestr := trim . " " -}}
6497
{{- if and (ne $datestr "") (findRE `^\d{4}-\d{2}-\d{2}` $datestr) -}}
6598
{{- $d = time $datestr -}}
6699
{{- end -}}
67100
{{- end -}}
68-
<time datetime="{{ $d.Format "2006-01-02" }}">{{ $d.Format "2006-01-02" }}</time><br>
101+
{{- $d = $d.Format "2006-01-02" -}}
102+
{{- /* Don't display bogus date */ -}}
103+
{{- if (ne $d "0001-01-01") }}
104+
<time datetime="{{ $d }}">{{ $d }}</time><br>
105+
{{ end -}}
69106

70107
{{ 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 " " -}}
108+
{{- /* can't plainify, as above */ -}}
109+
{{- /* $plain := . | plainify | htmlEscape | replaceRE `\s+` " " */ -}}
110+
{{- $plain := . | htmlEscape | replaceRE `\s+` " " -}}
111+
{{- $previewing := gt (countwords $plain) $previewWordLimit -}}
112+
{{- $preview := "" -}}
113+
{{- if $previewing -}}
114+
{{- $previewWords := split $plain " " | first $previewWordLimit -}}
115+
{{- $preview = delimit $previewWords " " -}}
116+
{{- else -}}
117+
{{- $preview = replace . "\n" "<br>" -}}
118+
{{- end -}}
75119
<br>
76-
<div>{{ $preview | safeHTML }}{{ if gt (len $words) 24 }}…{{ end }}</div>
120+
<div>{{ $preview | safeHTML }}{{ if $previewing }}…{{ end }}</div>
77121
<br>
78122
{{- end -}}
79123

80-
{{- $authors := .Params.authors -}}
81-
{{- if $authors -}}
82-
{{- if reflect.IsSlice $authors -}}
83-
{{ delimit $authors "; " " and " }}<br>
84-
{{- else -}}
85-
{{ $authors }}<br>
86-
{{- end -}}
87-
{{- end -}}
88124
</li>
89125
{{ end }}
90126
</ul>

layouts/bibliography/single.html

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,53 @@
22
<article class="bibliography-entry">
33
<h1>{{ .Title }}</h1>
44

5+
{{- $authors := .Params.authors -}}
6+
{{- $editors := .Params.editors -}}
7+
{{- $isPatent := eq .Params.item_type "patent" -}}
8+
{{- if or $authors $editors -}} {{- /* no empty <p> if neither */ -}}
59
<p>
6-
{{- if .Params.authors -}}
7-
{{- if reflect.IsSlice .Params.authors -}}
8-
{{ delimit .Params.authors ", " " and " }}<br>
10+
{{- if $authors -}}
11+
{{- if reflect.IsSlice $authors -}}
12+
{{- if $isPatent }}
13+
<strong>Inventors:</strong>
14+
{{ end }}
15+
{{ delimit $authors "; " "; and " }}
916
{{- else -}}
10-
{{ .Params.authors }}<br>
17+
{{- if $isPatent }}
18+
<strong>Inventor:</strong>
19+
{{ end }}
20+
{{ $authors }}
1121
{{- end -}}
22+
{{- else -}}
23+
<strong>Edited by:</strong>
24+
{{ if reflect.IsSlice $editors }}
25+
{{ delimit $editors "; " "; and " }}
26+
{{- else }}
27+
{{ $editors }}
28+
{{- end -}}
29+
{{- end -}}
30+
<br></p>
1231
{{- end -}}
13-
</p>
1432

1533
<p>
1634
{{- $d := .Date -}}
17-
{{- with .Params.date }}{{ $d = time . }}{{ end }}
18-
<time datetime="{{ $d.Format "2006-01-02" }}">{{ $d.Format "2006-01-02" }}</time>
35+
{{- with .Params.date -}}
36+
{{- $datestr := trim . " " -}}
37+
{{- if and (ne $datestr "") (findRE `^\d{4}-\d{2}-\d{2}` $datestr) -}}
38+
{{- $d = time $datestr -}}
39+
{{- end -}}
40+
{{- end }}
41+
{{- $d = $d.Format "2006-01-02" -}}
42+
{{- /* Don't display bogus date */ -}}
43+
{{- if (ne $d "0001-01-01") }}
44+
<time datetime="{{ $d }}">{{ $d }}</time>
45+
{{ end -}}
1946
</p>
2047
<p>
21-
<strong>URL:</strong> {{ with .Params.url_source }}
48+
<strong>View document:</strong> {{ with .Params.url_source }}
2249
<a href="{{ . | safeURL }}" target="_blank" rel="noopener noreferrer">{{ . }}</a>
2350
{{ else }}
24-
No URL available.
51+
No URL to the document is available.
2552
{{ end }}
2653
<br>
2754
Cite: placeholder for link to retrieve citation from Zotero

scripts/bib-fns.jq

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ def issued_iso_string:
3030
.
3131
end;
3232

33-
# Build ["Family, Given", "Family2, Given2", ...] string array from .author array.
34-
# Falls back to other common shapes (name / firstName+lastName). Skips empty parts.
35-
def author_string_list:
36-
( .author // [] )
37-
| dbg("author_string_list.count"; length)
38-
| map(
33+
def format_person_name:
3934
if (has("family") and .family != null and (.family|tostring|length)>0) then
4035
.family
4136
+ ( if (has("given") and .given != null and (.given|tostring|length)>0)
@@ -50,12 +45,28 @@ def author_string_list:
5045
.name
5146
else
5247
empty
53-
end
54-
);
48+
end;
49+
50+
# Build ["Family, Given", "Family2, Given2", ...] string array from .author array.
51+
# Falls back to other common shapes (name / firstName+lastName). Skips empty parts.
52+
def author_string_list:
53+
( .author // [] )
54+
# | dbg("author_string_list.count"; length)
55+
| map(format_person_name);
5556

5657
# If you want the field added into each item:
5758
def add_author_string:
58-
. + { authorsFormatted: (author_string_list) };
59+
if (.author) then . + { authorsFormatted: (author_string_list) } end;
60+
61+
# Likewise for editors
62+
def editor_string_list:
63+
( .editor // [] )
64+
# | dbg("editor_string_list.count"; length)
65+
| map(format_person_name);
66+
67+
# If you want the field added into each item:
68+
def add_editor_string:
69+
if (.editor) then. + { editorsFormatted: (editor_string_list) } end;
5970

6071
def make_DOI_to_url($doi):
6172
if ($doi | startswith("https:")) then $doi else "https://doi.org/" + ($doi | ltrimstr("/")) end ;
@@ -139,3 +150,7 @@ def bibItem: # assumes that only one item is the input
139150
. as $item
140151
| (keys - ["key","title","target"]) as $tailKeys
141152
| {"key": .key, "title": .title, "target": .target } + ($tailKeys | map(. as $tKey | {"key": $tKey, "value": ($item | getpath([$tKey]))}) | from_entries);
153+
154+
155+
def removeEmptyKeys:
156+
with_entries(select(.value != "" and .value != null and .value != [] and .value != {}));

scripts/bibSplit.pl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ BEGIN
5858
# Abstracts can be multi-line and contain multiple paragraphs. Place YAML keyword on
5959
# one line and follow it with the abstract indented on subsequent lines.
6060
my $abs = sanitize_text($obj->{abstract} // '');
61+
# a hack for bulleted lists in the abstracts (use markdown there)
62+
# won't work for nested lists.
63+
$abs =~ s/\n?\n\N{U+2022}/\n*/g;
6164
my $indented = join('', map { " $_\n" } split(/\n/, $abs));
6265
my $abstract = $indented eq '' ? "abstract: ''" : "abstract: |\n$indented";
6366

@@ -72,6 +75,17 @@ BEGIN
7275
}
7376
$itemAuthors =~ s/\n$//; # strip trailing newline
7477
}
78+
79+
my $itemEditors = '';
80+
if (ref($obj->{editorsFormatted}) eq 'ARRAY' && @{$obj->{editorsFormatted}}) {
81+
$itemEditors = "\n";
82+
for my $a (@{$obj->{editorsFormatted}}) {
83+
my $quoted = encode_json($a // '');
84+
$itemEditors .= " - $quoted\n";
85+
}
86+
$itemEditors =~ s/\n$//; # strip trailing newline
87+
}
88+
7589
my $urlSource = defined $obj->{url} ? $obj->{url} : '';
7690

7791
# optional fields - ones used vary by value of type
@@ -147,6 +161,7 @@ BEGIN
147161
type: bibliography
148162
item_type: $type
149163
authors: $itemAuthors
164+
editors: $itemEditors
150165
$abstract
151166
152167
$extraFields

scripts/update_bibliography.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
set -e
44

5-
rawItemsFile=false
5+
rawItemsFile=true
66
debugFiles=false
7-
tagFiles=false
8-
typeFiles=true
7+
tagFiles=true
8+
typeFiles=false
99
curlFiles=false
1010
# The collection files will be created only if directly querying Zotero API.
1111
collectionFiles=false
@@ -204,6 +204,7 @@ if $debugFiles ; then
204204
fi
205205

206206
items=$(jq 'include "./bib-fns";map(getTargetInfo)' <<< "$items")
207+
items=$(jq 'include "./bib-fns";map(removeEmptyKeys)' <<< "$items")
207208

208209
# now use children items to amend the info for the parentItem
209210
childrenGroupedByParent=$(jq 'group_by(.target)|map(sort_by(.parentItem))' <<< "$items")
@@ -267,6 +268,8 @@ finalCount=$(jq '. | length' <<< "$items")
267268
items=$(jq 'include "./bib-fns";map(issued_iso_string)' <<< "$items")
268269

269270
items=$(jq 'include "./bib-fns";map(add_author_string)' <<< "$items")
271+
272+
items=$(jq 'include "./bib-fns";map(add_editor_string)' <<< "$items")
270273
# if $removeChildrenFromFinalFile; then
271274
# # Remove .children arrays, if any. Save space.
272275
# items=$(jq 'map(del(.children))' <<< "$items")
@@ -279,7 +282,6 @@ items=$(jq 'include "./bib-fns";map(add_author_string)' <<< "$items")
279282

280283
# Do this here, instead of keeping a copy of the current value of $items, just to do this later.
281284
jq -c 'include "./bib-fns";.[] | bibItem' <<< "$items" > bibliography-items-by-line.json
282-
# jq 'include "./bib-fns";map(bibItem)' <<< "$items" > 000-bibliography-items-by-line.json
283285

284286
# Group by year
285287
items=$(jq 'group_by(.issued."date-parts"[0][0])' <<< "$items")

0 commit comments

Comments
 (0)