Skip to content

Commit

Permalink
Make build_article() work with quarto
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Jun 12, 2024
1 parent 1c16400 commit 8b39778
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
29 changes: 17 additions & 12 deletions R/build-article.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ build_article <- function(name,
input <- pkg$vignettes$file_in[vig]
output_file <- pkg$vignettes$file_out[vig]
depth <- pkg$vignettes$depth[vig]
type <- pkg$vignettes$type[vig]

input_path <- path_abs(input, pkg$src_path)
output_path <- path_abs(output_file, pkg$dst_path)
Expand All @@ -36,18 +37,22 @@ build_article <- function(name,
return(invisible())
}

build_rmarkdown_article(
pkg = pkg,
input_file = input,
input_path = input_path,
output_file = output_file,
output_path = output_path,
depth = depth,
seed = seed,
new_process = new_process,
pandoc_args = pandoc_args,
quiet = quiet
)
if (type == "rmd") {
build_rmarkdown_article(
pkg = pkg,
input_file = input,
input_path = input_path,
output_file = output_file,
output_path = output_path,
depth = depth,
seed = seed,
new_process = new_process,
pandoc_args = pandoc_args,
quiet = quiet
)
} else {
build_quarto_articles(pkg = pkg, article = name)
}
}

build_rmarkdown_article <- function(pkg,
Expand Down
23 changes: 17 additions & 6 deletions R/build-quarto-articles.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
build_quarto_articles <- function(pkg = ".", quiet = TRUE) {
build_quarto_articles <- function(pkg = ".", article = NULL, quiet = TRUE) {
check_required("quarto")
pkg <- as_pkgdown(pkg)

qmds <- pkg$vignettes[pkg$vignettes$type == "qmd", ]
if (!is.null(article)) {
qmds <- qmds[qmds$name == article, ]
}
if (nrow(qmds) == 0) {
return()
}
Expand All @@ -22,15 +25,23 @@ build_quarto_articles <- function(pkg = ".", quiet = TRUE) {
write_yaml(quarto_format(pkg), metadata_path)

# If needed, temporarily make a quarto project so we can build entire dir
project_path <- path(pkg$src_path, "vignettes", "_quarto.yaml")
if (!file_exists(project_path)) {
yaml::write_yaml(list(project = list(render = list("*.qmd"))), project_path)
withr::defer(file_delete(project_path))
if (is.null(article)) {
project_path <- path(pkg$src_path, "vignettes", "_quarto.yaml")
if (!file_exists(project_path)) {
yaml::write_yaml(list(project = list(render = list("*.qmd"))), project_path)
withr::defer(file_delete(project_path))
}
}

if (is.null(article)) {
src_path <- path(pkg$src_path, "vignettes")
} else {
src_path <- path(pkg$src_path, qmds$file_in)
}

output_dir <- withr::local_tempdir("pkgdown-quarto-")
quarto::quarto_render(
path(pkg$src_path, "vignettes"),
src_path,
metadata_file = metadata_path,
execute_dir = output_dir,
quarto_args = c("--output-dir", output_dir),
Expand Down

0 comments on commit 8b39778

Please sign in to comment.