Created
September 10, 2024 01:27
-
-
Save defuneste/48eddf36f9886bedf64bb8e0925b32c3 to your computer and use it in GitHub Desktop.
same idea that blogdown::new_post but way less cool
This file contains hidden or 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
# 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