Skip to content

Commit

Permalink
suport for multiple custom outputs defined in renders: param in confi…
Browse files Browse the repository at this point in the history
…g.yaml
  • Loading branch information
mivalek committed Jul 10, 2021
1 parent fcecabf commit a44ff2b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#' @export
build_site = function(local = FALSE, run_hugo = TRUE, build_rmd = FALSE, ...) {
knitting = is_knitting()
renders = as.list(yaml::read_yaml("config.yaml")$renders)
if (!knitting) on.exit(run_script('R/build.R', as.character(local)), add = TRUE)
if (build_method() == 'custom') return()

Expand All @@ -81,7 +82,7 @@ build_site = function(local = FALSE, run_hugo = TRUE, build_rmd = FALSE, ...) {
if (length(files)) get_option('blogdown.files_filter', identity)(files)
}
}
build_rmds(files, knitting)
build_rmds(files, knitting, renders)
}
if (run_hugo) on.exit(hugo_build(local, ...), add = TRUE)
if (!knitting) on.exit(run_script('R/build2.R', as.character(local)), add = TRUE)
Expand Down Expand Up @@ -117,7 +118,7 @@ list_mds = function() list_files(content_file(), '[.]md$')
is_knitting = function() isTRUE(opts$get('render_one'))

# build R Markdown posts
build_rmds = function(files, knitting = is_knitting()) {
build_rmds = function(files, knitting = is_knitting(), renders) {
# emit a message indicating that a file is being knitted when the knitting is
# not triggered by the Knit button
msg_knit = function(f, start = TRUE) {
Expand Down Expand Up @@ -178,7 +179,7 @@ build_rmds = function(files, knitting = is_knitting()) {
copy_output_yml(d)
msg_knit(f)
x = xfun::Rscript_call(
build_one, list(f, I(basename(out2)), to_md, !knitting),
build_one, list(f, I(basename(out2)), to_md, !knitting, renders),
fail = c('Failed to render ', f)
)

Expand All @@ -205,14 +206,17 @@ build_rmds = function(files, knitting = is_knitting()) {
}
}

build_one = function(input, output, to_md = file_ext(output) != 'html', quiet = TRUE) {
build_one = function(input, output, to_md = file_ext(output) != 'html', quiet = TRUE, renders) {
options(htmltools.dir.version = FALSE)
setwd(dirname(input))
input = basename(input)
# for bookdown's theorem environments generated from bookdown:::eng_theorem
if (to_md) options(bookdown.output.markdown = TRUE)
output_fmt = unname(unlist(renders[rmarkdown::yaml_front_matter(input)$type]))
if (is.null(output_fmt)) output_fmt = renders$default
if (is.null(output_fmt)) output_fmt = 'blogdown::html_page'
res = rmarkdown::render(
input, 'blogdown::html_page', output_file = output, envir = globalenv(),
input, output_fmt, output_file = output, envir = globalenv(),
quiet = quiet, run_pandoc = !to_md, clean = !to_md
)
x = read_utf8(res)
Expand Down

0 comments on commit a44ff2b

Please sign in to comment.