/
README.Rmd
137 lines (104 loc) · 5.58 KB
/
README.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE)
```
```{r attach-pkgs, message=FALSE}
# Attach packages
suppressPackageStartupMessages({
library(emoji)
library(ggplot2)
library(knitr)
library(lubridate)
})
```
```{r fetch-post-names}
# Get all the internal post paths
post_paths <-
list.files("posts", pattern = ".qmd$", full.names = TRUE, recursive = TRUE)
# Extract title and date from each post
get_post_info <- function(post_path) {
post_lines <- readLines(post_path, warn = FALSE)
title_rx <- "title:"
date_rx <- "date:"
title_i <- grep(title_rx, post_lines)[1]
date_i <- grep(date_rx, post_lines)[1]
post_title <- trimws(gsub(title_rx, "", post_lines[title_i]))
post_title <- gsub("^\'|\'$|^\"|\"$", "", post_title)
post_date <- trimws(gsub(date_rx, "", post_lines[date_i]))
data.frame(title = post_title, publish_date = ymd(post_date))
}
# Get title and date of every post
post_info <- lapply(post_paths, function(path) get_post_info(path))
posts <- do.call(rbind, post_info)
# Generate a web link to each post
posts$link <- paste0("https://www.rostrum.blog/", dirname(post_paths))
# Invert order, so latest is at the top
posts <- posts[rev(row.names(posts)), ]
```
```{r date-bin}
# A dataframe with one row per day since the blog's first post
all_dates <- data.frame(
publish_date = as_date(
ymd(min(posts$publish_date)):today()
)
)
# Left join posts to dates
post_timeline <- merge(all_dates, posts, by = "publish_date", all.x = TRUE)
# Add a 'binary' column: 1 if there was a post that day, NA if not
post_timeline$bin <- ifelse(is.na(post_timeline$title), NA_real_, 1)
date_bin_wth_dupes <- post_timeline[, c("publish_date", "bin")]
# Remove duplicates because sometimes there's more than one post per day
date_bin <- date_bin_wth_dupes[!duplicated(date_bin_wth_dupes), ]
```
```{r plot}
# Create plot object
p <- ggplot(date_bin) +
# geom_point( # marker for today's date
# aes(x = Sys.Date(), y = 1),
# shape = "|", size = 10, stroke = 1, color = "grey95"
# ) +
geom_point( # markers for publishing dates
aes(x = publish_date, y = bin),
shape = "|", size = 10, stroke = 1, color = "#1D8016", alpha = 0.7
) +
theme(
legend.position = "none",
panel.grid = element_blank(),
axis.title = element_blank(),
axis.text.x = element_text(colour = "#1D8016"),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
panel.background = element_blank()
)
```
<img src="images/logo-hex.png" alt="Bright green hexagon with the blog's logo of a 16-bit insect in black." width="150" align="right">
# rostrum-blog
<!-- badges: start -->
[![rostrum.blog
post](https://img.shields.io/badge/rostrum-blog-008900?style=flat&labelColor=black&logo=data:image/gif;base64,R0lGODlhEAAQAPEAAAAAABWCBAAAAAAAACH5BAlkAAIAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAEAAQAAAC55QkISIiEoQQQgghRBBCiCAIgiAIgiAIQiAIgSAIgiAIQiAIgRAEQiAQBAQCgUAQEAQEgYAgIAgIBAKBQBAQCAKBQEAgCAgEAoFAIAgEBAKBIBAQCAQCgUAgEAgCgUBAICAgICAgIBAgEBAgEBAgEBAgECAgICAgECAQIBAQIBAgECAgICAgICAgECAQECAQICAgICAgICAgEBAgEBAgEBAgICAgICAgECAQIBAQIBAgECAgICAgIBAgECAQECAQIBAgICAgIBAgIBAgEBAgECAgECAgICAgICAgECAgECAgQIAAAQIKAAAh+QQJZAACACwAAAAAEAAQAAAC55QkIiESIoQQQgghhAhCBCEIgiAIgiAIQiAIgSAIgiAIQiAIgRAEQiAQBAQCgUAQEAQEgYAgIAgIBAKBQBAQCAKBQEAgCAgEAoFAIAgEBAKBIBAQCAQCgUAgEAgCgUBAICAgICAgIBAgEBAgEBAgEBAgECAgICAgECAQIBAQIBAgECAgICAgICAgECAQECAQICAgICAgICAgEBAgEBAgEBAgICAgICAgECAQIBAQIBAgECAgICAgIBAgECAQECAQIBAgICAgIBAgIBAgEBAgECAgECAgICAgICAgECAgECAgQIAAAQIKAAA7)](https://www.rostrum.blog/)
[![License: CC BY-NC-SA 4.0](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
[![Netlify Status](https://api.netlify.com/api/v1/badges/09af3502-e7fc-4abb-b370-ca71214bea50/deploy-status)](https://app.netlify.com/sites/rostrum-blog/deploys)
<!-- badges: end -->
`r emoji("floppy_disk")` Source files for [rostrum.blog](https://www.rostrum.blog/): fun and learning with the R language.
`r emoji("hammer_and_wrench")` Built with [Quarto](https://quarto.org/) and deployed with [Netlify](https://www.netlify.com/).
`r emoji("1234")` There have been `r nrow(posts)` posts on [the blog](https://www.rostrum.blog/) between `r min(posts$publish_date)` (first) to `r max(posts$publish_date)` (latest). `r if (format(today(), "%m-%d") == format(min(posts$publish_date), "%m-%d")) emoji::emoji("balloon")`
`r emoji("date")` That's a post roughly every `r round((as.numeric(max(posts$publish_date) - min(posts$publish_date))) / nrow(posts))` days, or about `r round(((nrow(posts) / (as.numeric(max(posts$publish_date) - min(posts$publish_date)))) * 30), 1)` posts per month.
`r emoji("new")` The latest post: [`r posts$title[1]`](`r posts$link[1]`)`r ifelse(grepl("[!|?|\\.|]$", posts$link[1]), "", ".")`
`r emoji("chart_with_upwards_trend")` Posts over time:
```{r plot-out, fig.height=1, fig.width=10, fig.alt="A 2D chart where each point represents a published blog post on a Y axis of time spanning from 2018 to the present. There are some gaps, but posts have been relatively consistent over time."}
p
```
<details><summary>`r emoji("open_file_folder")` Click to expand a full list of posts</summary>
```{r posts-table}
posts_table <- posts[, "publish_date", drop = FALSE]
posts_table[["title_url"]] <-
paste0("[", posts[["title"]], "](", posts[["link"]], ")")
names(posts_table) <- c("Date", "Title")
kable(posts_table)
```
</details><div>
---
`r emoji("three_o_clock")` Last updated: `r format(Sys.time(), "%Y-%m-%d at %H:%M")`.