Skip to content

Commit

Permalink
Display inst/AUTHORS info in authors.html (#2506)
Browse files Browse the repository at this point in the history
Fixes #2332.
  • Loading branch information
hadley authored May 4, 2024
1 parent c56da52 commit a3d8e3e
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 29 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pkgdown (development version)

* `build_home()` now includes the contents of `inst/AUTHORS` on the authors page (#2506).
* If you put a dropdown menu (e.g. articles) on the right hand side of the navbar, it will now be right aligned. This makes longer titles more likely to stay on the page (#2421).
* The title for the "Reference" page is now "Package index" since this page might contain more than just function details (#2181).
* `build_redirects()` now automatically adds redirects for topic
Expand Down
22 changes: 9 additions & 13 deletions R/build-home-authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ data_authors <- function(pkg = ".", roles = default_roles()) {
pkg <- as_pkgdown(pkg)
author_info <- pkg$meta$authors %||% list()

inst_path <- path(pkg$src_path, "inst", "AUTHORS")
if (file_exists(inst_path)) {
inst <- read_lines(inst_path)
} else {
inst <- NULL
}

all <- pkg %>%
pkg_authors() %>%
purrr::map(author_list, author_info, pkg = pkg)
Expand All @@ -22,7 +29,8 @@ data_authors <- function(pkg = ".", roles = default_roles()) {
print_yaml(list(
all = all,
main = main,
needs_page = more_authors || comments
inst = inst,
needs_page = more_authors || comments || !is.null(inst)
))
}

Expand Down Expand Up @@ -72,18 +80,6 @@ data_home_sidebar_authors <- function(pkg = ".") {
sidebar_section(tr_("Developers"), bullets)
}

data_authors_page <- function(pkg) {
data <- list(
pagetitle = tr_("Authors"),
authors = data_authors(pkg)$all
)

data$before <- markdown_text_block(pkg$meta$authors$before)
data$after <- markdown_text_block(pkg$meta$authors$after)

return(data)
}

author_name <- function(x, authors, pkg) {
name <- format_author_name(x$given, x$family)

Expand Down
5 changes: 3 additions & 2 deletions R/build-home-citation.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ build_citation_authors <- function(pkg = ".") {
repo_source(pkg, "DESCRIPTION")
}

authors <- data_authors(pkg)
data <- list(
pagetitle = tr_("Authors and Citation"),
citationtitle = tr_("Citation"),
citations = data_citations(pkg),
authors = unname(data_authors(pkg)$all),
authors = unname(authors$all),
inst = authors$inst,
source = source
)

Expand Down
3 changes: 2 additions & 1 deletion R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ data_template <- function(pkg = ".", depth = 0L) {
authors = tr_("Authors"),
version = tr_("Version"),
examples = tr_("Examples"),
citation = tr_("Citation")
citation = tr_("Citation"),
author_details = tr_("Additional details")
)

# Components that mostly end up in the <head>
Expand Down
2 changes: 1 addition & 1 deletion inst/BS3/templates/content-citation-authors.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1>{{pagetitle}}</h1>
</div>
<div class="section level2 citation-section">
<div>
<h1 id="citation">{{citationtitle}}</h1>
<h1 id="citation">{{#translate}}{{citation}}{{/translate}}</h1>
{{#source}}<small class="dont-index">{{{.}}}</small>{{/source}}
</div>
</div>
Expand Down
11 changes: 9 additions & 2 deletions inst/BS5/templates/content-citation-authors.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h1>{{{pagetitle}}}</h1>
</div>

<div class="section level2 citation">
<div class="section level2">
<h2>{{#translate}}{{authors}}{{/translate}}</h2>
{{{before}}}
<ul class="list-unstyled">
Expand All @@ -19,7 +19,7 @@ <h2>{{#translate}}{{authors}}{{/translate}}</h2>
{{{after}}}
</div>

<div class="section level2 citation">
<div class="section level2">
<h2 id="citation">{{#translate}}{{citation}}{{/translate}}</h2>
<p>{{#source}}<small class="dont-index">{{{.}}}</small>{{/source}}</p>

Expand All @@ -28,6 +28,13 @@ <h2 id="citation">{{#translate}}{{citation}}{{/translate}}</h2>
<pre>{{{bibtex}}}</pre>
{{/citations}}
</div>

{{#inst}}
<div class="section level2">
<h2>{{#translate}}{{author_details}}{{/translate}}</h2>
<pre>{{.}}</pre>
</div>
{{/inst}}
</main>

<aside class="col-md-3">
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/_snaps/render.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
version: Version
examples: Examples
citation: Citation
author_details: Additional details
has_favicons: no
opengraph: []
extra:
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/assets/inst-authors/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Package: testpackage
Version: 1.0.0
Title: A test package
Description: A test package
Authors@R: c(
person("Hadley", "Wickham", , "[email protected]", role = c("aut", "cre")),
person("RStudio", role = c("cph", "fnd"))
)
2 changes: 2 additions & 0 deletions tests/testthat/assets/inst-authors/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
template:
bootstrap: 5
1 change: 1 addition & 0 deletions tests/testthat/assets/inst-authors/inst/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello
6 changes: 5 additions & 1 deletion tests/testthat/test-build-footer.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
test_that("works by default", {
pkg <- structure(
list(
desc = desc::desc(text = "Authors@R: person('First', 'Last', role = 'cre')")
desc = desc::desc(text = "Authors@R: person('First', 'Last', role = 'cre')"),
src_path = tempdir()
),
class = "pkgdown"
)
Expand All @@ -16,6 +17,7 @@ test_that("includes package component", {
list(
package = "noodlr",
desc = desc::desc(text = "Authors@R: person('First', 'Last', role = 'cre')"),
src_path = tempdir(),
meta = list(
footer = list(
structure = list(left = "package")
Expand All @@ -30,6 +32,7 @@ test_that("includes package component", {
test_that("can use custom components", {
pkg <- structure(list(
desc = desc::desc(text = "Authors@R: person('a', 'b', roles = 'cre')"),
src_path = tempdir(),
meta = list(
footer = list(
structure = list(left = "test"),
Expand All @@ -44,6 +47,7 @@ test_that("can use custom components", {
test_that("multiple components are pasted together", {
pkg <- structure(list(
desc = desc::desc(text = "Authors@R: person('a', 'b', roles = 'cre')"),
src_path = tempdir(),
meta = list(
footer = list(
structure = list(left = c("a", "b")),
Expand Down
12 changes: 3 additions & 9 deletions tests/testthat/test-build-home-authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,9 @@ test_that("Data authors can accept different filtering", {
expect_length(data_authors(pkg, roles = "cre")$main, 1)
})

test_that("Text can be added", {
pkg <- as_pkgdown(test_path("assets/sidebar-comment"))
expect_null(data_authors_page(pkg)$after)
expect_null(data_authors_page(pkg)$before)

pkg$meta$authors$before <- "Dream team:"
pkg$meta$authors$after <- "You are welcome!"
expect_equal(data_authors_page(pkg)$before, "<p>Dream team:</p>")
expect_equal(data_authors_page(pkg)$after, "<p>You are welcome!</p>")
test_that("authors data includes inst/AUTHORS", {
pkg <- as_pkgdown(test_path("assets/inst-authors"))
expect_equal(data_authors(pkg)$inst, "Hello")
})

test_that("data_home_sidebar_authors() works with text", {
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-build-home-citation.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ test_that("source link is added to citation page", {
expect_true(any(grepl("<code>inst/CITATION</code></a></small>", lines)))
})

test_that("citation page includes inst/AUTHORS", {
pkg <- local_pkgdown_site(test_path("assets/inst-authors"))
suppressMessages(init_site(pkg))
suppressMessages(build_citation_authors(pkg))

lines <- read_lines(path(pkg$dst_path, "authors.html"))
expect_true(any(grepl("<pre>Hello</pre>", lines)))
})

test_that("multiple citations all have HTML and BibTeX formats", {
citations <- data_citations(test_path("assets/site-citation/multi"))
expect_snapshot_output(citations)
Expand All @@ -45,3 +54,4 @@ test_that("links in curly braces in authors comments are escaped", {
"reviewed see &lt;<a href='https://github.com/r-lib/pkgdown/pulls'>https://github.com/r-lib/pkgdown/pulls</a>&gt;"
)
})

0 comments on commit a3d8e3e

Please sign in to comment.