From 4ed37469e87c3ab813dc954da388242a873738ab Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Tue, 10 Dec 2024 13:08:08 -0700 Subject: [PATCH] Better support for rmd/qmd articles (#2826) Closes #2821. Closes #2733 --- .Rbuildignore | 3 +++ .github/workflows/R-CMD-check.yaml | 3 ++- .github/workflows/test-coverage.yaml | 3 ++- .gitignore | 1 + NEWS.md | 1 + R/build-quarto-articles.R | 6 ++++++ pkgdown/_pkgdown.yml | 1 + tests/testthat/test-build-quarto-articles.R | 19 ++++++++++++++++++- vignettes/articles/.gitignore | 3 +++ vignettes/articles/test-quarto-article.qmd | 6 ++++++ vignettes/articles/test-rmarkdown-article.Rmd | 6 ++++++ 11 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 vignettes/articles/.gitignore create mode 100644 vignettes/articles/test-quarto-article.qmd create mode 100644 vignettes/articles/test-rmarkdown-article.Rmd diff --git a/.Rbuildignore b/.Rbuildignore index 620b2328e..84163ab97 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -21,3 +21,6 @@ ^tools$ ^\.lintr.R$ ^vignettes/\.quarto$ +^vignettes/articles/\.quarto$ +^vignettes/articles/*_files$ +^vignettes/articles$ diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 11411bea0..377bb63c5 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -45,7 +45,7 @@ jobs: - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 - + - uses: r-lib/actions/setup-tinytex@v2 - uses: r-lib/actions/setup-r@v2 @@ -58,6 +58,7 @@ jobs: with: extra-packages: any::rcmdcheck needs: check + quarto-version: 1.6.32 - uses: r-lib/actions/check-r-package@v2 with: diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index eb25110b7..9dfa2d652 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -29,7 +29,8 @@ jobs: with: extra-packages: any::covr, any::xml2 needs: coverage - + quarto-version: 1.6.32 + - uses: r-lib/actions/setup-tinytex@v2 - name: Test coverage diff --git a/.gitignore b/.gitignore index df027dcf3..baa1d4b10 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ inst/doc docs /.quarto/ +**/.quarto/ diff --git a/NEWS.md b/NEWS.md index 979a0e0d8..900f4af38 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* Articles (i.e., vignettes in `vignettes/articles`, created by `usethis::use_article()` and available on pkgdown sites but not included in a built package) have improved test cases (thanks to @venpopov and @ethanbass). * New `clean_site(force = TRUE)` for cleaning of `docs/` regardless of whether it was built by pkgdown (#2827). * Links to favicons in page headers were updated to reflect changes to https://realfavicongenerator.net/ (#2804). Favicons should be re-generated by manually removing the `pkgdown/favicon` directory and then running `pkgdown::build_favicons()`. * The language of the site is set from the first `Language:` in the `DESCRIPTION` if it is available and no other language is specified (@jonthegeek, #2808). diff --git a/R/build-quarto-articles.R b/R/build-quarto-articles.R index 72b39980b..148fbb318 100644 --- a/R/build-quarto-articles.R +++ b/R/build-quarto-articles.R @@ -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")) diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 7bd5bcd6d..b19f8e68d 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -52,6 +52,7 @@ articles: easily be tested automatically. contents: - starts_with("test") + - starts_with("articles/test") reference: - title: Build diff --git a/tests/testthat/test-build-quarto-articles.R b/tests/testthat/test-build-quarto-articles.R index 2caa1e781..317abd9d5 100644 --- a/tests/testthat/test-build-quarto-articles.R +++ b/tests/testthat/test-build-quarto-articles.R @@ -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 @@ -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"))) +}) diff --git a/vignettes/articles/.gitignore b/vignettes/articles/.gitignore new file mode 100644 index 000000000..ba7abf328 --- /dev/null +++ b/vignettes/articles/.gitignore @@ -0,0 +1,3 @@ +*.html +*.R +*_files diff --git a/vignettes/articles/test-quarto-article.qmd b/vignettes/articles/test-quarto-article.qmd new file mode 100644 index 000000000..086966cfb --- /dev/null +++ b/vignettes/articles/test-quarto-article.qmd @@ -0,0 +1,6 @@ +--- +title: "Test Quarto article" +format: html +--- + +This article should appear on the pkgdown site but not in the built package. diff --git a/vignettes/articles/test-rmarkdown-article.Rmd b/vignettes/articles/test-rmarkdown-article.Rmd new file mode 100644 index 000000000..67c2ea2de --- /dev/null +++ b/vignettes/articles/test-rmarkdown-article.Rmd @@ -0,0 +1,6 @@ +--- +title: "Test Rmarkdown article" +output: html_document +--- + +This article should appear on the pkgdown site but not in the built package.