-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect-README.R
53 lines (46 loc) · 1.33 KB
/
collect-README.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
library(tidyverse)
manifest <- yaml::read_yaml("manifest.yaml")
files <- tibble::tibble(
group_desc = manifest
) |>
unnest_wider(group_desc) |>
unnest_longer(files) |>
unnest_wider(files)
readme_content <- files |>
mutate(
group = as_factor(group),
tag = as_factor(tag),
name = as_factor(name),
format = as_factor(format)
) |>
mutate(
md_link = glue::glue("[{format}]({url})")
) |>
group_by(group, tag, name) |>
summarise(
link_summary = paste(md_link, collapse = ", "),
bullet = glue::glue("- {name[1]} ({link_summary})"),
.groups = "drop_last"
) |>
select(-link_summary) |>
summarise(
file_listing = paste(bullet, collapse = "\n"),
file_summary = glue::glue("## Files\n\n{file_listing}"),
.groups = "drop_last"
) |>
select(-file_listing) |>
summarise(
file_summary = paste0(file_summary, collapse = "\n\n"),
.groups = "drop"
) |>
mutate(readme_file = glue::glue("{group}/README.md"))
readme_content
for (i in seq_len(nrow(readme_content))) {
f <- readme_content$readme_file[i]
content <- readr::read_lines(f)
target <- which(content == "<!-- begin file listing -->")
stopifnot(length(target) == 1L)
readr::write_lines(content[1:target], f)
readr::write_lines("\n", f, append = TRUE)
readr::write_lines(readme_content$file_summary[i], f, append = TRUE)
}