From 48c344d25461ca1dd23697a42d968dd342df1a8f Mon Sep 17 00:00:00 2001 From: froggleston Date: Wed, 27 Nov 2024 13:24:55 +0000 Subject: [PATCH] Improve instructor notes warnings --- R/build_instructor_notes.R | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/R/build_instructor_notes.R b/R/build_instructor_notes.R index c6f84ee2..18d1e9bd 100644 --- a/R/build_instructor_notes.R +++ b/R/build_instructor_notes.R @@ -5,14 +5,26 @@ build_instructor_notes <- function(pkg, pages = NULL, built = NULL, quiet) { path <- get_source_path() %||% root_path(pkg$src_path) lsn <- this_lesson(path) outpath <- fs::path(pkg$dst_path, "instructor-notes.html") + + instructor_notes_exists <- any(grepl("instructor-notes[.]R?md$", list.files(path=path_instructors(path)))) + if (!instructor_notes_exists) { + cli::cli_alert_danger("WARNING: instructors/instructor-notes.[R]md does not exist!") + return(invisible(NULL)) + } + already_built <- template_check$valid() && fs::file_exists(outpath) && !is.null(built) && !"instructor-notes" %in% get_slug(built) if (!already_built) { page_globals <- setup_page_globals() - inote <- .resources$get()[["instructors"]] - inote <- inote[get_slug(inote) == "instructor-notes"] + inote_resc <- .resources$get()[["instructors"]] + inote <- inote_resc[get_slug(inote_resc) == "instructor-notes"] + if (length(inote) == 0) { + cli::cli_alert_danger("WARNING: instructors/instructor-notes.[R]md exists but is not referenced in your config.yaml `instructors` section.") + return(invisible(NULL)) + } + html <- render_html(inote) if (html != "") { html <- xml2::read_html(html)