Last active
August 16, 2023 21:25
-
-
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)
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
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