forked from UT-IDDynamics/wepidemics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entries.R
119 lines (78 loc) · 2.58 KB
/
entries.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
if (!file.exists("docs/functions.R")) {
source("functions.R")
} else
source("docs/functions.R")
fns <- list.files("data", full.names = TRUE) |> sort()
fns <- fns[!grepl("README[.]md$", fns)]
headers <- get_headers(fns)
# Common URL for the data entries
entry_url <- "https://github.com/UT-IDDynamics/wepidemics/blob/main/"
# Iterating through each document
for (f in fns) {
# Preparing the file
f_path <- sub(".+/", "entries/", f)
if (file.exists(f_path))
file.remove(f_path)
adder <- function(..., end_line = TRUE) {
cat(
...,
ifelse(end_line, "\n", ""),
file = f_path, append = TRUE
)
}
adder("<!--DO NOT EDIT BY HAND-->\n")
# Getting the file headers
header <- headers[[f]]
# Title and menu
adder("# ", null2empty(header$name), "\n")
adder(menu_maker(path = "../", escape_bar = TRUE),"\n")
# Adding content -------------------------------------------------------------
adder(sprintf("**title of the paper:** %s\n", header$`title-paper`))
# DOI
adder(sprintf("**doi:** [%s](https://doi.org/%s)\n", header$doi, header$doi))
# Keywords
if (length(header$keywords)) {
keywords <- tolower(header$keywords)
keywords <- linker(keywords, paste0("**`", keywords, "`**"), "../by-keyword.md") |>
paste(collapse = ", ")
adder("\n**keywords:**", keywords)
}
# Parameters
if (length(header$parameters)) {
parameters <- tolower(header$parameters)
parameters <- linker(parameters, paste0("**`", parameters, "`**"), "../by-parameter.md") |>
paste(collapse = ", ")
adder("\n**Parameters:**", parameters)
}
# Software
if (length(header$`software-package`)) {
adder("\n**software:**\n")
for (s in header$`software-package`)
adder(sprintf(" - [%s](%s) (%s)", s[2], s[3], s[1]))
}
# Data sources
if (length(header$`data-source`)) {
adder("\n**data:**\n")
for (s in header$`data-source`)
adder(sprintf(" - %s [**(link)**](%2$s)", s[1], s[2]))
}
# Example papers
if (length(header$`example-papers`)) {
adder("\n**Example papers:**\n")
for (p in header$`example-papers`)
adder(sprintf(" - [%s](%1$s)", p))
}
# Links
if (length(header$links)) {
adder("\n**Links:**\n")
for (p in header$links)
adder(sprintf(" - [%s](%1$s)", p))
}
# Contents
adder("\n\n## Content\n\n", get_content(f)[[1]], sep = "\n")
# Link to the original
adder(
"\n\n **original entry:** ",
sprintf("[%s%s](%1$s%2$s)", entry_url, f)
)
}