Blogdown Workflow
Below is my general workflow for creating a blog post using blogdown if I am building locally. If I am making full use of automation and CI, I utilize something similar to what is described in this outline.
Local Workflow
- Open my project file —
open calex.Rproj
. - Utilize the
Tools -> Addins
to select theNew Post
addin from theblogdown
package. Note that I have updated my global Rprofile —~/.Rprofile
— to include the following:
options(servr.daemon = TRUE,
blogdown.author = "Curtis Alexander",
blogdown.subdir = "blog",
blogdown.ext = ".Rmd")
This will create the needed Rmd
file within content/blog
.
- Below is a screenshot of the completed
New Post
addin form for this particular blog post.
- [Optional] In order to preview locally, utilize
Tools -> Addins
and theServe Site
addin from theblogdown
package. It will runblogdown::serve_site()
. - Write up my post using R Markdown flavored markdown and using RStudio as my IDE.
- [Optional] Cleanup output artifacts using the
Build -> More
button to runClean All
. This in turn executes the commandrmarkdown::clean_site()
which removes the directoriesblogdown
,public
, andstatic/rmarkdown-libs
. - Next I utilize the
Build Website
button within RStudio. If I am already serving the site and taking advantage of theservr
daemon in step 4, then this step is unneeded. TheBuild Website
button executesrmarkdown::render_site(encoding = 'UTF-8')
to convertRmd
files tohtml
.Rmd
files within thecontent/blog
directory are ignored by Hugo as myconfig.toml
is setup to ignore such files —ignoreFiles = ["\\.Rmd$", "\\.Rmarkdown$", "_files$", "_cache$"]
. - [Optional] The blogdown workflow section recommends that one restart their R session and run the command
blogdown::hugo_build()
within the R console. However, I allow netlify to build everything with Hugo so this step is unnecessary. - I then go to the
Git
menu within RStudio and commit and push my changes. I push everything to a repo within Github. - netlify then picks up the changes to the
master
branch of the Github repo that houses my website. The final Hugo command that builds the website is run by netlify. After building, the static site is uploaded to netlify’s CDN. - et voilà!
Caveats
Drafts
The blogdown documentation suggests adding the YAML field draft: true
to the YAML front matter of a blog post in order to set the post as a draft. In order for this to work properly I had to ensure that builddrafts
within my config.toml
file was set to false
.