Skip to content

Instantly share code, notes, and snippets.

@defuneste
Created September 10, 2024 01:27
Show Gist options
  • Save defuneste/48eddf36f9886bedf64bb8e0925b32c3 to your computer and use it in GitHub Desktop.
Save defuneste/48eddf36f9886bedf64bb8e0925b32c3 to your computer and use it in GitHub Desktop.
same idea that blogdown::new_post but way less cool
# Assumption is that you run it at the root of the project
# waiting https://github.com/quarto-dev/quarto-cli/issues/3917 to ditch
new_post <- function(title, author = "default") {
t <- tolower(gsub(" ", "_", title, fixed = TRUE))
dir_path <- paste("posts",
paste(Sys.Date(), t, sep = "_"),
sep = "/")
# lazy
system(sprintf("mkdir -p %s", dir_path))
my_index_qmd <- paste(dir_path, "index.qmd", sep = "/")
if(file.exists(my_index_qmd)) {
stop(sprintf("%s exist!", my_index_qmd), call. = FALSE)
} else {
file.create(paste(dir_path, "index.qmd", sep = "/"))
con <- file(my_index_qmd)
writeLines(c("---",
sprintf("title: '%s'", title),
sprintf("author: '%s'", author),
"categories:",
"---"
), con)
close(con)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment