-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog.Rmd
executable file
·78 lines (60 loc) · 2.2 KB
/
blog.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
title: "Blog"
subtitle: "Mostly a reference"
output: html_document
---
---
```{r include = F}
knitr::opts_chunk$set(dev = 'svg',
echo = FALSE,
message = FALSE)
packages <- c("readr", "glue", "tidyverse", "psych", "zoo")
xfun::pkg_attach(packages, message = F)
```
```{r}
df <- read_csv("blogs.csv") %>%
mutate(date = glue("{year}-{month}-{day}")) %>%
mutate(date = as.Date(date)) %>%
arrange(desc(date))
df_collab <- read_csv("collaborator-urls.csv")
df_tags <- read_csv("tag-colors.csv")
```
```{r, results = 'asis'}
html_row <- function(df, i) {
code <- glue("<div class='divTableRow'>")
code <- glue("{code}<div style='width: 100px;' class='divTableCell'>{df$date[i]}</div>")
code <- glue("{code}<div class='divTableCell'>")
# title
code <- glue("{code}<div class='divBlogTitle'>")
if (df$link_new_window[i] == TRUE) {
code <- glue("{code}<a href='{df$link[i]}' target='_blank'>{df$title[i]}</a>")
} else {
code <- glue("{code}<a href='{df$link[i]}'>{df$title[i]}</a>")
}
if (!is.na(df$github_link[i])) {
code <- glue("{code} <a href='{df$github_link[i]}' target='_blank'><span class='fa fa-github'></span></a>")
}
code <- glue("{code}</div>")
code <- glue("{code}<br>{df$description[i]}")
# tags
tags <- str_split(df$tags[i], ",") %>% unlist() %>% sort()
tags_code <- ""
for (j in 1:length(tags)) {
tag_color <- df_tags$color[which(df_tags$tag == tags[j])]
tags_code <- glue("{tags_code} <span class='badge badge-pill badge-{tag_color}'>{tags[j]}</span>")
}
code <- glue("{code}<br>*Tags*: {tags_code}")
code <- glue("{code}</div></div>")
return(code)
}
code_all <- "<div class='divTable'><div class='divTableBody'><div class='divTableRow'><div class='divTableCell'>**Date**</div><div class='divTableCell'>**Post**</div></div>"
for (i in 1:nrow(df)) {
code_all <- glue("{code_all}<br>{html_row(df, i)}")
}
code_all <- glue("{code_all}</div></div>")
# link collaborators to their respective website
for (i in 1:nrow(df_collab)) {
code_all <- str_replace_all(code_all, df_collab$collaborator[i], glue("<a href='{df_collab$link[i]}' target='_blank'>{df_collab$collaborator[i]}</a>"))
}
cat(code_all)
```