Skip to content

Commit

Permalink
feat: add support for ROR IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Feb 4, 2025
1 parent e23c4d1 commit 35e4f4b
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ Config/testthat/parallel: true
Config/testthat/start-first: build-article, build-quarto-article, build-reference
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.2.9000
SystemRequirements: pandoc
31 changes: 28 additions & 3 deletions R/build-home-authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ data_home_sidebar_authors <- function(pkg = ".", call = caller_env()) {
)
data <- data_authors(pkg, roles)
authors <- purrr::map_chr(data$main, author_desc, comment = FALSE)

before <- config_pluck_markdown_inline(pkg, "authors.sidebar.before", call = call)
after <- config_pluck_markdown_inline(pkg, "authors.sidebar.after", call = call)

bullets <- c(before, authors, after)
if (data$needs_page) {
bullets <- c(bullets, a(tr_("More about authors..."), "authors.html"))
Expand Down Expand Up @@ -136,11 +136,15 @@ author_list <- function(x, authors_info = NULL, comment = FALSE, pkg = ".") {
orcid <- purrr::pluck(x$comment, "ORCID")
x$comment <- remove_orcid(x$comment)

ror <- purrr::pluck(x$comment, "ROR")
x$comment <- remove_ror(x$comment)

list(
name = name,
roles = roles,
comment = linkify(x$comment),
orcid = orcid_link(orcid)
# can't have both ORCID and ROR
uniqueid = orcid_link(orcid) %||% ror_link(ror)
)
}

Expand All @@ -151,6 +155,9 @@ author_desc <- function(x, comment = TRUE) {
if (!is.null(x$orcid)) {
x$orcid
},
if (!is.null(x$ror)) {
x$ror
},
if (comment && !is.null(x$comment) && length(x$comment) != 0) {
paste0("<br/>\n<small>(", linkify(x$comment), ")</small>")
}
Expand All @@ -168,6 +175,17 @@ orcid_link <- function(orcid) {
)
}

ror_link <- function(ror) {
if (is.null(ror)) {
return(NULL)
}

paste0(
"<a href='https://ror.org/", ror, "'>",
"<img src='https://raw.githubusercontent.com/ror-community/ror-logos/main/ror-icon-rgb.svg' class='ror' alt='ROR'></a>"
)
}

# Derived from:
# db <- utils:::MARC_relator_db
# db <- db[db$usage != "",]
Expand Down Expand Up @@ -300,3 +318,10 @@ remove_orcid <- function(x) {
}
out
}
remove_ror <- function(x) {
out <- x[names2(x) != "ROR"]
if (all(names(out) == "")) {
names(out) <- NULL
}
out
}
9 changes: 6 additions & 3 deletions R/build-home.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@
#' See `?build_home` and `?build_site` for details about changing the location
#' of the authors information within the home sidebar and the site footer.
#'
#' ## Authors ORCID and bio
#' ## Authors ORCID, ROR and bio
#'
#' Author ORCID identification numbers in the `DESCRIPTION` are linked using
#' the ORCID logo:
#' the ORCID logo,
#' author ROR identification numbers are linked using the ROR logo:
#'
#' ```r
#' Authors@R: c(
Expand All @@ -131,7 +132,9 @@
#' ),
#' person("Jay", "Hesselberth", role = "aut",
#' comment = c(ORCID = "0000-0002-6299-179X")
#' )
#' ),
#' person("Posit Software, PBC", role = c("cph", "fnd"),
#' comment = c(ROR = "03wc8by49"))
#' )
#' ```
#'
Expand Down
13 changes: 9 additions & 4 deletions inst/BS5/assets/pkgdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $pkgdown-navbar-bg-dark: if($navbar-dark-bg, $navbar-dark-bg, null) !default;
}

// make both the active nav and the hovered nav more clear by mixing the
// background colour with the body and primary colours respectively
// background colour with the body and primary colours respectively
.nav-item .nav-link {
@include border-radius($border-radius);
}
Expand Down Expand Up @@ -312,6 +312,11 @@ dt:target + dd {
color: #A6CE39;
margin-right: 4px;
}
// ror badge
.ror {
height: 16px;
margin-right: 4px;
}
// activate font awesome
.fab {
font-family: "Font Awesome 5 Brands" !important;
Expand Down Expand Up @@ -372,7 +377,7 @@ a[href='#main'] {
}
.lifecycle-stable { background-color: rgb(16, 128, 1); color: var(--bs-white);}
.lifecycle-superseded { background-color: rgb(7, 64, 128); color: var(--bs-white);}
.lifecycle-experimental,
.lifecycle-experimental,
.lifecycle-deprecated { background-color: rgb(253, 128, 8); color: var(--bs-black);}

/* Footnotes ---------------------------------------------------------------- */
Expand Down Expand Up @@ -452,7 +457,7 @@ pre, pre code {
// Default dark mode styling does not look good for code
[data-bs-theme="dark"] {
pre, code {
background-color: RGBA(var(--bs-body-color-rgb), 0.1);
background-color: RGBA(var(--bs-body-color-rgb), 0.1);
}
// don't double apply transparency
pre code {
Expand Down Expand Up @@ -594,7 +599,7 @@ span.smallcaps {font-variant: small-caps;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}

Expand Down
2 changes: 1 addition & 1 deletion inst/BS5/templates/content-authors.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1>{{{pagetitle}}}</h1>
<ul class="list-unstyled">
{{#authors}}
<li>
<p><strong>{{{name}}}</strong>. {{{roles}}}. {{{orcid}}}
<p><strong>{{{name}}}</strong>. {{{roles}}}. {{{uniqueid}}}
{{#comment}}<br /><small>{{{.}}}</small>{{/comment}}</p>
</li>
{{/authors}}
Expand Down
2 changes: 1 addition & 1 deletion inst/BS5/templates/content-citation-authors.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2>{{#translate}}{{authors}}{{/translate}}</h2>
<ul class="list-unstyled">
{{#authors}}
<li>
<p><strong>{{{name}}}</strong>. {{{roles}}}. {{{orcid}}}
<p><strong>{{{name}}}</strong>. {{{roles}}}. {{{uniqueid}}}
{{#comment}}<br /><small>{{{.}}}</small>{{/comment}}</p>
</li>
{{/authors}}
Expand Down
2 changes: 1 addition & 1 deletion man/deploy_site_github.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/deploy_to_branch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/init_site.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/pkgdown-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/test-dont.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions tests/testthat/test-build-home-authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ test_that("ORCID can be identified & removed from all comment styles", {
)
})

test_that("ROR can be identified & removed from all comment styles", {
desc <- desc::desc(text = c(
'Authors@R: c(',
' person("no comment"),',
' person("bare comment", comment = "comment"),',
' person("ror only", comment = c(ROR = "1")),',
' person("both", comment = c("comment", ROR = "2"))',
' )'
))
authors <- purrr::map(desc$get_authors(), author_list, list())
expect_equal(
purrr::map(authors, "ror"),
list(NULL, NULL, ror_link("1"), ror_link("2"))
)

expect_equal(
purrr::map(authors, "comment"),
list(character(), "comment", character(), "comment")
)
})

test_that("author comments linkified with escaped angle brackets (#2127)", {
p <- list(name = "Jane Doe", roles = "rev", comment = "<https://x.org/>")
expect_match(
Expand Down

0 comments on commit 35e4f4b

Please sign in to comment.