Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for rmd/qmd articles #2826

Merged
merged 8 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
^tools$
^\.lintr.R$
^vignettes/\.quarto$
^vignettes/articles/\.quarto$
^vignettes/articles/*_files$
^vignettes/articles$
3 changes: 2 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ inst/doc
docs

/.quarto/
**/.quarto/
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)

* 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).
Expand Down
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
1 change: 1 addition & 0 deletions pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ articles:
easily be tested automatically.
contents:
- starts_with("test")
- starts_with("articles/test")

reference:
- title: Build
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")))
})
3 changes: 3 additions & 0 deletions vignettes/articles/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.html
*.R
*_files
6 changes: 6 additions & 0 deletions vignettes/articles/test-quarto-article.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: "Test Quarto article"
format: html
---

This article should appear on the pkgdown site but not in the built package.
6 changes: 6 additions & 0 deletions vignettes/articles/test-rmarkdown-article.Rmd
Original file line number Diff line number Diff line change
@@ -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.
Loading