Skip to content

Commit f212723

Browse files
committed
Improved, but still work in progress.
This now creates the files but has some difficulties. The main Bibliography page hasn't been changed.
1 parent 0b2482e commit f212723

File tree

6 files changed

+169
-91
lines changed

6 files changed

+169
-91
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ _gen/
1818
.hugo_build.lock
1919
.idea
2020
data/bibliography.json
21+
/docs

layouts/shortcodes/bibItem.html

Lines changed: 118 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
.abstractContent {
1515
padding: 5px;
1616
margin: 0 5px 0 15px;
17-
display: none;
18-
font-size: 0.9rem;
19-
overflow: hidden;
20-
background-color: #e8e8ff;
17+
font-size: 1.0rem;
2118
clear: both;
2219
}
2320

@@ -30,12 +27,6 @@
3027
color: white;
3128
}
3229

33-
.bibTitle {
34-
font-weight: 700;
35-
}
36-
37-
.authors { margin: 5px auto 2px 5px; }
38-
3930
.tooltipNotes {
4031
position: relative;
4132
display: inline-block;
@@ -145,58 +136,129 @@
145136
border-color: #555 transparent transparent transparent;
146137
}
147138

139+
.label {
140+
font-weight: 700;
141+
}
142+
148143
</style>
149144

150-
{{ $notesIcon := "\u24C3" }}
151-
{{ $nonBreakingHyphen := "\u2011" }}
145+
{{- $notesIcon := "\u24C3" -}}
146+
{{- $nonBreakingHyphen := "\u2011" -}}
152147
<script>
153148
var abstractExpanderOpen = "Abstract \u25BC";
154149
var abstractExpanderClose = "Abstract \u25B2";
150+
</script>
155151

156-
/*
157-
var abstractExpanderOpen = "Abstract +";
158-
var abstractExpanderClose = "Abstract -";
159-
*/</script>
160-
161-
<table style="max-width: 100%">
162-
<thead>
163-
<tr>
164-
<th>Reference</th>
165-
</tr>
166-
</thead>
167-
<tbody style="overflow:auto">
168-
{{ with .params.bibItem }}
169-
<tr>
170-
{{ $itemID := (cond (gt (len .id) 0) (replace .id `/` `_`) `_0`) }}
171-
<td><div class="bibTitle">{{ if .url }}<a href="{{ .url }}">{{ .title }}</a>{{ else }}{{ .title }}{{ end }}</div>
172-
{{ if or .author .editor }}<div class="authors">{{ if not .author }}<i>Edited by: </i>{{ end }}{{ range $naE, $auEd := or .author .editor }}{{ if $naE }}; {{ end }}{{ if $auEd.literal }}{{ $auEd.literal }}{{ else if and $auEd.family $auEd.given }}{{ $auEd.family }}, {{ $auEd.given }}{{ else }}{{ $auEd.family }}{{ $auEd.given }}{{ end }}{{ end }}
173-
</div>{{ end }}
174-
{{ if .abstract }}<button type="button" class="abstractExpander left" id="A{{$itemID}}">AAA</button>{{ end }}
175-
{{ if and false .note }}
176-
{{ $notes := split (plainify .note) "\n" }}
177-
<div class="tooltipNotes right" id="N{{$itemID}}">Notes
178-
<span class="tooltipNotesText tooltipNotes-left" id="N{{$itemID}}_Text">
179-
{{ range $nn, $note := $notes }}
180-
{{if strings.ContainsNonSpace $note }}
181-
{{ if $nn }}<br>{{ end }}
182-
{{ print (safeJS (replace (replace (htmlUnescape $note) "-" $nonBreakingHyphen) " " " ")) }}
183-
{{ end }}
184-
{{ end }}</span></div>
185-
{{ end }}
186-
{{ if .abstract }}<br><div class="abstractContent" id="A{{$itemID }}_Abs">
187-
{{ range $na, $abstract := split (plainify .abstract) "\n" }}
188-
{{if strings.ContainsNonSpace $abstract }}
189-
{{ if $na }}<br>{{ end }}
190-
{{ $trimmed := strings.TrimLeft " " $abstract }}{{ $indent := (sub ($abstract | len) ($trimmed | len)) }}
191-
{{ print (safeJS (htmlUnescape (printf "%s" $trimmed | printf "%s%s" (strings.Repeat $indent " ") | printf "%s"))) }}
192-
{{ end }}
193-
{{ end }}
194-
</div>{{ end }}</td>
195-
</tr>
196-
{{ end }}
197-
</tbody>
198-
199-
</table>
152+
{{ $item := dict -}}
153+
{{- $jsonFile := printf "data/bibItems/%s.json" (.Get "key") -}}
154+
{{- $bib := resources.Get $jsonFile -}}
155+
{{- with $bib -}}
156+
{{- with . | transform.Unmarshal -}}
157+
{{- $item = . -}}
158+
{{- end -}}
159+
{{- else -}}
160+
{{- $jsonFile | errorf "Unable to get item resource '%s'" -}}
161+
{{- end -}}
162+
{{- with $item -}}
163+
{{- if or .author .editor -}}
164+
<h3>
165+
{{- if not .author -}}<i>Edited by: </i>{{- end -}}
166+
{{- range $naE, $auEd := or .author .editor -}}
167+
{{- if $naE -}}; {{ end -}}
168+
{{- if $auEd.literal -}}
169+
{{- $auEd.literal -}}
170+
{{- else if and $auEd.family $auEd.given -}}
171+
{{- $auEd.family -}},&nbsp;{{- $auEd.given -}}
172+
{{- else -}}
173+
{{- $auEd.family -}}{{- $auEd.given -}}
174+
{{- end -}}
175+
{{- end -}}
176+
</h3>
177+
{{- end -}}
178+
{{- if .url }}
179+
<h3><a href="{{- .url -}}">Access document</a></h3>
180+
{{ end -}}
181+
{{- if eq .itemType "journalArticle" -}}
182+
{{- $journalTitle := or .publicationTitle .journalAbbreviation -}}
183+
{{- if $journalTitle }}
184+
<br><span class="label">Publication:</span> {{ $journalTitle -}}
185+
{{- end -}}
186+
{{- if .volume }}
187+
<br><span class="label">Volume:</span> {{ .volume -}}
188+
{{- end -}}
189+
{{- if .issue }}
190+
<br><span class="label">Issue:</span> {{ .issue -}}
191+
{{- end -}}
192+
{{- $date := "" -}}
193+
{{- if .issuedDateParts -}}
194+
{{- $dp := .issuedDateParts -}}
195+
{{- $dpl := len $dp -}}
196+
{{- $dpf := "January 1, 1900" -}}
197+
{{- $y := 0 -}}
198+
{{- $m := 10 -}}
199+
{{- $d := 18 -}}
200+
{{- if ge $dpl 1 -}}
201+
{{- $y := strings.TrimLeft "0" (string (index $dp 0)) | int -}}
202+
{{- $dpf := "1900" -}}
203+
{{- end -}}
204+
{{- if ge $dpl 2 -}}
205+
{{- $m := strings.TrimLeft "0" (string (index $dp 1)) | int -}}
206+
{{- $dpf := "January 1900" -}}
207+
{{- end -}}
208+
{{- if ge $dpl 3 -}}
209+
{{- $d := strings.TrimLeft "0" (string (index $dp 2)) | int -}}
210+
{{- $dpf := "January 1, 1900" -}}
211+
{{- end -}}
212+
{{- if $y -}}
213+
{{- $t := printf "%4d-%2d-%2d" $y $m $d -}}
214+
{{- $dp := time.AsTime $t -}}
215+
{{- $date := $dp.Format $dpf -}}
216+
{{- end -}}
217+
{{- end -}}
218+
{{- if and (not $date) .date -}}
219+
{{- $date := .date -}}
220+
{{- end -}}
221+
{{- if $date }}
222+
<br><span class="label">Date:</span> {{ $date -}}
223+
{{- end -}}
224+
{{- $pages := or .pages .page -}}
225+
{{- if $pages }}
226+
<br><span class="label">Pages:</span> {{ $pages -}}
227+
{{- end -}}
228+
{{- end -}}
229+
{{- if .DOI }}
230+
<br><span class="label">DOI:</span> {{ .DOI -}}
231+
{{- end -}}
232+
{{- if .ISSN }}
233+
<br><span class="label">ISSN:</span> {{ .ISSN -}}
234+
{{- end -}}
235+
{{- if .abstract }}
236+
<br><span class="label">Abstract:</span><br><div class="abstractContent">
237+
{{- range $na, $abstract := split (plainify .abstract) "\n" -}}
238+
{{- if $na -}}<br>{{- end -}}
239+
{{if strings.ContainsNonSpace $abstract -}}
240+
{{- $trimmed := strings.TrimLeft " " $abstract -}}{{- $indent := (sub ($abstract | len) ($trimmed | len)) -}}
241+
{{- print (safeJS (htmlUnescape (printf "%s" $trimmed | printf "%s%s" (strings.Repeat $indent " ") | printf "%s"))) -}}
242+
{{- end -}}
243+
{{- end -}}
244+
</div>
245+
{{ end -}}
246+
{{- if and false .note -}}
247+
{{- $itemID := (cond (gt (len .id) 0) (replace .id `/` `_`) `_0`) -}}
248+
{{- $notes := split (plainify .note) "\n" -}}
249+
<div class="tooltipNotes right" id="N{{$itemID}}">Notes
250+
<span class="tooltipNotesText tooltipNotes-left" id="N{{$itemID}}_Text">
251+
{{- range $nn, $note := $notes -}}
252+
{{if strings.ContainsNonSpace $note -}}
253+
{{- if $nn -}}<br>{{- end -}}
254+
{{- print (safeJS (replace (replace (htmlUnescape $note) "-" $nonBreakingHyphen) " " " ")) -}}
255+
{{- end -}}
256+
{{- end -}}
257+
</span>
258+
</div>
259+
{{- end -}}
260+
{{- end -}}
261+
<br><hr><br>
200262
<script>
201263
function abstractExpanderClick() {
202264
this.classList.toggle("active");

scripts/bib-fns.jq

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ def unwrapDiv:
1212
def moveURL_to_url:
1313
select(nonBlankKey("URL")) | (setpath(["url"]; .URL) | del(.URL)) // .;
1414

15+
def raise_issued_date_parts:
16+
if nonBlankKey("issued") and (.issued | nonBlankKey("date-parts")) then setpath(["issuedDateParts"]; .issued."date-parts"[0]) else . end;
17+
1518
def make_DOI_to_url($doi):
1619
if ($doi | startswith("https:")) then $doi else "https://doi.org/" + ($doi | ltrimstr("/")) end ;
1720

scripts/bibSplit.pl

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
#! /usr/bin/perl -n
2-
BEGIN { $bibDir = $ENV{'BIBLIOGRAPHY_DIR'}; print "bibDir: $bibDir\n";}
2+
BEGIN
3+
{
4+
$bibDir = $ENV{'BIBLIOGRAPHY_DIR'};
5+
$bibItemsDir = $ENV{'BIBITEMS_DIR'};
6+
}
37
my $item = $_;
4-
/"key"\:"([A-Za-z0-9]{8})"/ || print "Cannot find key on line: $_\n";
8+
/"key"\:"([A-Za-z0-9]{8})"/ || print "Cannot find key in line: $_\n";
59
my $key = $1;
6-
/"title"\:("(?:[^"\\]++|\\.)*+")/ || print "Cannot find title for key \"$key\" on line: $_\n";
7-
my $itemTitle = $1;
8-
/"target"\:"([A-Za-z0-9]{8})"/ || print "Cannot find target for key \"$key\" on line: $_\n";
10+
/"target"\:"([A-Za-z0-9]{8})"/ || print "Cannot find target for key \"$key\" in line: $_\n";
911
my $target = $1;
1012
if ($key eq $target) { # only top level entries
11-
# print "KEY: $key TITLE:$itemTitle\n";
1213
my $handle = undef;
13-
my $itemfn = "$bibDir/$key.md";
14-
open($handle, ">", $itemfn) || die "$0: cannot open $itemfn in write-open mode: $!";
14+
my $itemjson = "$bibItemsDir/$key.json";
15+
open($handle, ">", $itemjson) || die "$0: cannot open $itemjson in write-open mode: $!";
16+
print $handle $item;
17+
close $handle || die "$0: close of file $itemjson failed: $!";
18+
19+
/"title"\:("(?:[^"\\]++|\\.)*+")/ || print "Cannot find title for key \"$key\" in line: $_\n";
20+
my $itemTitle = $1;
21+
$handle = undef;
22+
my $itemmd = "$bibDir/$key.md";
23+
open($handle, ">", $itemmd) || die "$0: cannot open $itemmd in write-open mode: $!";
1524
print $handle <<ENDITEM;
16-
{"title": $itemTitle,
17-
"weight": "5",
18-
"type": "docs",
19-
"params": {"bibItem": $item}
20-
}
25+
---
26+
title: $itemTitle
27+
weight: 5
28+
type: docs
29+
---
2130
22-
{{< bibItem >}}
31+
{{< bibItem key="$key" >}}
2332
ENDITEM
24-
close $handle || die "$0: close of file $itemfn failed: $!";
25-
}
26-
else
27-
{
28-
# print "KEY: $key TARGET: $target TITLE:$itemTitle\n";
33+
close $handle || die "$0: close of file $itemmd failed: $!";
34+
2935
}

