forked from hospitalbuildings/site2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03renderhtml.Rmd
57 lines (47 loc) · 1.28 KB
/
03renderhtml.Rmd
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
---
title: "03renderhtml"
output: html_document
date: "2023-07-05"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Rendering the HTML versions
```{r get file names}
#get the names of all the html files
filenames <- list.files("site")
filenames
```
```{r generate yaml}
#store the string we want to start out yaml file with
yamlstring <- 'name: "LA"
navbar:
title: "Incinerators"
left:
- text: "Authorities"
menu:'
#create an empty vector to store all the strings we're about to create
strvec <- c()
#loop through the filenames
for (i in filenames){
if(substring(i,nchar(i)-2,nchar(i)) == ".md" ){
#replace spaces with dashes, and replace the file extension with .html
htmlversion <- gsub(" ","-",gsub(".md",".html",i))
#get the name by removing the file extension.
textversion <- gsub(".md","",i)
#create a string for the YAML file by inserting those
fullstring <- paste0('
- text: "',textversion,'"
href: ',htmlversion)
strvec <- c(strvec,fullstring) #add to the collection of strings
}
}
#add the initial string
strvec <- c(yamlstring, strvec)
#create a yaml file with that string of text in it
write(strvec, file = "site/_site.yml")
```
```{r render site}
#now render the site
rmarkdown::render_site("site")
```