From ffa71fbf3d09b5a2424c40d3095aed9d814ecf50 Mon Sep 17 00:00:00 2001 From: Toby Hodges Date: Mon, 30 Oct 2023 11:29:34 +0100 Subject: [PATCH 1/2] accept doi field in lesson config --- R/utils-yaml.R | 12 +++++++----- inst/templates/pkgdown-yaml-template.txt | 6 ++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/R/utils-yaml.R b/R/utils-yaml.R index e7cfcac0c..2576f0934 100644 --- a/R/utils-yaml.R +++ b/R/utils-yaml.R @@ -180,10 +180,13 @@ 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", + # Should we display DOI info? + doi = siQuote(usr$doi), NULL ) ) @@ -236,4 +239,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 }} From a8579c78349522cb6fbd484c02d16325d1d34bcc Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Fri, 10 Nov 2023 10:47:02 -0800 Subject: [PATCH 2/2] allow for empty or missing DOI; bump news --- NEWS.md | 4 ++++ R/utils-yaml.R | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3b738b820..8e634a54d 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 8cc00333f..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 @@ -187,8 +191,7 @@ create_pkgdown_yaml <- function(path) { alpha = usr$life_cycle == "alpha", beta = usr$life_cycle == "beta", stable = usr$life_cycle == "stable", - # Should we display DOI info? - doi = siQuote(usr$doi), + doi = doi, NULL ) )