Skip to content

Commit

Permalink
close #59: link url and orcid for authors in DESCRIPTION (#62)
Browse files Browse the repository at this point in the history
Co-authored-by: Yihui Xie <[email protected]>
  • Loading branch information
TimTaylor and yihui authored Dec 16, 2024
1 parent c78675d commit cc34de8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
35 changes: 27 additions & 8 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,11 @@ pkg_desc = function(name = detect_pkg()) {
names(d) = fields
# remove single quotes on words (which are unnecessary IMO)
for (i in c('Title', 'Description')) d[[i]] = sans_sq(d[[i]])
# format authors
if (is.na(d[['Author']])) d$Author = one_string(by = ',', format(
eval(xfun::parse_only(d[['Authors@R']])), include = c('given', 'family', 'role')
))
d[['Author']] = pkg_authors(d)
d[['Authors@R']] = NULL
# convert URLs to <a>, and escape HTML in other fields
for (i in names(d)) d[[i]] = if (!is.na(d[[i]])) {
if (i %in% c('URL', 'BugReports')) {
if (i %in% c('Description', 'URL', 'BugReports', 'Author')) {
sans_p(commonmark::markdown_html(d[[i]], extensions = 'autolink'))
} else xfun::html_escape(d[[i]])
}
Expand All @@ -152,7 +149,28 @@ pkg_desc = function(name = detect_pkg()) {
paste0('\n<td>', d, '</td>'), '\n</tr>', collapse = '\n'
), '\n</tbody></table>'
)
new_asis(res)
new_asis(c(pkg_style(), res))
}

# format authors, adding URL and ORCID links as appropriate
pkg_authors = function(desc, role = NULL) {
if (is.null(a <- desc[['Authors@R']])) return(desc[['Author']])
a = eval(xfun::parse_only(a))
a = uapply(a, function(x) {
role = if (length(x$role)) {
if (length(role) == 0 || role %in% x$role) paste0('[', one_string(x$role, ', '), ']')
}
name = paste(x$given, x$family)
comment = as.list(x$comment)
orcid = sprintf(
'[![ORCID iD](https://cloud.r-project.org/web/orcid.svg){.orcid}](https://orcid.org/%s)',
comment[["ORCID"]]
)
link = comment[['URL']]
if (length(link)) name = sprintf('[%s](%s)', name, link)
one_string(c(name, orcid, role), ' ')
})
a
}

#' @param path For [pkg_news()], path to the `NEWS.md` file. If empty, [news()]
Expand Down Expand Up @@ -354,10 +372,11 @@ pkg_manual = function(
res = gsub('<code class="language-R"', '<code class="language-r"', res, fixed = TRUE)
res = gsub('&#8288;', '', res, fixed = TRUE)
res = gsub('<table>', '<table class="table-full">', res, fixed = TRUE)
style = gen_tag(jsd_resolve(jsdelivr('css/manual.min.css')))
new_asis(c(style, toc, res))
new_asis(c(pkg_style(), toc, res))
}

pkg_style = function() gen_tag(jsd_resolve(jsdelivr('css/manual.min.css')))

run_examples = function(html, config, path) {
config$dev.path = path = paste0(config$dev.path, path)
on.exit(xfun::del_empty_dir(dirname(path)), add = TRUE)
Expand Down
9 changes: 1 addition & 8 deletions site/_footer.Rmd
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
```{r, include = FALSE}
get_authors = function() {
d = packageDescription(litedown:::detect_pkg())
if (is.null(a <- d[['Authors@R']])) return(d[['Author']])
a = Filter(function(x) 'aut' %in% x$role, eval(xfun::parse_only(a)))
a = unlist(lapply(a, function(x) {
name = paste(x$given, x$family)
link = as.list(x$comment)[['URL']]
if (length(link) != 1) return(name)
sprintf('[%s](%s)', name, link)
}))
a = litedown:::pkg_authors(d, 'aut')
xfun::join_words(a)
}
```
Expand Down

0 comments on commit cc34de8

Please sign in to comment.