-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.qmd
70 lines (59 loc) · 2.09 KB
/
index.qmd
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
---
title: "rdiscovery"
subtitle: A blog by Layal Christine Lettry
listing:
contents: posts
feed: true
sort: "date desc"
type: default
categories: cloud
sort-ui: [title, date]
filter-ui: [title, date]
page-layout: full
title-block-banner: true
image: profile.jpg
---
```{r write-redirects}
#| echo: false
# list names of post folders
posts <- list.dirs(
path = here::here("posts"),
full.names = FALSE,
recursive = FALSE
)
# extract the slugs
slugs <- gsub("^.*_", "", posts)
# lines to insert to a netlify _redirect file
post_redirects <- paste0("/", slugs, " ", "/posts/", posts)
# function to extract post categories from index.qmd files
get_post_categories <- function(post) {
file <- here::here("posts", post) |> fs::path("index.qmd")
if(!fs::file_exists(file)) {
return(character(0))
}
file |>
readLines() |>
stringr::str_subset("^categories:") |>
stringr::str_extract("\\[.*\\]") |>
stringr::str_remove_all("[\\[\\]]") |>
stringr::str_split(", ") |>
unlist()
}
# extract the categories
categories <- purrr::map(posts, get_post_categories) |>
unlist() |>
unique()
# extract categories in nice form
keys <- categories |>
stringr::str_to_lower() |>
stringr::str_replace_all(" ", "-")
# extract categories in ugly form
values <- categories |>
stringr::str_replace_all(" ", "%20")
# category redirects
category_redirects <- paste0("/category/", keys, " ", "/#category=", values)
# write the _redirect file
writeLines(c(post_redirects, category_redirects), here::here("_site", "_redirects"))
```
<!-- Mastodon verification -->
<a rel="me" style="display:none" href="https://fosstodon.org/@layal">Hidden link used to verify my account on fosstodon.org</a> <a rel="me" style="display:none" href="https://linkedin.com/in/layal-christine-lettry-529b4471/">Hidden link used to verify my account on LinkedIn</a> <a rel="me" style="display:none" href="https://twitter.com/LettryL">Hidden link used to verify my account on Twitter</a> <a rel="me" style="display:none" href="https://github.com/Layalchristine24">Hidden link used to verify my account on GitHub</a>