-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_content.R
51 lines (32 loc) · 1.36 KB
/
generate_content.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
# Set up ------------------------------------------------------------------
# Load lang_configs and pre-render functions
pre_render_files <- dir("pre-render", full.names = TRUE)
invisible(lapply(pre_render_files, source))
# Get the list of years
years <- dir(pattern = "^\\d{4}$")
# Page per year -----------------------------------------------------------
file_info_by_year <- vector("list", length(years))
for (year in years) {
# Build list of files by language
file_info_by_lang <- lapply(lang_configs,
get_file_info,
year)
year_file_info <- do.call(rbind, file_info_by_lang)
if (is.null(year_file_info)) next
year_file_info[["year"]] <- year
file_info_by_year <- append(file_info_by_year, list(year_file_info))
output_file <- file.path(year, "content.qmd")
con <- file(output_file, open = "w")
add_year_heading(year, con)
add_days_content(year_file_info, con)
close(con)
}
# Index page --------------------------------------------------------------
# filter list in case a year folder exists but no scripts
has_file_info <- vapply(file_info_by_year, is.data.frame, logical(1))
file_info_by_year <- file_info_by_year[has_file_info]
all_file_info <- do.call(rbind, file_info_by_year)
if (length(all_file_info) <= 0) {
stop("No solution files found.")
}
generate_index_page(all_file_info)