-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.R
78 lines (63 loc) · 1.69 KB
/
template.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
## Writing species pages and TOC
library(whisker)
## Example species info
sptab <- structure(
list(
id = c(
"ALFL",
"AMCR",
"AMGO"),
scientific = c(
"Empidonax alnorum",
"Corvus brachyrhynchos",
"Spinus tristis"),
english = c(
"Alder Flycatcher",
"American Crow",
"American Goldfinch"),
french = c(
"Moucherolle des aulnes",
"Corneille d'Amérique",
"Chardonneret jaune")),
row.names = c("ALFL", "AMCR", "AMGO"),
class = "data.frame")
## Species IDs to loop over
SPP <- sptab$id
## Template for TOC
TOC <-
'---
title: List of Species
---
Click on a species to see the summaries.
'
## Template for species page
TMP <-
'---
title: {{ENG}}
subtitle: {{SCI}}
---
This is the page for {{ENG}}.
![Distribution map](https://borealbirds.github.io/api/v4/species/{{ID}}/images/mean-pred.png)
'
for (spp in SPP) {
cat("Writing page for", spp, "\n")
flush.console()
## get info from table for spp
o <- sptab[spp,]
## Add a TOC entry
NAM <- sprintf("%s – %s (_%s_)", o$english, o$french, o$scientific)
LINK <- sprintf("{{ site.baseurl }}/species/%s/", spp)
TOC <- c(TOC, sprintf("- [%s](%s)", NAM, LINK))
## Make the species page
LIST <- list(
ID=o$id,
ENG=o$english,
SCI=o$scientific)
## Write the species page
if (!dir.exists(paste0("docs/species/", spp)))
dir.create(paste0("docs/species/", spp))
writeLines(whisker.render(TMP, LIST),
paste0("docs/species/", spp, "/index.md"))
}
## Write the TOC
writeLines(TOC, "docs/species/index.md")