Skip to content

Commit

Permalink
Merge commit '41fae74bcfe4bcf642736fe2f9930e7ddf7acc41'
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed May 14, 2024
2 parents 89db291 + 41fae74 commit 3e9a6a4
Show file tree
Hide file tree
Showing 95 changed files with 961 additions and 639 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ jobs:

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-tinytex@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
* No longer support IE9 or earlier
* Strip trailing whitespace
* Label `<nav>`s and improve navbar html.
* `build_home_index()` now renders math if you use it in your home page (#2263).
* `build_home()` now correctly escapes special HTML characters in the bibtex citation (#2022).
* BS5 templates no longer include empty link to logo when none exists (#2536).
* `build_articles()` now reports if you are missing alt-text for any images (#2357).
* `check_pkgdown()` and `pkgdown_sitrep()` have been unified so that they both report on the same problems. They now only differ in the style of their output: `pkgdown_sitrep()` reports whether each category is ok or not ok, while `check_pkgdown()` errors on the first issue (#2463).
* `build_site()` automatically runs `pkgdown_sitrep()` at the start of the process (#2380).
* New `vignette("accessibility")` describes what manual tasks you need to perform to make your site as accessible as possible (#2344).
* `build_reference()` now automatically translates `--`, `---`, ``` `` ```, and `''` to their unicode equivalents (#2530).
* Tweaked navbar display on mobile so that long titles in drop downs (e.g. article titles) are now wrapped, and the search input spans the full width (#2512).
* `build_reference()` now supports `\Sexpr[results=verbatim]` (@bastistician, #2510).
* `build_home()` no longer checks if the README is missing any images. This check is now performed in `build_site()`, after `build_articles()` so you can refer to images created by vignettes with warnings (#2194).
* `build_home()` now includes the contents of `inst/AUTHORS` on the authors page (#2506).
Expand Down
16 changes: 6 additions & 10 deletions R/build-articles.R
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ data_articles_index <- function(pkg = ".") {
pkg <- as_pkgdown(pkg)

meta <- pkg$meta$articles %||% default_articles_index(pkg)
sections <- meta %>%
purrr::map(data_articles_index_section, pkg = pkg) %>%
purrr::compact()
sections <- unwrap_purrr_error(meta %>%
purrr::imap(data_articles_index_section, pkg = pkg) %>%
purrr::compact())

# Check for unlisted vignettes
listed <- sections %>%
Expand Down Expand Up @@ -411,13 +411,9 @@ data_articles_index <- function(pkg = ".") {
))
}

data_articles_index_section <- function(section, pkg) {
if (!set_contains(names(section), c("title", "contents"))) {
cli::cli_abort(
"Section must have components {.field title}, {.field contents}",
call = caller_env()
)
}
data_articles_index_section <- function(section, index, pkg) {
id <- section$title %||% section$subtitle %||% index
check_contents(section$contents, id, pkg, quote(build_articles()))

# Match topics against any aliases
in_section <- select_vignettes(section$contents, pkg$vignettes)
Expand Down
2 changes: 1 addition & 1 deletion R/build-favicons.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) {
i = "Building favicons with {.url https://realfavicongenerator.net} ..."
))

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

json_request <- list(
"favicon_generation" = list(
Expand Down
70 changes: 37 additions & 33 deletions R/build-home-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ data_home_sidebar <- function(pkg = ".", call = caller_env()) {
if (isFALSE(pkg$meta$home$sidebar))
return(pkg$meta$home$sidebar)

html_path <- file.path(pkg$src_path, pkg$meta$home$sidebar$html)
html_path <- path(pkg$src_path, pkg$meta$home$sidebar$html)

if (length(html_path)) {
if (!file.exists(html_path)) {
rel_html_path <- fs::path_rel(html_path, pkg$src_path)
rel_html_path <- path_rel(html_path, pkg$src_path)
config_abort(
pkg,
"{.field home.sidebar.html} specifies a file that doesn't exist ({.file {rel_html_path}}).",
Expand Down Expand Up @@ -97,61 +97,65 @@ data_home_sidebar <- function(pkg = ".", call = caller_env()) {
return(sidebar_html)
}

# compute any custom component
components <- pkg$meta$home$sidebar$components
custom <- pkg$meta$home$sidebar$components
sidebar_custom <- unwrap_purrr_error(purrr::map(
set_names(names2(custom)),
function(comp) {
data_home_component(
custom[[comp]],
error_pkg = pkg,
error_path = paste0("home.sidebar.components.", comp),
error_call = call
)
}
))
sidebar_components <- utils::modifyList(sidebar_components, sidebar_custom)

sidebar_components <- utils::modifyList(
config_check_list(
sidebar_components,
unwrap_purrr_error(purrr::map2(
components,
names(components),
data_home_component,
pkg = pkg,
call = call
)) %>%
set_names(names(components))
)

check_yaml_has(
setdiff(sidebar_structure, names(sidebar_components)),
where = c("home", "sidebar", "components"),
pkg = pkg,
call = call
has_names = sidebar_structure,
error_pkg = pkg,
error_path = "home.sidebar.components",
error_call = call
)

sidebar_final_components <- purrr::compact(
sidebar_components[sidebar_structure]
)

paste0(sidebar_final_components, collapse = "\n")

}

# Update sidebar-configuration.Rmd if this changes
default_sidebar_structure <- function() {
c("links", "license", "community", "citation", "authors", "dev")
}

data_home_component <- function(component, component_name, pkg, call = caller_env()) {

check_yaml_has(
setdiff(c("title", "text"), names(component)),
where = c("home", "sidebar", "components", component_name),
pkg = pkg,
call = call
)

sidebar_section(
data_home_component <- function(component,
error_pkg,
error_path,
error_call = caller_env()) {
title <- config_check_string(
component$title,
bullets = markdown_text_block(component$text)
error_pkg = error_pkg,
error_path = paste0(error_path, ".title"),
error_call = error_call
)
text <- config_check_string(
component$text,
error_pkg = error_pkg,
error_path = paste0(error_path, ".text"),
error_call = error_call
)

sidebar_section(title, bullets = markdown_text_block(text))
}

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

repo <- cran_link(pkg$package)
links <- purrr::pluck(pkg, "meta", "home", "links")
links <- config_pluck(pkg, "home.links")

links <- c(
link_url(sprintf(tr_("View on %s"), repo$repo), repo$url),
Expand Down
6 changes: 3 additions & 3 deletions R/build-home-md.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package_mds <- function(path, in_dev = FALSE) {

# Do not build 404 page if in-dev
if (in_dev) {
mds <- mds[fs::path_file(mds) != "404.md"]
mds <- mds[path_file(mds) != "404.md"]
}

# Remove files that don't need to be rendered
Expand All @@ -29,7 +29,7 @@ package_mds <- function(path, in_dev = FALSE) {
"pull_request_template.md",
"cran-comments.md"
)
mds <- mds[!fs::path_file(mds) %in% no_render]
mds <- mds[!path_file(mds) %in% no_render]

unname(mds)
}
Expand All @@ -45,7 +45,7 @@ render_md <- function(pkg, filename) {
pagetitle = attr(body, "title"),
body = body,
filename = filename,
source = repo_source(pkg, fs::path_rel(filename, pkg$src_path))
source = repo_source(pkg, path_rel(filename, pkg$src_path))
),
path = path
)
Expand Down
2 changes: 1 addition & 1 deletion R/build-logo.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ logo_path <- function(pkg, depth) {
return()
}

paste0(up_path(depth), fs::path_file(path))
paste0(up_path(depth), path_file(path))
}
6 changes: 2 additions & 4 deletions R/build-reference-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data_reference_index_rows <- function(section, index, pkg) {

if (has_name(section, "contents")) {
id <- section$title %||% section$subtitle %||% index
check_contents(section$contents, id, pkg)
check_contents(section$contents, id, pkg, quote(build_reference_index()))
topics <- section_topics(section$contents, pkg$topics, pkg$src_path)

names <- topics$name
Expand All @@ -67,9 +67,7 @@ data_reference_index_rows <- function(section, index, pkg) {
purrr::compact(rows)
}

check_contents <- function(contents, id, pkg) {
call <- quote(build_reference_index())

check_contents <- function(contents, id, pkg, call = caller_env()) {
if (length(contents) == 0) {
config_abort(
pkg,
Expand Down
4 changes: 2 additions & 2 deletions R/build-reference.R
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ build_reference_topic <- function(topic,
deps <- purrr::map(
deps,
htmltools::copyDependencyToDir,
outputDir = file.path(pkg$dst_path, "reference", "libs"),
outputDir = path(pkg$dst_path, "reference", "libs"),
mustWork = FALSE
)
deps <- purrr::map(
deps,
htmltools::makeDependencyRelative,
basepath = file.path(pkg$dst_path, "reference"),
basepath = path(pkg$dst_path, "reference"),
mustWork = FALSE
)
data$dependencies <- htmltools::renderDependencies(deps, c("file", "href"))
Expand Down
16 changes: 8 additions & 8 deletions R/build-search-docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ build_search <- function(pkg = ".",
search_index <- build_search_index(pkg)
jsonlite::write_json(
search_index,
file.path(pkg$dst_path, "search.json"),
path(pkg$dst_path, "search.json"),
auto_unbox = TRUE
)
}
Expand Down Expand Up @@ -127,7 +127,7 @@ build_search_index <- function(pkg) {
}

news_search_index <- function(path, pkg) {
html <- xml2::read_html(file.path(pkg$dst_path, path), encoding = "UTF-8")
html <- xml2::read_html(path(pkg$dst_path, path), encoding = "UTF-8")

# Get contents minus logo
node <- xml2::xml_find_all(html, ".//main")
Expand All @@ -147,7 +147,7 @@ news_search_index <- function(path, pkg) {
}

file_search_index <- function(path, pkg) {
html <- xml2::read_html(file.path(pkg$dst_path, path), encoding = "UTF-8")
html <- xml2::read_html(path(pkg$dst_path, path), encoding = "UTF-8")
# Get page title
title <- xml2::xml_find_first(html, ".//meta[@property='og:title']") %>%
xml2::xml_attr("content")
Expand All @@ -171,11 +171,11 @@ file_search_index <- function(path, pkg) {
}
# Directory parts (where in the site)
get_dir <- function(path) {
dir <- fs::path_dir(path)
dir <- path_dir(path)
if (dir == ".") {
return("")
}
paste(capitalise(unlist(fs::path_split(dir))), collapse = " > ")
paste(capitalise(unlist(path_split(dir))), collapse = " > ")
}
# Headings (where in the page)
get_headings <- function(section, depth) {
Expand Down Expand Up @@ -303,10 +303,10 @@ capitalise <- function(string) {
}

get_site_paths <- function(pkg) {
paths <- fs::dir_ls(pkg$dst_path, glob = "*.html", recurse = TRUE)
paths_rel <- fs::path_rel(paths, pkg$dst_path)
paths <- dir_ls(pkg$dst_path, glob = "*.html", recurse = TRUE)
paths_rel <- path_rel(paths, pkg$dst_path)

# do not include dev package website in search index / sitemap
dev_destination <- meta_development(pkg$meta, pkg$version)$destination
paths_rel[!fs::path_has_parent(paths_rel, "dev")]
paths_rel[!path_has_parent(paths_rel, "dev")]
}
2 changes: 2 additions & 0 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ build_site_local <- function(pkg = ".",
cli::cli_inform("Reading from: {src_path(path_abs(pkg$src_path))}")
cli::cli_inform("Writing to: {dst_path(path_abs(pkg$dst_path))}")

pkgdown_sitrep(pkg)

init_site(pkg)

build_home(pkg, override = override, preview = FALSE)
Expand Down
38 changes: 38 additions & 0 deletions R/check-built.R
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, "*")
))
}
}
Loading

0 comments on commit 3e9a6a4

Please sign in to comment.