Skip to content

Instantly share code, notes, and snippets.

@matt-dray
Last active August 26, 2023 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matt-dray/90ffdbd3759f2d2c382f331477ec7a39 to your computer and use it in GitHub Desktop.
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)
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