Skip to content

Initial attempt to create individual pages for the Bibliography entries. #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ _gen/
.hugo_build.lock
.idea
data/bibliography.json
/docs
294 changes: 294 additions & 0 deletions layouts/shortcodes/bibItem.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
<style>
.abstractExpander {
background-color: #00A6ED;
color: white;
cursor: pointer;
padding: 1px 5px;
border: none;
text-align: left;
margin: 5px auto 2px 25px;
outline: none;
font-size: 1.0rem;
}

.abstractContent {
padding: 5px;
margin: 0 5px 0 15px;
font-size: 1.0rem;
clear: both;
}

.right { float: right }
.left { float: left }

.year {
margin: 5px auto 2px 15px;
background-color: #88C;
color: white;
}

.tooltipNotes {
position: relative;
display: inline-block;
font-size: 1.0rem;
font-weight: 400;
background-color: #00A6ED;
color: white;
cursor: pointer;
padding: 1px 5px;
border: none;
text-align: center;
margin: auto;
outline: none;
}

/*
Below, where populating the tooltipNotesText, the nested replace functions remove any p-tags, and make - non-breaking.
It also makes space non-breaking.
This is because I cannot determine how to specify not to word wrap the content UNTIL it would exceed the container's max-width (if there even IS a way to do so). This causes long items to wrap VERY BADLY.
*/
.tooltipNotes .tooltipNotesText {
visibility: hidden;
position: absolute;
min-width: 150px;
max-width: 600px;
background-color: #555;
color: white;
font-size: 1.0rem;
text-align: left;
padding: 5px;
border-radius: 6px;
z-index: 1;
opacity: 0;
transition: opacity 0.3s;
overflow-wrap: break-word;
}

.tooltipNotes:hover .tooltipNotesText {
visibility: visible;
opacity: 1;
}

.tooltipNotes-left {
top: 0px;
bottom:auto;
right: 128%;
}

.tooltipNotes-left::after {
content: "";
position: absolute;
top: 0.9rem;
left: 100%;
margin-top: 0px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent transparent #555;
}
.tooltipNotes-right {
top: -5px;
bottom:auto;
left: 125%;
}

.tooltipNotes-right::after {
content: "";
position: absolute;
top: 0.9rem;
right: 100%;
margin-top: 0px;
border-width: 5px;
border-style: solid;
border-color: transparent #555 transparent transparent;
}

.tooltipNotes-bottom {
top: 135%;
left: 50%;
margin-left: -60px;
}

.tooltipNotes-bottom::after {
content: "";
position: absolute;
bottom: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent #555 transparent;
}

.tooltipNotes-top {
bottom: 125%;
left: 50%;
margin-left: -60px;
}

.tooltipNotes-top::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}

.label {
font-weight: 700;
}

</style>

{{- $notesIcon := "\u24C3" -}}
{{- $nonBreakingHyphen := "\u2011" -}}
<script>
var abstractExpanderOpen = "Abstract \u25BC";
var abstractExpanderClose = "Abstract \u25B2";
</script>

{{ $item := dict -}}
{{- $jsonFile := printf "data/bibItems/%s.json" (.Get "key") -}}
{{- $bib := resources.Get $jsonFile -}}
{{- with $bib -}}
{{- with . | transform.Unmarshal -}}
{{- $item = . -}}
{{- end -}}
{{- else -}}
{{- $jsonFile | errorf "Unable to get item resource '%s'" -}}
{{- end -}}
{{- with $item -}}
{{- if or .author .editor -}}
<h3>
{{- 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 -}},&nbsp;{{- $auEd.given -}}
{{- else -}}
{{- $auEd.family -}}{{- $auEd.given -}}
{{- end -}}
{{- end -}}
</h3>
{{- end -}}
{{- if .url }}
<h3><a href="{{- .url -}}">Access document</a></h3>
{{ end -}}
{{- if eq .itemType "journalArticle" -}}
{{- $journalTitle := or .publicationTitle .journalAbbreviation -}}
{{- if $journalTitle }}
<br><span class="label">Publication:</span> {{ $journalTitle -}}
{{- end -}}
{{- if .volume }}
<br><span class="label">Volume:</span> {{ .volume -}}
{{- end -}}
{{- if .issue }}
<br><span class="label">Issue:</span> {{ .issue -}}
{{- end -}}
{{- $date := "" -}}
{{- if .issuedDateParts -}}
{{- $dp := .issuedDateParts -}}
{{- $dpl := len $dp -}}
{{- $dpf := "January 1, 1900" -}}
{{- $y := 0 -}}
{{- $m := 10 -}}
{{- $d := 18 -}}
{{- if ge $dpl 1 -}}
{{- $y := strings.TrimLeft "0" (string (index $dp 0)) | int -}}
{{- $dpf := "1900" -}}
{{- end -}}
{{- if ge $dpl 2 -}}
{{- $m := strings.TrimLeft "0" (string (index $dp 1)) | int -}}
{{- $dpf := "January 1900" -}}
{{- end -}}
{{- if ge $dpl 3 -}}
{{- $d := strings.TrimLeft "0" (string (index $dp 2)) | int -}}
{{- $dpf := "January 1, 1900" -}}
{{- end -}}
{{- if $y -}}
{{- $t := printf "%4d-%2d-%2d" $y $m $d -}}
{{- $dp := time.AsTime $t -}}
{{- $date := $dp.Format $dpf -}}
{{- end -}}
{{- end -}}
{{- if and (not $date) .date -}}
{{- $date := .date -}}
{{- end -}}
{{- if $date }}
<br><span class="label">Date:</span> {{ $date -}}
{{- end -}}
{{- $pages := or .pages .page -}}
{{- if $pages }}
<br><span class="label">Pages:</span> {{ $pages -}}
{{- end -}}
{{- end -}}
{{- if .DOI }}
<br><span class="label">DOI:</span> {{ .DOI -}}
{{- end -}}
{{- if .ISSN }}
<br><span class="label">ISSN:</span> {{ .ISSN -}}
{{- end -}}
{{- if .abstract }}
<br><span class="label">Abstract:</span><br><div class="abstractContent">
{{- range $na, $abstract := split (plainify .abstract) "\n" -}}
{{- if $na -}}<br>{{- end -}}
{{if strings.ContainsNonSpace $abstract -}}
{{- $trimmed := strings.TrimLeft " " $abstract -}}{{- $indent := (sub ($abstract | len) ($trimmed | len)) -}}
{{- print (safeJS (htmlUnescape (printf "%s" $trimmed | printf "%s%s" (strings.Repeat $indent " ") | printf "%s"))) -}}
{{- end -}}
{{- end -}}
</div>
{{ end -}}
{{- if and false .note -}}
{{- $itemID := (cond (gt (len .id) 0) (replace .id `/` `_`) `_0`) -}}
{{- $notes := split (plainify .note) "\n" -}}
<div class="tooltipNotes right" id="N{{$itemID}}">Notes
<span class="tooltipNotesText tooltipNotes-left" id="N{{$itemID}}_Text">
{{- range $nn, $note := $notes -}}
{{if strings.ContainsNonSpace $note -}}
{{- if $nn -}}<br>{{- end -}}
{{- print (safeJS (replace (replace (htmlUnescape $note) "-" $nonBreakingHyphen) " " " ")) -}}
{{- end -}}
{{- end -}}
</span>
</div>
{{- end -}}
{{- end -}}
<br><hr><br>
<script>
function abstractExpanderClick() {
this.classList.toggle("active");
var abstractContent = document.getElementById(this.id.concat("_Abs"));
if (abstractContent.style.display === "block") {
abstractContent.style.display = "none";
this.textContent = abstractExpanderOpen;
} else {
abstractContent.style.display = "block";
this.textContent = abstractExpanderClose;
}
}

