From 4c64a0680f432fab336409211b409b2b3817b076 Mon Sep 17 00:00:00 2001 From: Lars Bilke <lars.bilke@ufz.de> Date: Wed, 26 Jul 2017 13:47:11 +0200 Subject: [PATCH] [web] Added bib-shortcode for inserting references. Requires pandoc-citeproc tool. --- scripts/cmake/Find.cmake | 1 + scripts/cmake/Web.cmake | 9 ++++++- web/.gitignore | 5 +++- web/README.md | 13 ++++++++++ .../thermo-mechanics/thermomechanics.md | 4 ++- web/layouts/shortcodes/bib.html | 26 +++++++++++++++++++ 6 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 web/layouts/shortcodes/bib.html diff --git a/scripts/cmake/Find.cmake b/scripts/cmake/Find.cmake index f4451e61a7a..66e5e468ee1 100644 --- a/scripts/cmake/Find.cmake +++ b/scripts/cmake/Find.cmake @@ -52,6 +52,7 @@ find_program(NPM npm) find_program(YARN yarn) find_program(PIP pip) find_package(PythonInterp) +find_program(PANDOC_CITEPROC pandoc-citeproc) find_program(MODULE_CMD modulecmd PATHS /usr/local/modules/3.2.10-1/Modules/3.2.10/bin) diff --git a/scripts/cmake/Web.cmake b/scripts/cmake/Web.cmake index 1a948528eee..18e1b7879b6 100644 --- a/scripts/cmake/Web.cmake +++ b/scripts/cmake/Web.cmake @@ -30,6 +30,13 @@ else() message(STATUS "[web] Skipping import from Contentful!") endif() +if(PANDOC_CITEPROC) + add_custom_target(web-bib-convert + COMMAND ${PANDOC_CITEPROC} --bib2json ${PROJECT_SOURCE_DIR}/Documentation/bibliography.bib > ${PROJECT_SOURCE_DIR}/web/data/bibliography.json + ) + set(BIB_CONVERT_TARGET web-bib-convert) +endif() + if(DEFINED OGS_WEB_BASE_URL) set(HUGO_ARGS --baseURL ${OGS_WEB_BASE_URL}) endif() @@ -41,7 +48,7 @@ endif() add_custom_target(web COMMAND ${NPM} run build:release -- ${HUGO_ARGS} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/web - DEPENDS web-install ${IMPORT_TARGET} + DEPENDS web-install ${IMPORT_TARGET} ${BIB_CONVERT_TARGET} ) add_custom_target(web-clean diff --git a/web/.gitignore b/web/.gitignore index 8381a342560..7e1d49138da 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -12,5 +12,8 @@ yarn-error.log # Generated from Contentful content/internal -data/news.json +data/bibliography.json import/c + +# Generated by other tools +data/news.json diff --git a/web/README.md b/web/README.md index 7c985c3ebbf..2fa4e69e0f3 100644 --- a/web/README.md +++ b/web/README.md @@ -131,6 +131,19 @@ Run `npm run convert` to get a list of possible arguments. Equations can be set with typical LaTeX syntax by using [MathJax](https://www.mathjax.org/). Blocks are defined by `$$` at the beginning and `$$` at the end of the block. Inline math uses one `$` as the delimiter. For more usage instructions see the [MathJax LaTeX help](http://docs.mathjax.org/en/latest/tex.html). +### Bibliography references + +Bibliography items from *Documentation/bibliography.bib* can be referenced by +their id with the `bib`-shortcode: + +```go +{{< bib id="Kolditz2012" >}} +``` + +When building the `web`-target the file *Documentation/bibliography.bib* is +converted to *web/data/bibliography.json* with the tool `pandoc-citeproc`. This +json-file is then used by the shortcode. + ## Developer notes When adding a new module with `yarn add` you have to manually rebuild node-sass: diff --git a/web/content/docs/benchmarks/thermo-mechanics/thermomechanics.md b/web/content/docs/benchmarks/thermo-mechanics/thermomechanics.md index 3f88c19281b..ceb08d282d8 100644 --- a/web/content/docs/benchmarks/thermo-mechanics/thermomechanics.md +++ b/web/content/docs/benchmarks/thermo-mechanics/thermomechanics.md @@ -33,4 +33,6 @@ $$ The relative error between the numerical simulation and the analytical solution is $9.2 \cdot 10^{-13}$. -Kolditz, Olaf, Uwe-Jens Görke, Hua Shao, and Wenqing Wang, eds. Thermo-hydro-mechanical-chemical processes in porous media: benchmarks and examples. Vol. 86. Springer Science & Business Media, 2012. +## References + +{{< bib id="Kolditz2012" >}} diff --git a/web/layouts/shortcodes/bib.html b/web/layouts/shortcodes/bib.html new file mode 100644 index 00000000000..74abe7e84c2 --- /dev/null +++ b/web/layouts/shortcodes/bib.html @@ -0,0 +1,26 @@ +{{ if .Site.Data.bibliography }} + <p> + {{ $id := .Get "id" }} + {{ range where .Site.Data.bibliography "id" $id }} + {{ range .author }} + {{ .family }}, {{ .given}} + {{ end }} + ({{ range .issued }} + {{ range . }} + {{ range . }} + {{.}} + {{ end }} + {{ end }} + {{ end }}): + <i>{{ .title }}</i>. + <!-- Workaround for keys with hyphens inside with index-function --> + {{ if isset . "container-title" }}{{ index . "container-title" }}{{ end }} + {{ if isset . "issue" }}{{ .issue }},{{ end }} + {{ if isset . "volume" }}vol. {{ .volume }},{{ end }} + {{ if isset . "page" }}p. {{ .page }},{{ end }} + {{ .publisher }} + {{ end }} + </p> +{{ else }} + {{ printf "Warning: Bibliography not converted! Missing bib id: "}}<code>{{.Get "id"}}</code> +{{ end }} -- GitLab