-
Notifications
You must be signed in to change notification settings - Fork 335
/
Copy pathcheck.R
113 lines (99 loc) · 2.99 KB
/
check.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#' Check `_pkgdown.yml`
#'
#' @description
#' 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:
#'
#' * There's a `url` in the pkgdown configuration, which is also recorded
#' in the `URL` field of the `DESCRIPTION`.
#'
#' * 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."))
}
#' @export
#' @rdname check_pkgdown
pkgdown_sitrep <- function(pkg = ".") {
cli::cli_rule("Sitrep")
pkg <- as_pkgdown(pkg)
if (pkg$bs_version == 3) {
cli::cli_inform(c(
x = "Bootstrap 3 is deprecated; please switch to Bootstrap 5.",
i = "Learn more at {.url https://www.tidyverse.org/blog/2021/12/pkgdown-2-0-0/#bootstrap-5}."
))
}
error_to_sitrep("URLs", check_urls(pkg))
error_to_sitrep("Favicons", check_favicons(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))
}
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_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
)
}
url <- pkg$meta[["url"]]
if (is.null(url)) {
config_abort(pkg, c("{.field url} is missing.", details), call = call)
} else {
desc_urls <- pkg$desc$get_urls()
desc_urls <- sub("/$", "", desc_urls)
if (!pkg$meta[["url"]] %in% desc_urls) {
msg <- "{.field URL} is missing package url ({url})."
config_abort(pkg, c(msg, details), path = "DESCRIPTION", call = call)
}
}
}
check_favicons <- function(pkg) {
if (!has_logo(pkg)) {
return()
}
if (has_favicons(pkg)) {
logo <- find_logo(pkg$src_path)
favicon <- path(path_favicons(pkg), "favicon.ico")
if (out_of_date(logo, favicon)) {
cli::cli_abort(c(
"Package logo is newer than favicons.",
i = "Do you need to rerun {.run [build_favicons()](pkgdown::build_favicons())}?"
))
}
} else {
cli::cli_abort(c(
"Found package logo but not favicons.",
i = "Do you need to run {.run [build_favicons()](pkgdown::build_favicons())}?"
))
}
}