Skip to content

Commit

Permalink
Add MODS XML generation & links
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Bollmann committed Mar 9, 2019
1 parent fa57a95 commit 4cbe908
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ To build the Anthology website, you will need:
will speed up the generation process.
+ [**Hugo 0.54**](https://gohugo.io) or higher (can be [downloaded directly from
their repo](https://github.com/gohugoio/hugo/releases); the ***extended version*** is required!)

+ [**bibutils**](https://sourceforge.net/p/bibutils/home/Bibutils/) for creating
non-BibTeX citation formats (not strictly required to build the website, but
without them you need to invoke the build steps manually as laid out in the
[detailed README](README_detailed.md))

### Cloning

Expand Down
13 changes: 12 additions & 1 deletion README_detailed.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,22 @@ In this step, we create `.bib` files for each paper and proceedings volume in
the Anthology. This is achieved by calling:

```bash
$ python3 bin/create_export_formats.py
$ python3 bin/create_bibtex.py
```

The exported files will be written to the `hugo/data-export/` subdirectory.

For other export formats, we rely on the
[`bibutils`](https://sourceforge.net/p/bibutils/home/Bibutils/) suite by
first converting the generated `.bib` files to MODS XML:

```bash
$ find hugo/data-export -name '*.bib' -exec bin/bib2xml_wrapper {} \; >/dev/null
```

This creates a corresponding `.xml` file in MODS format for every `.bib` file
generated previously.

### Step 4: Run Hugo

After all necessary files have been created, the website can be built by simply
Expand Down
3 changes: 3 additions & 0 deletions bin/bib2xml_wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

bib2xml -nt $1 2>&1 > ${1%.bib}.xml
20 changes: 19 additions & 1 deletion bin/build_hugo
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,26 @@ set -o errexit

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Some sanity checks
if ! [ -x "$(command -v bib2xml)" ]; then
>&2 echo "ERROR Couldn't find bib2xml -- did you install bibutils?"
exit 1
fi
if ! [ -x "$(command -v hugo)" ]; then
>&2 echo "ERROR Couldn't find hugo"
exit 1
fi

python3 $DIR/create_hugo_yaml.py
python3 $DIR/create_hugo_pages.py --clean
python3 $DIR/create_export_formats.py --clean
python3 $DIR/create_bibtex.py --clean
cd $DIR/../hugo
>&2 echo "INFO Converting BibTeX files to MODS XML..."
if ! [ -x "$(command -v tqdm)" ]; then
find data-export -name '*.bib' -print0 | xargs -0 -n 1 -P 8 $DIR/bib2xml_wrapper >/dev/null
else
find data-export -name '*.bib' -print0 | xargs -0 -n 1 -P 8 $DIR/bib2xml_wrapper | tqdm --total $(find data-export -name '*.bib' | wc -l) --unit files >/dev/null
fi

>&2 echo "INFO Running Hugo... this may take a while."
hugo --cleanDestinationDir --minify
4 changes: 2 additions & 2 deletions bin/create_export_formats.py → bin/create_bibtex.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
# Marcel Bollmann <[email protected]>, 2019

"""Usage: create_export_formats.py [--importdir=DIR] [--exportdir=DIR] [-c] [--debug]
"""Usage: create_bibtex.py [--importdir=DIR] [--exportdir=DIR] [-c] [--debug]
Creates files for all papers and export formats in the Hugo directory.
Creates .bib files for all papers in the Hugo directory.
Options:
--importdir=DIR Directory to import XML files from. [default: {scriptdir}/../import/]
Expand Down
12 changes: 9 additions & 3 deletions hugo/layouts/papers/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{{ with $paper.page_first }}<meta content="{{ . }}" name="citation_firstpage" >{{ end }}
{{ with $paper.page_last }}<meta content="{{ . }}" name="citation_lastpage" >{{ end }}
{{ with $paper.doi }}<meta content="{{ . }}" name="citation_doi" >{{ end }}
{{ with $paper.year }}<meta content="{{ . }}" name="citation_publication_date" >{{ end }}
{{ end }}

{{ define "javascript" }}
Expand Down Expand Up @@ -132,9 +133,14 @@ <h5 class="card-title">Abstract</h5>
<dd class="acl-button-row">
{{ if (fileExists (printf "/data-export/%s" $bibfile)) }}
<a class="btn btn-secondary btn-sm" href="{{ $bibfile | relURL }}">BibTeX</a>

<button type="button" class="btn btn-clipboard btn-secondary btn-sm d-none" data-clipboard-text="{{ readFile (printf "/data-export/%s" $bibfile) | safeHTMLAttr }}"><i class="far fa-clipboard pr-2"></i>Copy BibTeX to Clipboard</button>
{{ end }}
{{ end }}
{{ $expfile := printf "/papers/%s/%s/%s.xml" (slicestr $volume_id 0 1) $volume_id $anthology_id }}
{{ if (fileExists (printf "/data-export/%s" $expfile)) }}
<a class="btn btn-secondary btn-sm" href="{{ $expfile | relURL }}">MODS XML</a>
{{ end }}
{{ if (fileExists (printf "/data-export/%s" $bibfile)) }}
<button type="button" class="btn btn-clipboard btn-secondary btn-sm d-none" data-clipboard-text="{{ readFile (printf "/data-export/%s" $bibfile) }}"><i class="far fa-clipboard pr-2"></i>Copy BibTeX to Clipboard</button>
{{ end }}
</dd>

{{ range $paper.attachment }}
Expand Down
4 changes: 4 additions & 0 deletions hugo/layouts/volumes/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ <h2 id="title">
{{ if (fileExists (printf "/data-export/%s" $bibfile)) }}
<a class="btn btn-secondary btn-sm" href="{{ $bibfile | relURL }}">BibTeX</a>
{{ end }}
{{ $expfile := printf "/volumes/%s.xml" $volume_id }}
{{ if (fileExists (printf "/data-export/%s" $expfile)) }}
<a class="btn btn-secondary btn-sm" href="{{ $expfile | relURL }}">MODS XML</a>
{{ end }}
</dd>
</dl>
</div>
Expand Down

0 comments on commit 4cbe908

Please sign in to comment.