From f2cbcf07da385f147d1e4a86e0a86eeebdfb41ae Mon Sep 17 00:00:00 2001 From: cansavvy Date: Thu, 16 May 2024 15:41:48 -0400 Subject: [PATCH] Undo coursera.R changes --- R/coursera.R | 61 ++++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/R/coursera.R b/R/coursera.R index e7c28ed..37d1b8d 100644 --- a/R/coursera.R +++ b/R/coursera.R @@ -215,20 +215,14 @@ convert_coursera_quizzes <- function(input_quiz_dir = "quizzes", #' @importFrom utils download.file #' @import bookdown_path #' -# TODO: add a quarto/rmd argument here render_without_toc <- function(output_dir = file.path("docs", "no_toc"), - render_type = "rmd" output_yaml = "_output.yml", convert_quizzes = FALSE, input_quiz_dir = "quizzes", output_quiz_dir = "coursera_quizzes", verbose = TRUE) { - - # TODO: Look for a _quarto.yml OR a _bookdown.yml file for the root_dir - # TODO: declare in render_type whether this is an Rmd or quarto - - # TODO: root directory will be where _quarto.yml OR a _bookdown.yml is found - root_dir <- list.file(pattern = "") + # Find root directory by finding `_bookdown.yml` file + root_dir <- bookdown_path() # Output files: output_dir <- file.path(root_dir, output_dir) @@ -241,8 +235,20 @@ render_without_toc <- function(output_dir = file.path("docs", "no_toc"), } ###### Declare all the file paths relative to root directory ###### + # Input files: + toc_close_css <- file.path(root_dir, "assets", "toc_close.css") + + if (!file.exists(toc_close_css)) { + download.file("https://raw.githubusercontent.com/jhudsl/ottrpal/master/inst/extdata/toc_close.css", + destfile = toc_close_css + ) + } output_yaml_file <- file.path(root_dir, output_yaml) + # Make sure we have that file + if (!file.exists(toc_close_css)) { + stop(paste0("Could not find: ", toc_close_css)) + } # Make sure we know where the output yaml is if (!file.exists(output_yaml_file)) { stop(paste0("Could not find: ", output_yaml_file)) @@ -274,29 +280,15 @@ render_without_toc <- function(output_dir = file.path("docs", "no_toc"), fs::dir_copy(needed_dir, file.path(output_dir, needed_dir), overwrite = TRUE) } }) - - if (render_type == "rmd") { - # Input files: - toc_close_css <- file.path(root_dir, "assets", "toc_close.css") - - if (!file.exists(toc_close_css)) { - download.file("https://raw.githubusercontent.com/jhudsl/ottrpal/master/inst/extdata/toc_close.css", - destfile = toc_close_css - ) - } - # Make sure we have that file - if (!file.exists(toc_close_css)) { - stop(paste0("Could not find: ", toc_close_css)) - } - - # Slightly different path for the libs folder - libs_path <- file.path("docs", "libs") - if (!dir.exists(file.path(output_dir, "libs"))) { - if (verbose) { - message(file.path("docs", "libs")) - } - fs::dir_copy(libs_path, file.path(output_dir, "libs"), overwrite = TRUE) - } + + # Slightly different path for the libs folder + libs_path <- file.path("docs", "libs") + if (!dir.exists(file.path(output_dir, "libs"))) { + if (verbose) { + message(file.path("docs", "libs")) + } + fs::dir_copy(libs_path, file.path(output_dir, "libs"), overwrite = TRUE) + } ###### Copy over CSS file ###### # Retrieve yaml file specs @@ -347,13 +339,6 @@ render_without_toc <- function(output_dir = file.path("docs", "no_toc"), # Write to "style.css" writeLines(append(full_css, toc_close_css_lines), css_file) - } - - if (render_type == "quarto") { - - # TODO: Put code here about how to get rid of TOC - - } # Only convert the quizzes if set to TRUE if (convert_quizzes) {