-
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 '79c11d2c747166d78f53aee50acc4f6e83a62cf5'
- Loading branch information
Showing
17 changed files
with
208 additions
and
201 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
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") | ||
src <- xml2::xml_attr(xml2::xml_find_all(html, ".//img"), "src") | ||
|
||
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)) | ||
|
||
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}" | ||
)) | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
# warn about missing images in readme | ||
|
||
Code | ||
check_built_site(pkg) | ||
Message | ||
-- Checking for problems ------------------------------------------------------- | ||
Condition | ||
Warning: | ||
Missing images in 'README.md': 'articles/kitten.jpg' | ||
i pkgdown can only use images in 'man/figures' and 'vignettes' | ||
|
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,37 +1,58 @@ | ||
# fails if reference index incomplete | ||
# sitrep reports all problems | ||
|
||
Code | ||
check_pkgdown(pkg) | ||
Condition | ||
Error in `check_pkgdown()`: | ||
! 1 topic missing from index: "?". | ||
i Either use `@keywords internal` to drop from index, or | ||
i Edit _pkgdown.yml to fix the problem. | ||
|
||
# fails if article index incomplete | ||
pkgdown_sitrep(pkg) | ||
Message | ||
-- Sitrep ---------------------------------------------------------------------- | ||
x URLs not ok. | ||
'DESCRIPTION' URL lacks package url (http://test.org). | ||
See details in `vignette(pkgdown::metadata)`. | ||
v Open graph metadata ok. | ||
v Articles metadata ok. | ||
x Reference metadata not ok. | ||
1 topic missing from index: "?". | ||
Either use `@keywords internal` to drop from index, or | ||
Edit _pkgdown.yml to fix the problem. | ||
|
||
# checks fails on first problem | ||
|
||
Code | ||
check_pkgdown(pkg) | ||
Condition | ||
Error in `check_pkgdown()`: | ||
! 2 vignettes missing from index: "articles/nested" and "width". | ||
i Edit _pkgdown.yml to fix the problem. | ||
! 'DESCRIPTION' URL lacks package url (http://test.org). | ||
i See details in `vignette(pkgdown::metadata)`. | ||
|
||
# informs if everything is ok | ||
# both inform if everything is ok | ||
|
||
Code | ||
pkgdown_sitrep(pkg) | ||
Message | ||
-- Sitrep ---------------------------------------------------------------------- | ||
v URLs ok. | ||
v Open graph metadata ok. | ||
v Articles metadata ok. | ||
v Reference metadata ok. | ||
Code | ||
check_pkgdown(pkg) | ||
Message | ||
v No problems found. | ||
|
||
# warn about missing images in readme | ||
# check_urls reports problems | ||
|
||
Code | ||
check_built_site(pkg) | ||
Message | ||
-- Checking for problems ------------------------------------------------------- | ||
check_urls(pkg) | ||
Condition | ||
Error: | ||
! _pkgdown.yml lacks url. | ||
i See details in `vignette(pkgdown::metadata)`. | ||
|
||
--- | ||
|
||
Code | ||
check_urls(pkg) | ||
Condition | ||
Warning: | ||
Missing images in 'README.md': 'articles/kitten.jpg' | ||
i pkgdown can only use images in 'man/figures' and 'vignettes' | ||
Error: | ||
! 'DESCRIPTION' URL lacks package url (https://testpackage.r-lib.org). | ||
i See details in `vignette(pkgdown::metadata)`. | ||
|
Oops, something went wrong.