Last active
August 26, 2023 18:23
-
-
Save matt-dray/90ffdbd3759f2d2c382f331477ec7a39 to your computer and use it in GitHub Desktop.
Create a redirects file from {blogdown}-style URL paths to Quarto-style (for rostrum.blog)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
redirect_to <- paste0("/", list.dirs("posts", recursive = FALSE)) | |
date_rx <- "\\d{4}-\\d{2}-\\d{2}" | |
date_portion <- regexpr(date_rx, redirect_to) |> | |
regmatches(redirect_to, m = _) |> | |
gsub("-", "/", x = _) | |
name_portion <- gsub(paste0("posts/", date_rx, "-"), "", redirect_to) | |
redirect_from <- paste0("/", date_portion, name_portion) | |
mapping <- paste0(paste(redirect_from, redirect_to, sep = " "), collapse = "\n") | |
cat(mapping, file = "~/Desktop/_redirects") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment