Skip to content

Commit

Permalink
Merge branch 'main' into readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored May 14, 2024
2 parents 0a86a98 + 3729c9a commit 5670c72
Show file tree
Hide file tree
Showing 38 changed files with 127 additions and 53 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
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# pkgdown (development version)

* `build_home_index()` now renders Math if you use it in your home page (#2263).
* `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).
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
2 changes: 1 addition & 1 deletion R/build-home-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ data_home_sidebar <- function(pkg = ".", call = caller_env()) {

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
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))
}
10 changes: 5 additions & 5 deletions R/build-search-docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
}
4 changes: 2 additions & 2 deletions R/check-built.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ check_missing_images <- function(pkg, src_path, dst_path) {
src <- xml2::xml_attr(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))
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]
Expand Down
2 changes: 1 addition & 1 deletion R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@ config_path <- function(pkg) {
if (is.null(config)) {
cli::cli_abort("Can't find {.file _pkgdown.yml}.", .internal = TRUE)
}
cli::style_hyperlink(fs::path_file(config), paste0("file://", config))
cli::style_hyperlink(path_file(config), paste0("file://", config))
}
2 changes: 1 addition & 1 deletion R/context.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ context_set_scoped <- function(name, value, scope = parent.frame()) {

article_index <- function(pkg) {
set_names(
fs::path_rel(pkg$vignettes$file_out, "articles"),
path_rel(pkg$vignettes$file_out, "articles"),
pkg$vignettes$name
)
}
8 changes: 4 additions & 4 deletions R/deploy-site.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ deploy_site_github <- function(
cli::cli_inform("Copying private key to {.file ssh_id_file}")
write_lines(rawToChar(openssl::base64_decode(ssh_id)), ssh_id_file)
cli::cli_inform("Setting private key permissions to 0600")
fs::file_chmod(ssh_id_file, "0600")
file_chmod(ssh_id_file, "0600")

cli::cli_inform("Setting remote to use the ssh url")

Expand Down Expand Up @@ -110,8 +110,8 @@ deploy_to_branch <- function(pkg = ".",
github_pages = (branch == "gh-pages"),
...,
subdir = NULL) {
dest_dir <- fs::dir_create(fs::file_temp())
on.exit(fs::dir_delete(dest_dir))
dest_dir <- dir_create(file_temp())
on.exit(dir_delete(dest_dir))

if (!git_has_remote_branch(remote, branch)) {
old_branch <- git_current_branch()
Expand All @@ -137,7 +137,7 @@ deploy_to_branch <- function(pkg = ".",

site_dest_dir <-
if (!is.null(subdir)) {
fs::dir_create(fs::path(dest_dir, subdir))
dir_create(path(dest_dir, subdir))
} else {
dest_dir
}
Expand Down
2 changes: 1 addition & 1 deletion R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ copy_asset_dir <- function(pkg,
}

src_paths <- dir_ls(src_dir, recurse = TRUE)
src_paths <- src_paths[!fs::is_dir(src_paths)]
src_paths <- src_paths[!is_dir(src_paths)]
if (!is.null(file_regexp)) {
src_paths <- src_paths[grepl(file_regexp, path_file(src_paths))]
}
Expand Down
4 changes: 2 additions & 2 deletions R/pkgdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ local_pkgdown_template_pkg <- function(path = NULL, meta = NULL, env = parent.fr
}

if (!is.null(meta)) {
path_pkgdown_yml <- fs::path(path, "inst", "pkgdown", "_pkgdown.yml")
fs::dir_create(fs::path_dir(path_pkgdown_yml))
path_pkgdown_yml <- path(path, "inst", "pkgdown", "_pkgdown.yml")
dir_create(path_dir(path_pkgdown_yml))
yaml::write_yaml(meta, path_pkgdown_yml)
}

Expand Down
6 changes: 4 additions & 2 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ data_template <- function(pkg = ".", depth = 0L) {
name = pkg$package,
version = as.character(pkg$version)
)
out$logo <- list(src = logo_path(pkg, depth = depth))
if (has_logo(pkg)) {
out$logo <- list(src = logo_path(pkg, depth = depth))
}
out$site <- list(
root = up_path(depth),
title = pkg$meta$title %||% pkg$package
Expand Down Expand Up @@ -220,7 +222,7 @@ write_if_different <- function(pkg, contents, path, quiet = FALSE, check = TRUE)
if (same_contents(full_path, contents)) {
# touching the file to update its modification time
# which is important for proper lazy behavior
fs::file_touch(full_path)
file_touch(full_path)
return(FALSE)
}

Expand Down
8 changes: 4 additions & 4 deletions R/utils-fs.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dir_copy_to <- function(src_dir,
}

src_paths <- dir_ls(src_dir, recurse = TRUE)
is_dir <- fs::is_dir(src_paths)
is_dir <- is_dir(src_paths)

dst_paths <- path(dst_dir, path_rel(src_paths, src_dir))

Expand All @@ -36,7 +36,7 @@ file_copy_to <- function(src_paths,
src_label = "",
dst_label = "") {
# Ensure all the "to" directories exist
dst_dirs <- unique(fs::path_dir(dst_paths))
dst_dirs <- unique(path_dir(dst_paths))
dir_create(dst_dirs)

eq <- purrr::map2_lgl(src_paths, dst_paths, file_equal)
Expand All @@ -54,7 +54,7 @@ file_copy_to <- function(src_paths,

# Checks init_site() first.
create_subdir <- function(pkg, subdir) {
if (!fs::dir_exists(pkg$dst_path)) {
if (!dir_exists(pkg$dst_path)) {
init_site(pkg)
}
dir_create(path(pkg$dst_path, subdir))
Expand Down Expand Up @@ -134,5 +134,5 @@ pkgdown_config_relpath <- function(pkg) {
pkg <- as_pkgdown(pkg)
config_path <- pkgdown_config_path(pkg$src_path)

fs::path_rel(config_path, pkg$src_path)
path_rel(config_path, pkg$src_path)
}
2 changes: 1 addition & 1 deletion inst/BS3/templates/content-citation-authors.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1 id="citation">{{#translate}}{{citation}}{{/translate}}</h1>

{{#citations}}
{{{html}}}
<pre>{{{bibtex}}}</pre>
<pre>{{bibtex}}</pre>
{{/citations}}

</div>
Expand Down
2 changes: 1 addition & 1 deletion inst/BS5/templates/content-citation-authors.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2 id="citation">{{#translate}}{{citation}}{{/translate}}</h2>

{{#citations}}
{{{html}}}
<pre>{{{bibtex}}}</pre>
<pre>{{bibtex}}</pre>
{{/citations}}
</div>

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/_snaps/build-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
Code
cat(examples)
Output
testpackage:::f()
#> [1] 0.080750138 0.834333037 0.600760886 0.157208442 0.007399441

2 changes: 0 additions & 2 deletions tests/testthat/_snaps/render.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
package:
name: testpackage
version: 1.0.0
logo:
src: ~
site:
root: ''
title: testpackage
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/assets/articles-images/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
template:
bootstrap: 5

figures:
dev: "jpeg"
fig.ext: "jpg"
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/assets/articles/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
template:
bootstrap: 5
3 changes: 3 additions & 0 deletions tests/testthat/assets/cname/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
url: https://testpackage.r-lib.org

template:
bootstrap: 5
3 changes: 3 additions & 0 deletions tests/testthat/assets/figure/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
template:
bootstrap: 5

figures:
dev: "jpeg"
fig.ext: "jpg"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
template:
bootstrap: 5
assets: pkgdown/assets
1 change: 1 addition & 0 deletions tests/testthat/assets/open-graph-customized/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
url: http://example.com/pkg

template:
bootstrap: 5
opengraph:
image:
src: man/figures/card.png
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/assets/open-graph/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
url: http://example.com/pkg

template:
bootstrap: 5
3 changes: 3 additions & 0 deletions tests/testthat/assets/reference-selector/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
url: http://test.org

template:
bootstrap: 5
3 changes: 3 additions & 0 deletions tests/testthat/assets/reference/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
url: http://test.org

template:
bootstrap: 5
2 changes: 2 additions & 0 deletions tests/testthat/assets/search-site/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
url: http://pkgdown.r-lib.org

template:
bootstrap: 3
params:
docsearch:
api_key: test-api-key
index_name: test-index-name

2 changes: 2 additions & 0 deletions tests/testthat/assets/sidebar/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
template:
bootstrap: 5
3 changes: 3 additions & 0 deletions tests/testthat/assets/site-bad-logo/_pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
url: http://example.com/pkg

template:
bootstrap: 5
Loading

0 comments on commit 5670c72

Please sign in to comment.