Skip to content

Instantly share code, notes, and snippets.

@matt-dray
Last active August 16, 2023 21:25
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/c66870f36df20660a59b62b874ef6b44 to your computer and use it in GitHub Desktop.
Save matt-dray/c66870f36df20660a59b62b874ef6b44 to your computer and use it in GitHub Desktop.
Rearranging post directory structure for a Quarto blog to mimic the URL path of a {blogdown} blog (for rostrum.blog)
paths <- list.dirs("posts", recursive = FALSE)
for (i in paths) {
from_dir <- i
date_rx <- "\\d{4}-\\d{2}-\\d{2}"
dates <- regexpr(date_rx, basename(i)) |>
regmatches(basename(i), m = _) |>
gsub("-", "/", x = _)
name <- gsub(paste0("posts/", date_rx, "-"), "", i)
to_dir <- file.path(dates, name)
files <- list.files(i, recursive = TRUE)
from_files <- file.path(from_dir, files)
to_files <- file.path(to_dir, files)
dir.create(file.path(to_dir, "resources"), recursive = TRUE)
file.rename(from_files, to_files)
message("Moved ", name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment