hugodown is an experimental package that aims to facilitate the use of RMarkdown and hugo together. It’s similar to blogdown, but is focussed purely on Hugo websites, and enforces a stricter partitioning of roles: hugodown is responsible for transforming
.md, and hugo is responsible for transforming
It only re-runs your R code when you explicitly ask for it (by knitting the post). This makes hugodown considerably easier to use for long-running blogs and blogs with multiple contributors.
Local previews are pinned to a specific version of hugo. This makes it easier to work with multiple blogs, and protects your from hugo <-> theme version incompatibilities.
It provides support for getting started with a limited number of themes, automatically making needed tweaks to ensure that html widgets, syntax highlighting, and math display work out of the box.
It is more opinonated about hugo configuration; see
vignette("config") for details.
Otherwise, it strives to provide the best of blogdown’s two Rmarkdown variants:
|Runs R code||y||y||y|
|Table of contents||y||n||y|
The only current limitation is that it does not support within page cross-references to figures, tables, and equations.
hugodown isn’t available from CRAN yet (and might never be), but you can install the development version from GitHub with:
The key to using hugodown is to put
output: hugodown::md_document() in the YAML metadata of your
.Rmd files. Then knitting the file will generate a
.md file designed to work well with hugo. The rest of hugodown just makes your life a little easier:
hugo_start() will automatically start a hugo server in the background, automatically previewing your site as you update it.
To knit an
.Rmd post, you can use the Knit button to knit to the correct output format. You can also use the keyboard shortcut
Cmd+Shift+K (Mac) or
site_outdated() lists all
.Rmd files that need to be re-rendered (i.e. they have changed since the last time their
.md was rendered).
With hugodown, knitting an individual post and building the site are two separate processes. A good workflow when working with an existing Hugo site in RStudio is to open the site’s
.Rproj file, use
hugo_start(), then add or edit your posts. Because the hugo server will only add
.Rmd content to your site preview after knitting, you’ll need to use the keyboard shortcut to knit first.
To use citations in a blog post, just provide a
bibliography in the YAML metadata. If you want to use footnotes for citations (a style that generally works well in blogs), you’ll need to find a footnote style CSL file (e.g.
chicago-fullnote-bibliography.csl, and use the following YAML header.
Make sure your post archetype has extension
.Rmd and includes
output: hugodown::md_document in the YAML. The post archetype should typically be
index.Rmd from the root of your site.
Ensure that hugo is configured as described in