scripts/update_bibliography.sh

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

33
set -e
44

5-
rawItemsFile=true
5+
rawItemsFile=false
66
debugFiles=true
77
tagFiles=false
8-
typeFiles=false
8+
typeFiles=true
99
curlFiles=false
1010
# The collection files will be created only if directly querying Zotero API.
1111
collectionFiles=false
@@ -147,12 +147,6 @@ if $debugFiles ; then
147147
echo "$items" > "$dfn"
148148
fi
149149

150-
showInfo 5 "Delete items that Zotero indicated as such."
151-
beforeCount=$(jq '. | length' <<< "$items")
152-
items=$(jq 'map(select(.deleted|not))' <<< "$items")
153-
afterCount=$(jq '. | length' <<< "$items")
154-
showInfo 5 "Removed $(( $beforeCount - $afterCount )) items marked as deleted."
155-
156150
showInfo 8 "Find duplicate .key entries"
157151
groupedByKey=$(jq 'group_by(.key)' <<< "$items")
158152
if $debugFiles ; then
@@ -173,6 +167,16 @@ if $debugFiles ; then
173167
dfn=$(debugFileName "noDupSorted" $dfn)
174168
echo "$items" > "$dfn"
175169
fi
170+
171+
# Remove library, links, and meta objects; and some fields from entries
172+
# (These are not used any further on, so simplify.)
173+
items=$(jq 'map(del(.["library", "links", "meta", "accessed", "accessDate", "dateAdded", "dateModified"]))' <<< "$items")
174+
showInfo 8 "Remove library, links, and meta objects and some unnecessary fields"
175+
if $debugFiles ; then
176+
dfn=$(debugFileName "noLibraryLinksMeta" $dfn)
177+
echo "$items" > "$dfn"
178+
fi
179+
176180
if $typeFiles ; then
177181
types=$(jq 'map({key, title, type, itemType}) | group_by(.type) | map({type:.[0].type, itemTypes:(group_by(.itemType)|map({itemType:.[0].itemType, items:map({title, key})}))})' <<<"$items")
178182
echo "$types" > titleKeyTypeInfo.json
@@ -216,6 +220,12 @@ if $debugFiles ; then
216220
echo "$items" > "$dfn"
217221
fi
218222

