Skip to content

Commit

Permalink
Write rename funciton
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Jul 25, 2023
1 parent e9baddd commit 07457af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 57 deletions.
57 changes: 0 additions & 57 deletions args-data-details.qmd

This file was deleted.

20 changes: 20 additions & 0 deletions common.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,23 @@ options(
rlang_trace_top_env = rlang::current_env(),
rlang_backtrace_on_error = "none"
)

rename <- function(old, new) {
old_path <- fs::path_ext_set(old, "qmd")
new_path <- fs::path_ext_set(new, "qmd")

fs::file_move(old_path, new_path)
quarto <- readLines("_quarto.yml")
quarto <- gsub(old_path, new_path, quarto, fixed = TRUE)
writeLines(quarto, "_quarto.yml")

old_slug <- paste0("sec-", old)
new_slug <- paste0("sec-", new)

qmd_paths <- dir(pattern = ".qmd$")
qmds <- lapply(qmd_paths, readLines)
qmds <- lapply(qmds, \(lines) gsub(old_slug, new_slug, lines, fixed = TRUE))
purrr:::map2(qmds, qmd_paths, \(lines, path) writeLines(lines, path))

invisible()
}

0 comments on commit 07457af

Please sign in to comment.