Bibliography management in Hugo
The content of this website is generated from a set of Markdown files using Hugo. To manage citations in blog posts, the simplest option is to manually add footnotes, links, etc., which is a pain.
I have implemented a set of shortcodes to manage citations of papers in my blog posts.
These started off as a copy of the shortcodes implemented in the ‘third hemisphere’ Hugo theme1, but have now been extensively modified to suit my needs.
The code
You can view the code at the Git repository associated with this website, under the folder layouts/partials/cite
.
A small wrapper to allow the use of the cite function in markdown files is at shortcodes/cite.html
.
Automatic printing of the bibliography is done thorough a line at the end of layouts/_default/single.html
.
Creating a bibliography file
If you have your references in a bibtex file, you can generate the required CSL-JSON file by running
pandoc refs.bib -t csljson -o global_refs.json
Copy this JSON file to the assets
folder of your website.
Usage
In the preamble (TOML format) of your blog post, add
[params]
bib = "global_refs.json"
You can then cite references by using the following shortcodes (corresponding biblatex macros are given on the left):
\textcite: {{< cite t CITE_KEY >}}
\parencite: {{< cite p CITE_KEY >}}
\cite (\citealp in natbib): {{< cite alp CITE_KEY >}}
\fullcite: {{< cite f CITE_KEY >}}
Entries cited in this way (except for fullcite) will be added to the bibliography automatically). The bibliography is implemented as a partial which can be included in the HTML templates using
{{ partial "bibliography.html" . }}
Examples
- Here is a text citation: Käpylä (2019).
- And here is the same citation in brackets: (Käpylä 2019).
- Let us also cite Leibacher and Stein (1981) and Christensen-Dalsgaard (2002).
- For the sake of completeness,
alp
looks like this: Käpylä 2019. - Here is another work by Käpylä: Käpylä (2019_1). Note how a suffix has been added to the year to distinguish it from another (previously cited) study by the same author in the same year (Käpylä 2019).
All these entries will appear in the bibliography.
Here is a full citation which will not be added to the bibliography: Moffatt (1978). Magnetic Field Generation in Electrically Conducting Fluids. Cambridge University Press.
Bibliography
- Christensen-Dalsgaard (2002). Helioseismology. Rev. Mod. Phys., 74, 1073–1129. doi: 10.1103/RevModPhys.74.1073.
- Käpylä (2019_1). Effects of small-scale dynamo and compressibility on the \Lambda effect. Astronomische Nachrichten, 340(8), 744–751. doi: 10.1002/asna.201913632.
- Leibacher and Stein (1981). Oscillations and pulsations. In: The Sun as a Star. Ed. by Jordan (NASA Goddard Space Flight Center). https://ntrs.nasa.gov/citations/19810018479.
- Käpylä (2019). Magnetic and rotational quenching of the \Lambda effect. A&A, 622, A195. doi: 10.1051/0004-6361/201732519.