Skip to content

Commit

Permalink
Merge branch 'main' into dark-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jayhesselberth authored Nov 30, 2023
2 parents e6a3dba + 13d8d62 commit ce1885d
Show file tree
Hide file tree
Showing 93 changed files with 934 additions and 527 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Depends:
Imports:
bslib (>= 0.3.1),
callr (>= 3.7.3),
cli,
cli (>= 3.6.1),
desc (>= 1.4.0),
digest,
downlit (>= 0.4.0),
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export(autolink_html)
export(build_article)
export(build_articles)
export(build_articles_index)
export(build_favicon)
export(build_favicons)
export(build_home)
export(build_home_index)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# pkgdown (development version)

* 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).
* Avoid unwanted linebreaks from parsing `DESCRIPTION` (@salim-b, #2247).
* Remove redundant entries in the documentation index when multiple explicit `@usage` tags are provided (@klmr, #2302)
Expand Down
21 changes: 11 additions & 10 deletions R/build-articles.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ build_articles <- function(pkg = ".",
return(invisible())
}

rule("Building articles")
cli::cli_rule("Building articles")

build_articles_index(pkg)
purrr::walk(
Expand Down Expand Up @@ -207,7 +207,9 @@ build_article <- function(name,
# allow code sharing with building of the index.
vig <- match(name, pkg$vignettes$name)
if (is.na(vig)) {
stop("Can't find article called ", src_path(name), call. = FALSE)
cli::cli_abort(
"Can't find article {.file {name}}"
)
}

input <- pkg$vignettes$file_in[vig]
Expand Down Expand Up @@ -368,12 +370,9 @@ data_articles_index <- function(pkg = ".") {
missing <- setdiff(pkg$vignettes$name, c(listed, pkg$package))

if (length(missing) > 0) {
abort(
paste0(
"Vignettes missing from index: ",
paste(missing, collapse = ", ")
),
call. = FALSE
cli::cli_abort(
"{length(missing)} vignette{?s} missing from index: {.file {missing}}.",
call = caller_env()
)
}

Expand All @@ -385,7 +384,10 @@ data_articles_index <- function(pkg = ".") {

data_articles_index_section <- function(section, pkg) {
if (!set_contains(names(section), c("title", "contents"))) {
abort("Section must have components `title`, `contents`")
cli::cli_abort(
"Section must have components {.field title}, {.field contents}",
call = caller_env()
)
}

# Match topics against any aliases
Expand Down Expand Up @@ -424,7 +426,6 @@ default_articles_index <- function(pkg = ".") {
return(NULL)
}


print_yaml(list(
list(
title = tr_("All vignettes"),
Expand Down
40 changes: 16 additions & 24 deletions R/build-favicons.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,25 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) {
rlang::check_installed("openssl")
pkg <- as_pkgdown(pkg)

rule("Building favicons")
cli::cli_rule("Building favicons")

logo_path <- find_logo(pkg$src_path)

if (is.null(logo_path)) {
stop("Can't find package logo PNG or SVG to build favicons.", call. = FALSE)
cli::cli_abort(
"Can't find package logo PNG or SVG to build favicons."
)
}

if (has_favicons(pkg) && !overwrite) {
message("Favicons already exist in `pkgdown/`. Set `overwrite = TRUE` to re-create.")
cli::cli_inform(c(
"Favicons already exist in {.path pkgdown}",
"i" = "Set {.var overwrite = TRUE} to re-create."
))
return(invisible())
}

message("Building favicons with realfavicongenerator.net...")
cli::cli_inform("Building favicons with {.url https://realfavicongenerator.net} ...")

logo <- readBin(logo_path, what = "raw", n = fs::file_info(logo_path)$size)

Expand Down Expand Up @@ -66,18 +71,17 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) {
quiet = TRUE
)
if (httr::http_error(resp)) {
stop("API request failed.", call. = FALSE)
cli::cli_abort("API request failed.", call = caller_env())
}

content <- httr::content(resp)
result <- content$favicon_generation_result

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

tmp <- tempfile()
Expand All @@ -93,27 +97,15 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) {
utils::unzip(tmp, exdir = path(pkg$src_path, "pkgdown", "favicon"))
},
warning = function(e) {
abort("Your logo file couldn't be processed and may be corrupt.", parent = e)
cli::cli_abort("Your logo file couldn't be processed and may be corrupt.", parent = e)
},
error = function(e) {
abort("Your logo file couldn't be processed and may be corrupt.", parent = e)
cli::cli_abort("Your logo file couldn't be processed and may be corrupt.", parent = e)
})

invisible()
}

#' Deprecated as of pkgdown 1.4.0
#' @rdname build_favicons
#' @inheritParams build_favicons
#' @export
build_favicon <- function(pkg, overwrite) {
message(
"`build_favicon()` is deprecated as of pkgdown 1.4.0. ",
"Please use `build_favicons()` instead."
)
build_favicons(pkg, overwrite)
}

copy_favicons <- function(pkg = ".") {
pkg <- as_pkgdown(pkg)

Expand Down
4 changes: 2 additions & 2 deletions R/build-github.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ build_site_github_pages <- function(pkg = ".",
pkg <- as_pkgdown(pkg, override = list(destination = dest_dir))

if (clean) {
rule("Cleaning files from old site", line = 1)
cli::cli_rule("Cleaning files from old site")
clean_site(pkg)
}

Expand All @@ -36,7 +36,7 @@ build_site_github_pages <- function(pkg = ".",
}

build_github_pages <- function(pkg = ".") {
rule("Extra files for GitHub pages")
cli::cli_rule("Extra files for GitHub pages")
pkg <- as_pkgdown(pkg)

# Add .nojekyll since site is static HTML
Expand Down
4 changes: 2 additions & 2 deletions R/build-home-authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ role_lookup <- function(abbr) {

out <- unname(roles[abbr])
if (any(is.na(out))) {
missing <- paste0("'", abbr[is.na(out)], "'", collapse = ", ")
warn(paste0("Unknown MARC role abbreviation ", missing))
missing <- abbr[is.na(out)]
cli::cli_warn("Unknown MARC role abbreviation{?s}: {.field {missing}}")
out[is.na(out)] <- abbr[is.na(out)]
}
out
Expand Down
28 changes: 18 additions & 10 deletions R/build-home-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,21 @@ data_home_sidebar <- function(pkg = ".") {

if (length(html_path)) {
if (!file.exists(html_path)) {
abort(
sprintf(
"Can't find file '%s' specified by %s.",
pkg$meta$home$sidebar$html,
pkgdown_field(pkg, c("home", "sidebar", "html"))
)
rel_html_path <- fs::path_rel(html_path, pkg$src_path)

msg_fld <- pkgdown_field(
pkg, c('home', 'sidebar', 'html'), fmt = TRUE, cfg = TRUE
)

cli::cli_abort(
c(
"Can't locate {.file {rel_html_path}}.",
x = paste0(msg_fld, " is misconfigured.")
),
call = caller_env()
)


}
return(read_file(html_path))
}
Expand Down Expand Up @@ -215,10 +223,10 @@ check_missing_images <- function(pkg, src_path, dst_path) {
exists <- fs::file_exists(path(pkg$dst_path, rel_path))

if (any(!exists)) {
paths <- encodeString(rel_src[!exists], quote = "'")
warn(c(
paste0("Missing images in '", src_path, "': ", paste0(paths, collapse = ", ")),
i = "pkgdown can only use images in 'man/figures' and 'vignettes'"
paths <- rel_src[!exists]
cli::cli_warn(c(
"Missing images in {.file {src_path}}: {.file {paths}}",
i = "pkgdown can only use images in {.file man/figures} and {.file vignettes}"
))
}
}
2 changes: 1 addition & 1 deletion R/build-home-md.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build_home_md <- function(pkg) {
}

render_md <- function(pkg, filename) {
cat_line("Reading ", src_path(path_rel(filename, pkg$src_path)))
cli::cli_inform("Reading {src_path(path_rel(filename, pkg$src_path))}")

body <- markdown_body(filename, strip_header = TRUE)
path <- path_ext_set(basename(filename), "html")
Expand Down
2 changes: 1 addition & 1 deletion R/build-home.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ build_home <- function(pkg = ".",
quiet = TRUE) {

pkg <- section_init(pkg, depth = 0L, override = override)
rule("Building home")
cli::cli_rule("Building home")
dir_create(pkg$dst_path)

build_citation_authors(pkg)
Expand Down
17 changes: 10 additions & 7 deletions R/build-news.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ build_news <- function(pkg = ".",
if (!has_news(pkg$src_path))
return()

rule("Building news")
cli::cli_rule("Building news")
dir_create(path(pkg$dst_path, "news"))

switch(news_style(pkg$meta),
Expand Down Expand Up @@ -151,7 +151,7 @@ data_news <- function(pkg = list()) {
sections <- xml2::xml_find_all(xml, "./body/div")
footnotes <- has_class(sections, "footnotes")
if (any(footnotes)) {
warn("Footnotes in NEWS.md are not currently supported")
cli::cli_warn("Footnotes in NEWS.md are not currently supported")
}
sections <- sections[!footnotes]

Expand All @@ -160,11 +160,14 @@ data_news <- function(pkg = list()) {
xml2::xml_name()
ulevels <- unique(levels)
if (!identical(ulevels, "h1") && !identical(ulevels, "h2")) {
abort(c(
"Invalid NEWS.md: inconsistent use of section headings.",
i = "Top-level headings must be either all <h1> or all <h2>.",
i = "See ?build_news for more details."
))
cli::cli_abort(
c(
"Invalid NEWS.md: inconsistent use of section headings.",
i = "Top-level headings must be either all <h1> or all <h2>.",
i = "See {.help pkgdown::build_news} for more details."
),
call = caller_env()
)
}
if (ulevels == "h1") {
# Bump every heading down a level so to get a single <h1> for the page title
Expand Down
21 changes: 13 additions & 8 deletions R/build-redirects.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ build_redirects <- function(pkg = ".",
return(invisible())
}

rule("Building redirects")
cli::cli_rule("Building redirects")
if (is.null(pkg$meta$url)) {
abort(sprintf("%s required to generate redirects", pkgdown_field(pkg, "url")))
msg_fld <- pkgdown_field(pkg, "url", cfg = TRUE, fmt = TRUE)
cli::cli_abort(
paste0(msg_fld, " is required to generate redirects."),
call = caller_env()
)
}

purrr::iwalk(
Expand All @@ -25,12 +29,13 @@ build_redirects <- function(pkg = ".",

build_redirect <- function(entry, index, pkg) {
if (!is.character(entry) || length(entry) != 2) {
abort(
sprintf(
"Entry %s in %s must be a character vector of length 2.",
index,
pkgdown_field(pkg, "redirects")
)
msg_fld <- pkgdown_field(pkg, "url", cfg = TRUE, fmt = TRUE)
cli::cli_abort(
c(
"Entry {.emph {index}} must be a character vector of length 2.",
x = paste0("Edit ", msg_fld, ".")
),
call = caller_env()
)
}

Expand Down
28 changes: 10 additions & 18 deletions R/build-reference-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,12 @@ check_all_characters <- function(contents, index, pkg) {
any_null <- any(null)

if (any_null) {
abort(
msg_fld <- pkgdown_field(pkg, "reference", cfg = TRUE, fmt = TRUE)
cli::cli_abort(
c(
sprintf(
"Item %s in section %s in %s is empty.",
toString(which(null)),
index,
pkgdown_field(pkg, "reference")
),
i = "Either delete the empty line or add a function name."
)
"Item {.field {which(null)}} in section {index} is empty.",
x = paste0("Delete the empty line or add function name to ", msg_fld, ".")
), call = caller_env()
)
}

Expand All @@ -89,16 +85,12 @@ check_all_characters <- function(contents, index, pkg) {
return(invisible())
}

abort(
msg_fld <- pkgdown_field(pkg, "reference", cfg = TRUE, fmt = TRUE)
cli::cli_abort(
c(
sprintf(
"Item %s in section %s in %s must be a character.",
toString(which(not_char)),
index,
pkgdown_field(pkg, "reference")
),
i = "You might need to add '' around e.g. - 'N' or - 'off'."
)
"Item {.field {which(not_char)}} in section {index} must be a character.",
x = paste0("You might need to add '' around e.g. - 'N' or - 'off' to ", msg_fld, ".")
), call = caller_env()
)

}
Expand Down
Loading

0 comments on commit ce1885d

Please sign in to comment.