-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'ac1a5ce3b703482a53226eeb49f54cd5eaac87ba'
- Loading branch information
Showing
87 changed files
with
656 additions
and
522 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
check_built_site <- function(pkg = ".") { | ||
pkg <- as_pkgdown(pkg) | ||
|
||
cli::cli_rule("Checking for problems") | ||
index_path <- path_index(pkg) | ||
if (!is.null(index_path)) { | ||
check_missing_images(pkg, index_path, "index.html") | ||
} | ||
} | ||
|
||
check_missing_images <- function(pkg, src_path, dst_path) { | ||
html <- xml2::read_html(path(pkg$dst_path, dst_path), encoding = "UTF-8") | ||
img <- xml2::xml_find_all(html, ".//img") | ||
src <- xml2::xml_attr(img, "src") | ||
|
||
rel_src <- src[xml2::url_parse(src)$scheme == ""] | ||
rel_path <- path_norm(path(path_dir(dst_path), rel_src)) | ||
exists <- file_exists(path(pkg$dst_path, rel_path)) | ||
|
||
if (any(!exists)) { | ||
paths <- rel_src[!exists] | ||
cli::cli_inform(c( | ||
"Missing images in {.file {path_rel(src_path, pkg$src_path)}}: {.file {paths}}", | ||
i = "pkgdown can only use images in {.file man/figures} and {.file vignettes}" | ||
)) | ||
} | ||
|
||
alt <- xml2::xml_attr(img, "alt") | ||
if (anyNA(alt)) { | ||
problems <- src[is.na(alt)] | ||
problems[grepl("^data:image", problems)] <- "<base64 encoded image>" | ||
cli::cli_inform(c( | ||
x = "Missing alt-text in {.file {path_rel(src_path, pkg$src_path)}}", | ||
set_names(problems, "*") | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,87 @@ | ||
#' Check `_pkgdown.yml` | ||
#' | ||
#' @description | ||
#' Check that your `_pkgdown.yml` is valid without building the whole | ||
#' site. Currently this: | ||
#' This pair of functions checks that your `_pkgdown.yml` is valid without | ||
#' building the whole site. `check_pkgdown()` errors at the first problem; | ||
#' `pkgdown_sitrep()` reports the status of all checks. | ||
#' | ||
#' Currently they check that: | ||
#' | ||
#' * Checks the reference and article indexes to ensure that pkgdown can | ||
#' read them, and that every documentation topic and vignette/article is | ||
#' included in the index. | ||
#' * There's a `url` in the pkgdown configuration, which is also recorded | ||
#' in the `URL` field of the `DESCRIPTION`. | ||
#' | ||
#' * Validates any opengraph metadata that you might have supplied | ||
#' * All opengraph metadata is valid. | ||
#' | ||
#' * All reference topics are included in the index. | ||
#' | ||
#' * All articles/vignettes are included in the index. | ||
# | ||
#' @export | ||
#' @inheritParams as_pkgdown | ||
check_pkgdown <- function(pkg = ".") { | ||
pkg <- as_pkgdown(pkg) | ||
|
||
check_urls(pkg) | ||
data_open_graph(pkg) | ||
data_articles_index(pkg) | ||
data_reference_index(pkg) | ||
|
||
cli::cli_inform(c("v" = "No problems found.")) | ||
} | ||
|
||
check_built_site <- function(pkg = ".") { | ||
#' @export | ||
#' @rdname check_pkgdown | ||
pkgdown_sitrep <- function(pkg = ".") { | ||
cli::cli_rule("Sitrep") | ||
|
||
pkg <- as_pkgdown(pkg) | ||
error_to_sitrep("URLs", check_urls(pkg)) | ||
error_to_sitrep("Open graph metadata", data_open_graph(pkg)) | ||
error_to_sitrep("Articles metadata", data_articles_index(pkg)) | ||
error_to_sitrep("Reference metadata", data_reference_index(pkg)) | ||
} | ||
|
||
cli::cli_rule("Checking for problems") | ||
index_path <- path_index(pkg) | ||
if (!is.null(index_path)) { | ||
check_missing_images(pkg, index_path, "index.html") | ||
} | ||
error_to_sitrep <- function(title, code) { | ||
tryCatch( | ||
{ | ||
code | ||
cli::cli_inform(c("v" = "{title} ok.")) | ||
}, | ||
rlang_error = function(e) { | ||
bullets <- c(cnd_header(e), cnd_body(e)) | ||
cli::cli_inform(c(x = "{title} not ok.", set_names(bullets, " "))) | ||
} | ||
) | ||
invisible() | ||
} | ||
|
||
check_missing_images <- function(pkg, src_path, dst_path) { | ||
html <- xml2::read_html(path(pkg$dst_path, dst_path), encoding = "UTF-8") | ||
src <- xml2::xml_attr(xml2::xml_find_all(html, ".//img"), "src") | ||
check_urls <- function(pkg = ".", call = caller_env()) { | ||
pkg <- as_pkgdown(pkg) | ||
details <- c(i = "See details in {.vignette pkgdown::metadata}.") | ||
|
||
if (identical(pkg$meta, list())) { | ||
cli::cli_abort( | ||
c("No {.path _pkgdown.yml} found.", details), | ||
call = call | ||
) | ||
} | ||
|
||
rel_src <- src[xml2::url_parse(src)$scheme == ""] | ||
rel_path <- fs::path_norm(path(fs::path_dir(dst_path), rel_src)) | ||
exists <- fs::file_exists(path(pkg$dst_path, rel_path)) | ||
url <- pkg$meta[["url"]] | ||
|
||
if (any(!exists)) { | ||
paths <- rel_src[!exists] | ||
cli::cli_warn(c( | ||
"Missing images in {.file {path_rel(src_path, pkg$src_path)}}: {.file {paths}}", | ||
i = "pkgdown can only use images in {.file man/figures} and {.file vignettes}" | ||
)) | ||
if (is.null(url)) { | ||
cli::cli_abort( | ||
c("{config_path(pkg)} lacks {.field url}.", details), | ||
call = call | ||
) | ||
} else { | ||
desc_urls <- pkg$desc$get_urls() | ||
desc_urls <- sub("/$", "", desc_urls) | ||
|
||
if (!pkg$meta[["url"]] %in% desc_urls) { | ||
cli::cli_abort( | ||
c("{.file DESCRIPTION} {.field URL} lacks package url ({url}).", details), | ||
call = call | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.