-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog_transfer.R
55 lines (37 loc) · 1.48 KB
/
blog_transfer.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
library(tidyverse)
file_list <- list.files("/Users/spencergreenhalgh/Desktop/", pattern = ".md", full.names = TRUE)
for(i in 1:length(file_list)){
temp_file <- read_lines(file_list[i])
if(temp_file[7] == "categories = [\"macro\"]"){
next
}
if(temp_file[7] == "categories = [\"micro\"]"){
temp_file[c(1,8)] <- "---"
temp_file[3] <- temp_file[3] %>% str_replace(" =",":")
temp_file[4] <- temp_file[4] %>% str_replace(" =",":")
write_name <- temp_file[5] %>%
str_replace("slug = \"", "") %>%
str_replace("\"","") %>%
str_replace_all("[!',()]","") %>%
str_c(".md")
temp_file[7] <- temp_file[7] %>% str_replace("categories =","tags:")
temp_file <- temp_file[c(1,3,4,7,8)]
temp_file
write_lines(temp_file,paste0("/Users/spencergreenhalgh/hugo-testing/content/",write_name))
next
}
if(temp_file[7] == "categories = [\"link\"]"){
temp_file[c(1,8)] <- "---"
temp_file[3] <- temp_file[3] %>% str_replace(" =",":")
temp_file[4] <- temp_file[4] %>% str_replace(" =",":")
write_name <- temp_file[5] %>%
str_replace("slug = \"", "") %>%
str_replace("\"","") %>%
str_replace_all("[!',()]","") %>%
str_c(".md")
temp_file[7] <- temp_file[7] %>% str_replace("categories =","tags:")
temp_file <- temp_file[c(1,3,4,7,8,9,10,11)]
write_lines(temp_file,paste0("/Users/spencergreenhalgh/hugo-testing/content/",write_name))
}
print(i)
}