Blogdown Workflow
Sep 28, 2017
Curtis Alexander
2 minute read

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

  1. Open my project file — open calex.Rproj.
  2. Utilize the Tools -> Addins to select the New Post addin from the blogdown 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.

  1. Below is a screenshot of the completed New Post addin form for this particular blog post.

  1. [Optional] In order to preview locally, utilize Tools -> Addins and the Serve Site addin from the blogdown package. It will run blogdown::serve_site().
  2. Write up my post using R Markdown flavored markdown and using RStudio as my IDE.
  3. [Optional] Cleanup output artifacts using the Build -> More button to run Clean All. This in turn executes the command rmarkdown::clean_site() which removes the directories blogdown, public, and static/rmarkdown-libs.
  4. Next I utilize the Build Website button within RStudio. If I am already serving the site and taking advantage of the servr daemon in step 4, then this step is unneeded. The Build Website button executes rmarkdown::render_site(encoding = 'UTF-8') to convert Rmd files to html. Rmd files within the content/blog directory are ignored by Hugo as my config.toml is setup to ignore such files — ignoreFiles = ["\\.Rmd$", "\\.Rmarkdown$", "_files$", "_cache$"].
  5. [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.
  6. I then go to the Git menu within RStudio and commit and push my changes. I push everything to a repo within Github.
  7. 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.
  8. 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.