Skip to content

Commit

Permalink
Merge branch 'main' into translate-citation
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored Mar 11, 2024
2 parents 69cd6f0 + b04d5c9 commit 13e95b4
Show file tree
Hide file tree
Showing 24 changed files with 152 additions and 54 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pkgdown (development version)

* Fix parsing of github profiles and issues into links when present at the beginning of list items (@pearsonca, #2122)
* Correct parse usage for S3 methods with non-syntactic class names (#2384).

* Deprecated `build_favicon()` was removed (`build_favicons()` remains).
* Use [cli](https://github.com/r-lib/cli) to provide interactive feedback.
* Preserve Markdown code blocks with class rmd from roxygen2 docs (@salim-b, #2298).
Expand All @@ -12,6 +12,7 @@
* Set RNG seed for htmlwidgets IDs. This reduces noise in pkgdown reference HTML output when examples generate htmlwidgets (@salim-b, #2294).
* Fix BS5 navbar template to get `navbar.type: dark` to work with bslib 0.6+ / Bootstrap 5.3+ (@tanho63, #2388)
* Translates citation sections (@eliocamp, #2410).
* Topic names that conflict with selector functions can now be listed as references in `_pkgdown.yml` (@dmurdoch, #2397).

# pkgdown 2.0.7

Expand Down
3 changes: 2 additions & 1 deletion R/build-articles.R
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ data_articles_index <- function(pkg = ".") {

if (length(missing) > 0) {
cli::cli_abort(
"{length(missing)} vignette{?s} missing from index: {.file {missing}}.",
"{length(missing)} vignette{?s} missing from index in \\
{pkgdown_config_href({pkg$src_path})}: {.val {missing}}.",
call = caller_env()
)
}
Expand Down
7 changes: 2 additions & 5 deletions R/build-favicons.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) {
if (has_favicons(pkg) && !overwrite) {
cli::cli_inform(c(
"Favicons already exist in {.path pkgdown}",
"i" = "Set {.var overwrite = TRUE} to re-create."
"i" = "Set {.code overwrite = TRUE} to re-create."
))
return(invisible())
}
Expand Down Expand Up @@ -78,10 +78,7 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) {
result <- content$favicon_generation_result

if (!identical(result$result$status, "success")) {
cli::cli_abort(c(
"API request failed.",
"i" = "{.href [Please submit a bug report](https://github.com/r-lib/pkgdown/issues)}"
))
cli::cli_abort("API request failed.", .internal = TRUE)
}

tmp <- tempfile()
Expand Down
16 changes: 8 additions & 8 deletions R/build-reference-index.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
data_reference_index <- function(pkg = ".") {
data_reference_index <- function(pkg = ".", error_call = caller_env()) {
pkg <- as_pkgdown(pkg)

meta <- pkg$meta[["reference"]] %||% default_reference_index(pkg)
Expand All @@ -13,7 +13,7 @@ data_reference_index <- function(pkg = ".") {

has_icons <- purrr::some(rows, ~ .x$row_has_icons %||% FALSE)

check_missing_topics(rows, pkg)
check_missing_topics(rows, pkg, error_call = error_call)
rows <- Filter(function(x) !x$is_internal, rows)

print_yaml(list(
Expand Down Expand Up @@ -125,19 +125,19 @@ default_reference_index <- function(pkg = ".") {
))
}

check_missing_topics <- function(rows, pkg) {
check_missing_topics <- function(rows, pkg, error_call = caller_env()) {
# Cross-reference complete list of topics vs. topics found in index page
all_topics <- rows %>% purrr::map("names") %>% unlist(use.names = FALSE)
in_index <- pkg$topics$name %in% all_topics

missing <- !in_index & !pkg$topics$internal

if (any(missing)) {
topics <- paste0(pkg$topics$name[missing], collapse = ", ")
abort(c(
cli::cli_abort(c(
"All topics must be included in reference index",
`x` = paste0("Missing topics: ", topics),
i = "Either add to _pkgdown.yml or use @keywords internal"
))
"x" = "Missing topics: {pkg$topics$name[missing]}",
i = "Either add to {pkgdown_config_href({pkg$src_path})} or use @keywords internal"
),
call = error_call)
}
}
13 changes: 8 additions & 5 deletions R/build-reference.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ build_reference <- function(pkg = ".",
topics <- purrr::transpose(pkg$topics)
}

purrr::map(topics,
purrr::map(
topics,
build_reference_topic,
pkg = pkg,
lazy = lazy,
Expand Down Expand Up @@ -269,8 +270,7 @@ build_reference_topic <- function(topic,
pkg,
lazy = TRUE,
examples_env = globalenv(),
run_dont_run = FALSE
) {
run_dont_run = FALSE ) {

in_path <- path(pkg$src_path, "man", topic$file_in)
out_path <- path(pkg$dst_path, "reference", topic$file_out)
Expand All @@ -297,12 +297,14 @@ build_reference_topic <- function(topic,
if (data$has_deps) {
deps <- bs_theme_deps_suppress(deps)
deps <- htmltools::resolveDependencies(deps)
deps <- purrr::map(deps,
deps <- purrr::map(
deps,
htmltools::copyDependencyToDir,
outputDir = file.path(pkg$dst_path, "reference", "libs"),
mustWork = FALSE
)
deps <- purrr::map(deps,
deps <- purrr::map(
deps,
htmltools::makeDependencyRelative,
basepath = file.path(pkg$dst_path, "reference"),
mustWork = FALSE
Expand All @@ -326,6 +328,7 @@ data_reference_topic <- function(topic,
pkg,
examples_env = globalenv(),
run_dont_run = FALSE) {

local_context_eval(pkg$figures, pkg$src_path)
withr::local_options(list(downlit.rdname = get_rdname(topic)))

Expand Down
24 changes: 12 additions & 12 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -408,32 +408,32 @@ build_site_external <- function(pkg = ".",
timeout = getOption('pkgdown.timeout', Inf)
)

cli::cli_rule(paste0("Finished building pkgdown site for package ", cli::col_blue(pkg$package)))
cli::cli_rule("Finished building pkgdown site for package {.pkg {pkg$package}}")

preview_site(pkg, preview = preview)
invisible()
}

build_site_local <- function(pkg = ".",
examples = TRUE,
run_dont_run = FALSE,
seed = 1014,
lazy = FALSE,
override = list(),
preview = NA,
devel = TRUE
) {
examples = TRUE,
run_dont_run = FALSE,
seed = 1014,
lazy = FALSE,
override = list(),
preview = NA,
devel = TRUE) {

pkg <- section_init(pkg, depth = 0, override = override)

cli::cli_rule(paste0("Building pkgdown site for package ", cli::col_blue(pkg$package)))
cli::cli_rule("Building pkgdown site for package {.pkg {pkg$package}}")
cli::cli_inform("Reading from: {src_path(path_abs(pkg$src_path))}")
cli::cli_inform("Writing to: {dst_path(path_abs(pkg$dst_path))}")

init_site(pkg)

build_home(pkg, override = override, preview = FALSE)
build_reference(pkg,
build_reference(
pkg,
lazy = lazy,
examples = examples,
run_dont_run = run_dont_run,
Expand All @@ -453,6 +453,6 @@ build_site_local <- function(pkg = ".",
build_search(pkg, override = override)
}

cli::cli_rule(paste0("Finished building pkgdown site for package ", cli::col_blue(pkg$package)))
cli::cli_rule("Finished building pkgdown site for package {.pkg {pkg$package}}")
preview_site(pkg, preview = preview)
}
5 changes: 3 additions & 2 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ check_pkgdown <- function(pkg = ".") {
data_articles_index(pkg)
data_reference_index(pkg)

cli::cli_alert_success("No problems found in {.file {pkgdown_config_relpath(pkg)}}")
cli::cli_inform(c(
"v" = "No problems found in {pkgdown_config_href({pkg$src_path})}"
))
}

6 changes: 6 additions & 0 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ pkgdown_config_path <- function(path) {
)
)
}
pkgdown_config_href <- function(path) {
cli::style_hyperlink(
text = "_pkgdown.yml",
url = paste0("file://", pkgdown_config_path(path))
)
}

read_meta <- function(path) {
path <- pkgdown_config_path(path)
Expand Down
3 changes: 1 addition & 2 deletions R/rd-example.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ rd2ex <- function(x, ...) {
run_examples <- function(x,
topic = "unknown",
env = globalenv(),
run_dont_run = FALSE
) {
run_dont_run = FALSE) {

if (!inherits(x, "tag")) {
x <- rd_text(x)
Expand Down
4 changes: 2 additions & 2 deletions R/repo.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ repo_auto_link <- function(pkg, text) {

if (!is.null(url$user)) {
user_link <- paste0("\\1<a href='", url$user, "\\2'>@\\2</a>")
text <- gsub("(\\s|^|\\()@([-\\w]+)", user_link, text, perl = TRUE)
text <- gsub("(p>|\\s|^|\\()@([-\\w]+)", user_link, text, perl = TRUE)
}

if (!is.null(url$issue)) {
issue_link <- paste0("<a href='", url$issue, "\\2'>#\\2</a>")
text <- gsub("(\\(|\\s)#(\\d+)", paste0("\\1", issue_link), text, perl = TRUE)
text <- gsub("(p>|\\(|\\s)#(\\d+)", paste0("\\1", issue_link), text, perl = TRUE)

if (!is.null(pkg$repo$jira_projects)) {
issue_link <- paste0("<a href='", url$issue, "\\1\\2'>\\1\\2</a>")
Expand Down
19 changes: 10 additions & 9 deletions R/topics.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ all_sign <- function(x, text) {
}

match_env <- function(topics) {
out <- env(empty_env(),
fns <- env(empty_env(),
"-" = function(x) -x,
"c" = function(...) c(...)
)
out <- env(fns)

topic_index <- seq_along(topics$name)

Expand Down Expand Up @@ -99,36 +100,36 @@ match_env <- function(topics) {
is_public <- function(internal) {
if (!internal) !topics$internal else rep(TRUE, nrow(topics))
}
out$starts_with <- function(x, internal = FALSE) {
fns$starts_with <- function(x, internal = FALSE) {
any_alias(~ grepl(paste0("^", x), .), .internal = internal)
}
out$ends_with <- function(x, internal = FALSE) {
fns$ends_with <- function(x, internal = FALSE) {
any_alias(~ grepl(paste0(x, "$"), .), .internal = internal)
}
out$matches <- function(x, internal = FALSE) {
fns$matches <- function(x, internal = FALSE) {
any_alias(~ grepl(x, .), .internal = internal)
}
out$contains <- function(x, internal = FALSE) {
fns$contains <- function(x, internal = FALSE) {
any_alias(~ grepl(x, ., fixed = TRUE), .internal = internal)
}
out$has_keyword <- function(x) {
fns$has_keyword <- function(x) {
which(purrr::map_lgl(topics$keywords, ~ any(. %in% x)))
}
out$has_concept <- function(x, internal = FALSE) {
fns$has_concept <- function(x, internal = FALSE) {
match <- topics$concepts %>%
purrr::map(~ str_trim(.) == x) %>%
purrr::map_lgl(any)

which(match & is_public(internal))
}
out$lacks_concepts <- function(x, internal = FALSE) {
fns$lacks_concepts <- function(x, internal = FALSE) {
nomatch <- topics$concepts %>%
purrr::map(~ match(str_trim(.), x, nomatch = FALSE)) %>%
purrr::map_lgl(~ length(.) == 0L | all(. == 0L))

which(nomatch & is_public(internal))
}
out$lacks_concept <- out$lacks_concepts
fns$lacks_concept <- fns$lacks_concepts
out
}

Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Then learn about the many new ways to customise your site in `vignette("customis

## In the wild

At last count, pkgdown is used [by over 8,000 packages](https://github.com/search?q=path%3A_pkgdown.yml+language%3AYAML&type=code&l=YAML). Here are a few examples created by contributors to pkgdown:
At last count, pkgdown is used [by over 11,000 packages](https://github.com/search?q=path%3A_pkgdown.yml+language%3AYAML&type=code&l=YAML). Here are a few examples created by contributors to pkgdown:

* [bayesplot](http://mc-stan.org/bayesplot/index.html)
([source](https://github.com/stan-dev/bayesplot/tree/gh-pages)):
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Then learn about the many new ways to customise your site in

## In the wild

At last count, pkgdown is used [by over 8,000
At last count, pkgdown is used [by over 11,000
packages](https://github.com/search?q=path%3A_pkgdown.yml+language%3AYAML&type=code&l=YAML).
Here are a few examples created by contributors to pkgdown:

Expand Down
2 changes: 1 addition & 1 deletion man/rmd-fragments/footer-configuration.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The example below puts the authors' information on the right along with a legal
footer:
structure:
left: pkgdown
right: [authors, legal]
right: [developed_by, legal]
components:
legal: Provided without **any warranty**.
```
Expand Down
32 changes: 30 additions & 2 deletions tests/testthat/_snaps/build-reference-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
Code
data_reference_index(pkg)
Condition
Error in `check_missing_topics()`:
Error:
! All topics must be included in reference index
x Missing topics: c, e, ?
x Missing topics: c, e, and ?
i Either add to _pkgdown.yml or use @keywords internal

# errors well when a content entry is empty
Expand Down Expand Up @@ -157,3 +157,31 @@
has_icons: no

# can use a selector name as a topic name

Code
data_reference_index(pkg)
Output
pagetitle: Function reference
rows:
- title: bla
slug: bla
desc: ~
is_internal: no
- topics:
- path: matches.html
title: matches
aliases: matches()
icon: ~
- path: A.html
title: A
aliases: A()
icon: ~
names:
- matches
- A
row_has_icons: no
is_internal: no
has_icons: no

6 changes: 4 additions & 2 deletions tests/testthat/_snaps/check.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Code
check_pkgdown(pkg)
Condition
Error in `check_missing_topics()`:
Error in `check_pkgdown()`:
! All topics must be included in reference index
x Missing topics: ?
i Either add to _pkgdown.yml or use @keywords internal
Expand All @@ -14,10 +14,12 @@
check_pkgdown(pkg)
Condition
Error in `check_pkgdown()`:
! 2 vignettes missing from index: 'articles/nested' and 'width'.
! 2 vignettes missing from index in _pkgdown.yml: "articles/nested" and "width".

# informs if everything is ok

Code
check_pkgdown(pkg)
Message
v No problems found in _pkgdown.yml

6 changes: 6 additions & 0 deletions tests/testthat/assets/reference-selector/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Package: testpackage
Version: 1.0.0
Title: A test package
Description: A test package
Authors@R: person("Hadley Wickham")
RoxygenNote: 7.3.1
4 changes: 4 additions & 0 deletions tests/testthat/assets/reference-selector/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(A)
export(matches)
Loading

0 comments on commit 13e95b4

Please sign in to comment.