-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmake.R
57 lines (46 loc) · 1.61 KB
/
make.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#! /usr/bin/env Rscript
# Run as local job in RStudio!
options(error = NULL)
slides <- dir(pattern = "Rmd$", full.names = TRUE)
slides <- slides[!grepl("template|README|index", slides)]
slides_html <- purrr::map_chr(slides, ~ {
fs::path_ext(.x) <- "html"
.x
})
assets <- fs::dir_ls("assets", regexp = "libs", invert = TRUE, recurse = TRUE, type = "file")
assets <- c(assets, fs::dir_ls("R"))
youngest_input <- max(fs::file_info(c(slides, assets))$change_time)
youngest_output <- max(fs::file_info(slides_html)$change_time)
if (is.na(youngest_output) || youngest_input > youngest_output) {
message("! rebuilding slides")
source("R/utils.R")
message("Removing assets/libs/")
if (fs::dir_exists("assets/libs'")) fs::dir_delete("assets/libs/")
check_for <- function(
src,
pattern = "_placeholder.*=.*TRUE",
msg = "Placeholders may be turned on in "
) {
found <- grep(pattern, src, value = TRUE)
if (length(found)) {
message(msg, slide)
for (issue in found) {
message(paste("Line", which(issue == src), issue, collapse = "\n"))
}
}
}
for (slide in slides) {
message("Building ", slide, "...")
zap_tabs(slide)
src <- readr::read_lines(slide)
check_for(src) # placeholders
check_for(src, "unsplash_bg\\(")
check_for(src, "FIXME")
callr::r_safe(function(slide) {
options(placeholder_enable = FALSE, js4shiny_repl_local = FALSE)
rmarkdown::render(slide, quiet = TRUE, envir = new.env())
}, args = list(slide = slide))
}
fs::dir_delete(fs::dir_ls("assets/libs", regexp = "metathis", type = "directory"))
message("All done!")
}