function tooltipNotesTextMouseOver() {
// this.classList.toggle("active");
var content = document.getElementById(this.id.concat("_Text"));
if (content.style.display === "block") {
abstractContent.style.display = "none";
// this.textContent = abstractExpanderOpen;
} else {
abstractContent.style.display = "block";
// this.textContent = abstractExpanderClose;
}
}

var i;
var coll = document.getElementsByClassName("abstractExpander");
for (i = 0; i < coll.length; i++) {
coll[i].textContent = abstractExpanderOpen;
coll[i].addEventListener("click", abstractExpanderClick); }

</script>

7 changes: 7 additions & 0 deletions scripts/bib-fns.jq
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def unwrapDiv:
def moveURL_to_url:
select(nonBlankKey("URL")) | (setpath(["url"]; .URL) | del(.URL)) // .;

def raise_issued_date_parts:
if nonBlankKey("issued") and (.issued | nonBlankKey("date-parts")) then setpath(["issuedDateParts"]; .issued."date-parts"[0]) else . end;

def make_DOI_to_url($doi):
if ($doi | startswith("https:")) then $doi else "https://doi.org/" + ($doi | ltrimstr("/")) end ;

Expand Down Expand Up @@ -90,3 +93,7 @@ def semiflatten: # assumes that only one item is the input
+ ($innerKeys | map(. as $iKey | {"key": $iKey, "value": ($inner | getpath([$iKey]))})) )
| from_entries;

def bibItem: # assumes that only one item is the input
. as $item
| (keys - ["key","title","target"]) as $tailKeys
| {"key": .key, "title": .title, "target": .target } + ($tailKeys | map(. as $tKey | {"key": $tKey, "value": ($item | getpath([$tKey]))}) | from_entries);
35 changes: 35 additions & 0 deletions scripts/bibSplit.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! /usr/bin/perl -n
BEGIN
{
$bibDir = $ENV{'BIBLIOGRAPHY_DIR'};
$bibItemsDir = $ENV{'BIBITEMS_DIR'};
}
my $item = $_;
/"key"\:"([A-Za-z0-9]{8})"/ || print "Cannot find key in line: $_\n";
my $key = $1;
/"target"\:"([A-Za-z0-9]{8})"/ || print "Cannot find target for key \"$key\" in line: $_\n";
my $target = $1;
if ($key eq $target) { # only top level entries
my $handle = undef;
my $itemjson = "$bibItemsDir/$key.json";
open($handle, ">", $itemjson) || die "$0: cannot open $itemjson in write-open mode: $!";
print $handle $item;
close $handle || die "$0: close of file $itemjson failed: $!";

/"title"\:("(?:[^"\\]++|\\.)*+")/ || print "Cannot find title for key \"$key\" in line: $_\n";
my $itemTitle = $1;
$handle = undef;
my $itemmd = "$bibDir/$key.md";
open($handle, ">", $itemmd) || die "$0: cannot open $itemmd in write-open mode: $!";
print $handle <<ENDITEM;
---
title: $itemTitle
weight: 5
type: docs
---

{{< bibItem key="$key" >}}
ENDITEM
close $handle || die "$0: close of file $itemmd failed: $!";

}
Loading