newpost
is a simple, one-function package for Quarto
blogs that (slightly) speeds up the process of creating a new blog post
by creating a new folder and index.qmd file for a post. It uses the
RStudio IDE’s API, so you do need to be running RStudio for this to work
properly.
WARNING: This package will create folders and files on your system!
The newpost()
function has one required argument: the
headline for your post. If you run
newpost("Welcome to my blog!")
on March 8, 2025, it will
create a folder 2025-03-08-welcome-to-my-blog
in your
blog’s posts directory, and also create an index.qmd file in that new
directory with “Welcome to my blog!” as the YAML title. There are
optional arguments for description, author, and categories. Categories
should be a single comma-separated string and not a character
vector, such as “General, Community”.
I suggest using a code snippet for this function, which gives you
fill-in-the-blank code. I use this snippet, which I addded to my
snippets with the usethis::edit_rstudio_snippets()
function:
snippet qnp
newpost::newpost("${1:headline}", "${2:description}", "${3:categories}", author = "Sharon Machlis")
Note that there needs to be a tab before newpost::newpost, not spaces.
When I type qnp
and hit the tab key, I see this in my
console:
newpost::newpost("headline", "description", "categories", author = "Sharon Machlis")
with the cursor having jumped to headline
as a variable.
After filling in the headline spot, you can tab to description and then
tab again to categories.
If you want the date to be something besides the current date –
perhaps you are creating a post you plan on publishing sometime in the
future – you can also set the_date to be something like
Sys.Date() + 1
for tomorrow.
Categories
While it’s easy to check available blog categories by going to your
blog’s home page, you can stay in your R console and run the
see_cats()
function. It will check the blog home page for
you and print out the vector of available categories.
see_cats()
takes one argument, the full blog URL
including https://
. You can set an R environment variable
BLOG_URL
to your full blog URL so you don’t have to enter
it manually into the function.