Skip to content

Commit

Permalink
Merge branch 'main' into optional-yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored May 14, 2024
2 parents caa7544 + ac1a5ce commit 21f690d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pkgdown (development version)

* `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).
Expand Down
1 change: 1 addition & 0 deletions R/markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ convert_markdown_to_html <- function(in_path, out_path, ...) {
"--indented-code-classes=R",
"--section-divs",
"--wrap=none",
"--mathjax",
...
))
)
Expand Down
21 changes: 20 additions & 1 deletion R/pkgdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,32 @@ local_envvar_pkgdown <- function(pkg, scope = parent.frame()) {
)
}

local_pkgdown_site <- function(path = NULL, meta = NULL, env = parent.frame()) {
local_pkgdown_site <- function(path = NULL, meta = NULL, clone = FALSE, env = parent.frame()) {
check_bool(clone)

if (is.null(path)) {
path <- withr::local_tempdir(.local_envir = env)
desc <- desc::desc("!new")
desc$set("Package", "testpackage")
desc$set("Title", "A test package")
desc$write(file = path(path, "DESCRIPTION"))
}

if (clone) {
if (is.null(path)) {
cli::cli_abort("Can only clone when {.arg path} is set.")
} else {
src_paths <- dir_ls(path, recurse = TRUE)
is_dir <- is_dir(src_paths)

dst <- withr::local_tempdir("pkgdown", .local_envir = env)
dst_paths <- path(dst, path_rel(src_paths, path))

dir_create(dst_paths[is_dir])
file_copy(src_paths[!is_dir], dst_paths[!is_dir])

path <- dst
}
}

if (is.character(meta)) {
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-build-home-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ test_that("title and description come from DESCRIPTION by default", {
expect_equal(data_home(pkg)$opengraph$description, "Y")
})

test_that("math is handled", {
pkg <- local_pkgdown_site(test_path("assets/home-readme-rmd"), clone = TRUE)
write_lines(c("$1 + 1$"), path(pkg$src_path, "README.md"))

suppressMessages(init_site(pkg))
suppressMessages(build_home_index(pkg))

html <- xml2::read_html(path(pkg$dst_path, "index.html"))
expect_equal(xpath_text(html, ".//span[contains(@class, 'math')]"), "\\(1 + 1\\)")
})

test_that("version formatting in preserved", {
pkg <- local_pkgdown_site(test_path("assets/version-formatting"))
expect_equal(pkg$version, "1.0.0-9000")
Expand Down

0 comments on commit 21f690d

Please sign in to comment.