223+
showInfo 5 "Delete items that Zotero indicated as such."
224+
beforeCount=$(jq '. | length' <<< "$items")
225+
items=$(jq 'map(select(.deleted|not))' <<< "$items")
226+
afterCount=$(jq '. | length' <<< "$items")
227+
showInfo 5 "Removed $(( $beforeCount - $afterCount )) items marked as deleted."
228+
219229
showInfo 1 "Got $(jq '. | length' <<< "$items") clean, top-level items"
220230
items=$(jq 'include "./bib-fns";map(applyChildrenAmendments)' <<< "$items")
221231
showInfo 8 "Update Parent items from their Children"
@@ -254,6 +264,7 @@ if $debugFiles ; then
254264
fi
255265
finalCount=$(jq '. | length' <<< "$items")
256266

267+
items=$(jq 'include "./bib-fns";map(raise_issued_date_parts)' <<< "$items")
257268
# if $removeChildrenFromFinalFile; then
258269
# # Remove .children arrays, if any. Save space.
259270
# items=$(jq 'map(del(.children))' <<< "$items")
@@ -264,16 +275,9 @@ finalCount=$(jq '. | length' <<< "$items")
264275
# fi
265276
# fi
266277

267-
# Remove library, links, and meta objects from entries
268-
# (These are not used any further on, so simplify.)
269-
items=$(jq 'map(del(.["library", "links", "meta"]))' <<< "$items")
270-
showInfo 8 "Remove library, links, and meta objects"
271-
if $debugFiles ; then
272-
dfn=$(debugFileName "noLibraryLinksMeta" $dfn)
273-
echo "$items" > "$dfn"
274-
fi
275278
# Do this here, instead of keeping a copy of the current value of $items, just to do this later.
276279
jq -c 'include "./bib-fns";.[] | bibItem' <<< "$items" > bibliography-items-by-line.json
280+
# jq 'include "./bib-fns";map(bibItem)' <<< "$items" > 000-bibliography-items-by-line.json
277281

278282
# Group by year
279283
items=$(jq 'group_by(.issued."date-parts"[0][0])' <<< "$items")
@@ -293,6 +297,8 @@ fi
293297
showInfo 1 "Generating individual Bibliography entries' .md files"
294298
BIBLIOGRAPHY_DIR="$(dirname "$0")/../content/en/history/bibliography"
295299
export BIBLIOGRAPHY_DIR
300+
BIBITEMS_DIR="$(dirname "$0")/../static/data/bibItems"
301+
export BIBITEMS_DIR
296302
./bibSplit.pl bibliography-items-by-line.json
297303
# Cleanup (uncomment once working)
298304
# rm bibliography-items-by-line.json

static/data/bibItems/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)