From da85b72df0069a9d7ed2851cccc4c7c15efdc2bc Mon Sep 17 00:00:00 2001 From: olivroy Date: Tue, 20 Feb 2024 13:16:46 -0500 Subject: [PATCH 1/4] cli fixes --- R/build-favicons.R | 7 ++----- R/build.R | 16 ++++++++-------- man/build_site.Rd | 8 ++++---- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/R/build-favicons.R b/R/build-favicons.R index 066f4dfb7..ed137c686 100644 --- a/R/build-favicons.R +++ b/R/build-favicons.R @@ -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()) } @@ -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() diff --git a/R/build.R b/R/build.R index f455f9b31..46b72871d 100644 --- a/R/build.R +++ b/R/build.R @@ -27,7 +27,7 @@ #' It specifies where the site will be published and is used to allow other #' pkgdown sites to link to your site when needed (`vignette("linking")`), #' generate a `sitemap.xml`, automatically generate a `CNAME` when -#' [deploying to github][deploy_site_github], generate the metadata needed +#' [deploying to GitHub][deploy_site_github], generate the metadata needed #' rich social "media cards" (`vignette("metadata")`), and more. #' #' * `title` overrides the default site title, which is the package name. @@ -87,7 +87,7 @@ #' ```md #' ::: {.pkgdown-devel} #' You can install the development version of pkgdown from GitHub with: -#' `remotes::install_github("r-lib/pkgdown")` +#' `pak::pak("r-lib/pkgdown")` #' ::: #' ``` #' @@ -222,10 +222,10 @@ #' ```yaml #' repo: #' url: -#' home: https://github.com/r-lib/pkgdown/ +#' home: https://github.com/r-lib/pkgdown #' source: https://github.com/r-lib/pkgdown/blob/HEAD/ -#' issue: https://github.com/r-lib/pkgdown/issues/ -#' user: https://github.com/ +#' issue: https://github.com/r-lib/pkgdown/issues +#' user: https://github.com #' ``` #' #' * `home`: path to package home on source code repository. @@ -408,7 +408,7 @@ 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() @@ -426,7 +426,7 @@ build_site_local <- function(pkg = ".", 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))}") @@ -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) } diff --git a/man/build_site.Rd b/man/build_site.Rd index 60ab07f0f..b529fddcb 100644 --- a/man/build_site.Rd +++ b/man/build_site.Rd @@ -147,7 +147,7 @@ on the development version of your site: \if{html}{\out{
}}\preformatted{::: \{.pkgdown-devel\} You can install the development version of pkgdown from GitHub with: -`remotes::install_github("r-lib/pkgdown")` +`pak::pak("r-lib/pkgdown")` ::: }\if{html}{\out{
}} @@ -282,10 +282,10 @@ Otherwise, you can supply your own in the \code{repo} field: \if{html}{\out{
}}\preformatted{repo: url: - home: https://github.com/r-lib/pkgdown/ + home: https://github.com/r-lib/pkgdown source: https://github.com/r-lib/pkgdown/blob/HEAD/ - issue: https://github.com/r-lib/pkgdown/issues/ - user: https://github.com/ + issue: https://github.com/r-lib/pkgdown/issues + user: https://github.com }\if{html}{\out{
}} \itemize{ \item \code{home}: path to package home on source code repository. From 42f12c47751b73736a1a6fd3c2d644bd9faec01a Mon Sep 17 00:00:00 2001 From: olivroy Date: Tue, 20 Feb 2024 13:56:54 -0500 Subject: [PATCH 2/4] Fix chaining in `check_pkgdown()` + add hyperlink to `_pkgdown.yml` in error message. --- R/build-articles.R | 3 ++- R/build-reference-index.R | 16 ++++++++-------- R/check.R | 2 +- R/package.R | 6 ++++++ man/build_site.Rd | 2 +- tests/testthat/_snaps/build-reference-index.md | 4 ++-- tests/testthat/_snaps/check.md | 4 ++-- 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/R/build-articles.R b/R/build-articles.R index ceb406d93..d434233ad 100644 --- a/R/build-articles.R +++ b/R/build-articles.R @@ -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() ) } diff --git a/R/build-reference-index.R b/R/build-reference-index.R index 1e0c3dfce..0abdd661a 100644 --- a/R/build-reference-index.R +++ b/R/build-reference-index.R @@ -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) @@ -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( @@ -125,7 +125,7 @@ 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 @@ -133,11 +133,11 @@ check_missing_topics <- function(rows, pkg) { 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) } } diff --git a/R/check.R b/R/check.R index 49a1154df..3eb2267b5 100644 --- a/R/check.R +++ b/R/check.R @@ -12,6 +12,6 @@ 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_alert_success("No problems found in {pkgdown_config_href({pkg$src_path})}") } diff --git a/R/package.R b/R/package.R index 415baf2ef..dfaa04659 100644 --- a/R/package.R +++ b/R/package.R @@ -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) diff --git a/man/build_site.Rd b/man/build_site.Rd index b529fddcb..342d9799c 100644 --- a/man/build_site.Rd +++ b/man/build_site.Rd @@ -88,7 +88,7 @@ whole site. It specifies where the site will be published and is used to allow other pkgdown sites to link to your site when needed (\code{vignette("linking")}), generate a \code{sitemap.xml}, automatically generate a \code{CNAME} when -\link[=deploy_site_github]{deploying to github}, generate the metadata needed +\link[=deploy_site_github]{deploying to GitHub}, generate the metadata needed rich social "media cards" (\code{vignette("metadata")}), and more. \item \code{title} overrides the default site title, which is the package name. It's used in the page title and default navbar. diff --git a/tests/testthat/_snaps/build-reference-index.md b/tests/testthat/_snaps/build-reference-index.md index 13a43f0e2..892130a08 100644 --- a/tests/testthat/_snaps/build-reference-index.md +++ b/tests/testthat/_snaps/build-reference-index.md @@ -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 diff --git a/tests/testthat/_snaps/check.md b/tests/testthat/_snaps/check.md index d90010d88..92901e35e 100644 --- a/tests/testthat/_snaps/check.md +++ b/tests/testthat/_snaps/check.md @@ -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 @@ -14,7 +14,7 @@ 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 From 1508af0a909f7dc8e4dc06af9785304e99177a28 Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 21 Feb 2024 19:22:43 -0500 Subject: [PATCH 3/4] Actually show snapshot by using `cli_inform()` instead of `cli_alert_success()`. --- R/check.R | 5 +++-- tests/testthat/_snaps/check.md | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/check.R b/R/check.R index 3eb2267b5..1858ab454 100644 --- a/R/check.R +++ b/R/check.R @@ -12,6 +12,7 @@ check_pkgdown <- function(pkg = ".") { data_articles_index(pkg) data_reference_index(pkg) - cli::cli_alert_success("No problems found in {pkgdown_config_href({pkg$src_path})}") + cli::cli_inform(c( + "v" = "No problems found in {pkgdown_config_href({pkg$src_path})}" + )) } - diff --git a/tests/testthat/_snaps/check.md b/tests/testthat/_snaps/check.md index 92901e35e..f1e4bb125 100644 --- a/tests/testthat/_snaps/check.md +++ b/tests/testthat/_snaps/check.md @@ -20,4 +20,6 @@ Code check_pkgdown(pkg) + Message + v No problems found in _pkgdown.yml From 0b558e88a60adcfbfe1a10c28278f64f0506dcf2 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 22 Feb 2024 09:14:16 -0500 Subject: [PATCH 4/4] Remove unrelated changes --- R/build.R | 10 +++++----- man/build_site.Rd | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/R/build.R b/R/build.R index 46b72871d..14afb5cf5 100644 --- a/R/build.R +++ b/R/build.R @@ -27,7 +27,7 @@ #' It specifies where the site will be published and is used to allow other #' pkgdown sites to link to your site when needed (`vignette("linking")`), #' generate a `sitemap.xml`, automatically generate a `CNAME` when -#' [deploying to GitHub][deploy_site_github], generate the metadata needed +#' [deploying to github][deploy_site_github], generate the metadata needed #' rich social "media cards" (`vignette("metadata")`), and more. #' #' * `title` overrides the default site title, which is the package name. @@ -87,7 +87,7 @@ #' ```md #' ::: {.pkgdown-devel} #' You can install the development version of pkgdown from GitHub with: -#' `pak::pak("r-lib/pkgdown")` +#' `remotes::install_github("r-lib/pkgdown")` #' ::: #' ``` #' @@ -222,10 +222,10 @@ #' ```yaml #' repo: #' url: -#' home: https://github.com/r-lib/pkgdown +#' home: https://github.com/r-lib/pkgdown/ #' source: https://github.com/r-lib/pkgdown/blob/HEAD/ -#' issue: https://github.com/r-lib/pkgdown/issues -#' user: https://github.com +#' issue: https://github.com/r-lib/pkgdown/issues/ +#' user: https://github.com/ #' ``` #' #' * `home`: path to package home on source code repository. diff --git a/man/build_site.Rd b/man/build_site.Rd index 342d9799c..60ab07f0f 100644 --- a/man/build_site.Rd +++ b/man/build_site.Rd @@ -88,7 +88,7 @@ whole site. It specifies where the site will be published and is used to allow other pkgdown sites to link to your site when needed (\code{vignette("linking")}), generate a \code{sitemap.xml}, automatically generate a \code{CNAME} when -\link[=deploy_site_github]{deploying to GitHub}, generate the metadata needed +\link[=deploy_site_github]{deploying to github}, generate the metadata needed rich social "media cards" (\code{vignette("metadata")}), and more. \item \code{title} overrides the default site title, which is the package name. It's used in the page title and default navbar. @@ -147,7 +147,7 @@ on the development version of your site: \if{html}{\out{
}}\preformatted{::: \{.pkgdown-devel\} You can install the development version of pkgdown from GitHub with: -`pak::pak("r-lib/pkgdown")` +`remotes::install_github("r-lib/pkgdown")` ::: }\if{html}{\out{
}} @@ -282,10 +282,10 @@ Otherwise, you can supply your own in the \code{repo} field: \if{html}{\out{
}}\preformatted{repo: url: - home: https://github.com/r-lib/pkgdown + home: https://github.com/r-lib/pkgdown/ source: https://github.com/r-lib/pkgdown/blob/HEAD/ - issue: https://github.com/r-lib/pkgdown/issues - user: https://github.com + issue: https://github.com/r-lib/pkgdown/issues/ + user: https://github.com/ }\if{html}{\out{
}} \itemize{ \item \code{home}: path to package home on source code repository.