#' R Markdown site generator for teachr workshops
#'
#' @inheritParams rmarkdown::default_site_generator
#'
#' @export
teachr_website <- function(input, encoding = getOption("encoding"), ...) {
# create the default site generator
default <- rmarkdown::default_site_generator(input, ...)
# then wrap/delegate to the render and clean functions
list(
name = default$name,
output_dir = default$output_dir,
render = function(input_file, output_format, envir, quiet, encoding, ...) {
# Prevent incremental rendering
incremental <- !is.null(input_file)
if(incremental) {
stop("learnr sites must be rendered with rmarkdown::render_site()")
}
# Chapters
input_files <- list.files(file.path(input, "chapters"),
pattern = "^[^_].*\\.[Rr]md$", full.names = TRUE)
lapply(input_files, knitr::knit)
NULL
# delegate to default site generator
# result <- default$render(input_file, output_format, envir, quiet, encoding, ...)
# return result
# result
},
clean = function() {
# files generated by default site generator
generated <- default$clean()
# filter out by existence
generated[file.exists(file.path(input, generated))]
}
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.