diff --git a/NEWS.md b/NEWS.md index f4badc085..e3146bb3d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,10 @@ appended. Note that when clicking these links, the user will remain in instructor view. This behaviour may change in future iterations (reported: @karenword, #394; fixed: @ErinBecker, #530, reviewed: @zkamvar) +* DOI badges can now be displayed when paired with {varnish} version 0.4.0 by + adding the `doi:` key to the `config.yaml` file with either the raw DOI or + the URL to the DOI (reported: @tobyhodges, carpentries/workbench#67; + fixed: @tobyhodges, #535). ## BUG FIX diff --git a/R/utils-yaml.R b/R/utils-yaml.R index fd30342e9..97a0ff658 100644 --- a/R/utils-yaml.R +++ b/R/utils-yaml.R @@ -161,6 +161,10 @@ create_pkgdown_yaml <- function(path) { handout <- if (is.null(usr$handout)) "~" else usr$handout handout <- if (isTRUE(handout)) "files/code-handout.R" else handout yaml <- get_yaml_text(template_pkgdown()) + # Should we display DOI info? If so, parse the URL and return the doi + # note that a missing doi will return nothing + doi <- sub("^[/]", "", xml2::url_parse(usr$doi)$path) + doi <- if (length(doi) == 1L && nzchar(doi)) siQuote(doi) else "~" yaml <- whisker::whisker.render(yaml, data = list( # Basic information @@ -182,10 +186,12 @@ create_pkgdown_yaml <- function(path) { dc = usr$carpentry == 'dc', swc = usr$carpentry == 'swc', # Should we display a lifecycle banner? - life_cycle = if (usr$life_cycle == "stable") "~" else siQuote(usr$life_cycle), - pre_alpha = if (usr$life_cycle == "pre-alpha") TRUE else "~", - alpha = if (usr$life_cycle == "alpha") TRUE else "~", - beta = if (usr$life_cycle == "beta") TRUE else "~", + life_cycle = siQuote(usr$life_cycle), + pre_alpha = usr$life_cycle == "pre-alpha", + alpha = usr$life_cycle == "alpha", + beta = usr$life_cycle == "beta", + stable = usr$life_cycle == "stable", + doi = doi, NULL ) ) @@ -238,4 +244,3 @@ quote_config_items <- function(yaml) { } yaml } - diff --git a/inst/templates/pkgdown-yaml-template.txt b/inst/templates/pkgdown-yaml-template.txt index dfaaf8bcc..e436b4774 100644 --- a/inst/templates/pkgdown-yaml-template.txt +++ b/inst/templates/pkgdown-yaml-template.txt @@ -1,7 +1,7 @@ -# ------------------------------------------------------------------ information +# ------------------------------------------------------------------ information # This file was generated by sandpaper version {{ version }} # If you want to make changes, please edit {{ config }} -# ------------------------------------------------------------------ information +# ------------------------------------------------------------------ information title: {{ title }} # needed to set the site title home: title: Home @@ -27,3 +27,5 @@ template: pre_alpha: {{ pre_alpha }} alpha: {{ alpha }} beta: {{ beta }} + stable: {{ stable }} + doi: {{ doi }}