Skip to content

Commit

Permalink
process quarto arcticles and test
Browse files Browse the repository at this point in the history
  • Loading branch information
jayhesselberth committed Dec 7, 2024
1 parent 62fdd1b commit f85baeb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions R/build-quarto-articles.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ build_quarto_articles <- function(pkg = ".", article = NULL, quiet = TRUE) {
}
output_dir <- quarto_render(pkg, src_path, quiet = quiet)

# check for articles (in the `vignette/articles` sense)
article_dir <- fs::path(output_dir,"articles")
if (fs::dir_exists(article_dir)){
fs::file_move(dir_ls(article_dir), output_dir)
}

# Read generated data from quarto template and render into pkgdown template
unwrap_purrr_error(purrr::walk2(qmds$file_in, qmds$file_out, function(input_file, output_file) {
built_path <- path(output_dir, path_rel(output_file, "articles"))
Expand Down
19 changes: 18 additions & 1 deletion tests/testthat/test-build-quarto-articles.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ test_that("quarto articles are included in the index", {

suppressMessages(build_article("vig1", pkg))
index <- build_search_index(pkg)

expect_equal(index[[1]]$path, "/articles/vig1.html")
expect_equal(index[[1]]$what, "Heading 1")
expect_equal(index[[1]]$text, "text") # some is a stop word
Expand All @@ -103,3 +103,20 @@ test_that("quarto headings get anchors", {
headings <- xpath_xml(html, "//h2|//h3")
expect_equal(xpath_attr(headings, "./a", "href"), c("#heading-1", "#heading-2"))
})

test_that("can build quarto articles in articles folder", {
skip_if_no_quarto()

pkg <- local_pkgdown_site()
pkg <- pkg_add_file(pkg, "vignettes/articles/vig1.qmd")
pkg <- pkg_add_file(pkg, "vignettes/vig2.qmd")
pkg <- pkg_add_file(pkg, "vignettes/articles/vig3.rmd")
pkg <- pkg_add_file(pkg, "vignettes/vig4.rmd")

suppressMessages(build_articles(pkg))

expect_true(file_exists(path(pkg$dst_path, "articles/vig1.html")))
expect_true(file_exists(path(pkg$dst_path, "articles/vig2.html")))
expect_true(file_exists(path(pkg$dst_path, "articles/vig3.html")))
expect_true(file_exists(path(pkg$dst_path, "articles/vig4.html")))
})

0 comments on commit f85baeb

Please sign in to comment.