Skip to content

Commit

Permalink
Merge branch 'main' into tan/quarto-gha/2743
Browse files Browse the repository at this point in the history
  • Loading branch information
tanho63 authored Aug 16, 2024
2 parents eaba0e7 + 1a6c8b7 commit d4be243
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# pkgdown (development version)

* The `BugReports` field can now be an email (@catalamarti, #2275).

* New `clean_cache()` function removes the contents of the cache directory (#2718).

* pkgdown now depends on R >= 4.0.0 (#2714)
* Updated GitHub Actions advice and workflows around Quarto install (@tanho63, #2743)

Expand Down
15 changes: 10 additions & 5 deletions R/build-home-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ data_home_sidebar <- function(pkg = ".", call = caller_env()) {
"home.sidebar.structure",
default = default_sidebar_structure(),
call = call
)
)

# compute all default sections
default_components <- list(
Expand All @@ -122,7 +122,7 @@ data_home_sidebar <- function(pkg = ".", call = caller_env()) {
)

needs_components <- setdiff(structure, names(default_components))
custom_yaml <- config_pluck_sidebar_components(pkg, needs_components, call = call)
custom_yaml <- config_pluck_sidebar_components(pkg, needs_components, call = call)
custom_components <- purrr::map(custom_yaml, function(x) {
sidebar_section(x$title, markdown_text_block(pkg, x$text))
})
Expand All @@ -140,11 +140,11 @@ default_sidebar_structure <- function() {
config_pluck_sidebar_components <- function(pkg, new_components, call = caller_env()) {
base_path <- "home.sidebar.components"
components <- config_pluck_list(pkg, base_path, has_names = new_components, call = call)

for (name in names(components)) {
component <- components[[name]]
component_path <- paste0(base_path, ".", name)

config_pluck_list(pkg, component_path, has_names = c("title", "text"), call = call)
config_pluck_string(pkg, paste0(component_path, ".title"), call = call)
config_pluck_string(pkg, paste0(component_path, ".text"), call = call)
Expand All @@ -158,10 +158,15 @@ data_home_sidebar_links <- function(pkg = ".") {
repo <- cran_link(pkg$package)
links <- config_pluck(pkg, "home.links")

bug_reports <- pkg$desc$get_field("BugReports", default = NULL)
if (grepl("@", bug_reports) && !startsWith(bug_reports, "http")) {
bug_reports <- paste0("mailto:", bug_reports)
}

links <- c(
link_url(sprintf(tr_("View on %s"), repo$repo), repo$url),
link_url(tr_("Browse source code"), repo_home(pkg)),
link_url(tr_("Report a bug"), pkg$desc$get_field("BugReports", default = NULL)),
link_url(tr_("Report a bug"), bug_reports),
purrr::map_chr(links, ~ link_url(.$text, .$href))
)

Expand Down
3 changes: 1 addition & 2 deletions R/build-news.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ data_news <- function(pkg, call = caller_env() ) {
} else {
timeline <- NULL
}

purrr::walk2(
sections,
versions,
Expand Down Expand Up @@ -284,7 +284,6 @@ pkg_timeline <- function(package) {
data.frame(
version = names(timeline),
date = as.Date(timeline),
stringsAsFactors = FALSE,
row.names = NULL
)
}
Expand Down
3 changes: 1 addition & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ re_match <- function(text, pattern, perl = TRUE, ...) {
matchstr[ start == -1 ] <- NA_character_

res <- data.frame(
stringsAsFactors = FALSE,
.text = text,
.match = matchstr
)
Expand All @@ -124,7 +123,7 @@ re_match <- function(text, pattern, perl = TRUE, ...) {
groupstr[ gstart == -1 ] <- NA_character_
dim(groupstr) <- dim(gstart)

res <- cbind(groupstr, res, stringsAsFactors = FALSE)
res <- cbind(groupstr, res)
}

names(res) <- c(attr(match, "capture.names"), ".text", ".match")
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/build-home-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,11 @@
! In _pkgdown.yml, home.sidebar.components.fancy must have components "title" and "text".
2 missing components: "title" and "text".

# allow email in BugReports

Code
xpath_xml(html, ".//li/a")
Output
<a href="mailto:[email protected]">Report a bug</a>
<a href="authors.html#citation">Citing testpackage</a>

9 changes: 8 additions & 1 deletion tests/testthat/test-build-home-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test_that("math is handled", {
expect_equal(xpath_length(html, ".//math"), 1)
})

test_that("data_home() validates yaml metadata", {
test_that("data_home() validates yaml metadata", {
data_home_ <- function(...) {
pkg <- local_pkgdown_site(meta = list(...))
data_home(pkg)
Expand Down Expand Up @@ -153,3 +153,10 @@ test_that("cran_unquote works", {
"Quoting is CRAN's thing."
)
})

test_that("allow email in BugReports", {
# currently desc throws a warning if BugReports is an email
pkg <- local_pkgdown_site(desc = list(BugReports = "[email protected]"))
html <- xml2::read_html(data_home_sidebar(pkg))
expect_snapshot(xpath_xml(html, ".//li/a"))
})
7 changes: 3 additions & 4 deletions tests/testthat/test-build-news.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ test_that("news is syntax highlighted once", {
pkg <- local_pkgdown_site()
pkg <- pkg_add_file(pkg, "NEWS.md", c(
"# testpackage 1.0.0.9000",
"```r",
"x <- 1",
"```r",
"x <- 1",
"```"
))
suppressMessages(build_news(pkg, preview = FALSE))
Expand Down Expand Up @@ -117,8 +117,7 @@ test_that("correct timeline for first ggplot2 releases", {
timeline <- pkg_timeline("ggplot2")[1:3, ]
expected <- data.frame(
version = c("0.5", "0.5.1", "0.5.2"),
date = as.Date(c("2007-06-01", "2007-06-09", "2007-06-18")),
stringsAsFactors = FALSE
date = as.Date(c("2007-06-01", "2007-06-09", "2007-06-18"))
)

expect_equal(timeline, expected)
Expand Down

0 comments on commit d4be243

Please sign in to comment.