Skip to content

Commit

Permalink
Merge pull request #535 from tobyhodges/doi-banner
Browse files Browse the repository at this point in the history
Extend lesson YAML to enable DOI badge for peer-reviewed lessons
  • Loading branch information
zkamvar authored Nov 10, 2023
2 parents d3a7c04 + a8579c7 commit 795ea75
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 10 additions & 5 deletions R/utils-yaml.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
)
Expand Down Expand Up @@ -238,4 +244,3 @@ quote_config_items <- function(yaml) {
}
yaml
}

6 changes: 4 additions & 2 deletions inst/templates/pkgdown-yaml-template.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,3 +27,5 @@ template:
pre_alpha: {{ pre_alpha }}
alpha: {{ alpha }}
beta: {{ beta }}
stable: {{ stable }}
doi: {{ doi }}

0 comments on commit 795ea75

Please sign in to comment.