Wrapper functions to run Hugo commands via system2('hugo',
...)
.
Usage
hugo_cmd(...)
hugo_version()
hugo_available(version = "0.0.0", exact = FALSE)
hugo_build(
local = FALSE,
args = getOption("blogdown.hugo.args"),
baseURL = NULL,
relativeURLs = NULL
)
new_site(
dir = ".",
force = NA,
install_hugo = TRUE,
format = "yaml",
sample = TRUE,
theme = "yihui/hugo-lithium",
hostname = "github.com",
theme_example = TRUE,
empty_dirs = FALSE,
to_yaml = TRUE,
netlify = TRUE,
.Rprofile = TRUE,
serve = if (interactive()) "ask" else FALSE
)
new_content(path, kind = "", open = interactive())
new_post(
title,
kind = "",
open = interactive(),
author = getOption("blogdown.author"),
categories = NULL,
tags = NULL,
date = Sys.Date(),
time = getOption("blogdown.time", FALSE),
file = NULL,
slug = NULL,
title_case = getOption("blogdown.title_case"),
subdir = getOption("blogdown.subdir", "post"),
ext = getOption("blogdown.ext", ".md")
)
hugo_convert(to = c("YAML", "TOML", "JSON"), unsafe = FALSE, ...)
hugo_server(host, port)
Arguments
- ...
Arguments to be passed to
system2('hugo', ...)
, e.g.new_content(path)
is basicallyhugo_cmd(c('new', path))
(i.e. run the commandhugo new path
).- version
A version number.
- exact
If
FALSE
, check if the current Hugo version is equal to or higher than the specifiedversion
. IfTRUE
, check if the exact version is available.- local
Whether to build the site for local preview (if
TRUE
, all drafts and future posts will also be built).- args
A character vector of command-line arguments to be passed to
hugo
, e.g.,c("--minify", "--quiet")
.- baseURL, relativeURLs
Custom values of
baseURL
andrelativeURLs
to override Hugo's default and the settings in the site's config file.- dir
The directory of the new site.
- force
Whether to create the site in a directory even if it is not empty. By default,
force = TRUE
when the directory only contains hidden, RStudio project (*.Rproj
),LICENSE
, and/orREADME
files.- install_hugo
Whether to install Hugo automatically if it is not found.
- format
The format of the configuration file, e.g.,
'yaml'
or'toml'
(the valueTRUE
will be treated as'yaml'
, andFALSE
means'toml'
). Note that the frontmatter of the new (R) Markdown file created bynew_content()
always uses YAML instead of TOML or JSON.- sample
Whether to add sample content. Hugo creates an empty site by default, but this function adds sample content by default.
- theme
A Hugo theme on Github (a character string of the form
user/repo
, and you can optionally specify a GIT branch or tag name after@
, i.e.theme
can be of the formuser/repo@branch
). You can also specify a full URL to the zip file or tarball of the theme. Iftheme = NA
, no themes will be installed, and you have to manually install a theme.- hostname
Where to find the theme. Defaults to
github.com
; specify if you wish to use an instance of GitHub Enterprise. You can also specify the full URL of the zip file or tarball intheme
, in which case this argument is ignored.- theme_example
Whether to copy the example in the
exampleSite
directory if it exists in the theme. Not all themes provide example sites.- empty_dirs
Whether to keep the empty directories generated by Hugo.
- to_yaml
Whether to convert the metadata of all posts to YAML.
- netlify
Whether to create a Netlify config file
netlify.toml
.- .Rprofile
Whether to create a
.Rprofile
file. IfTRUE
, a sample.Rprofile
will be created. It contains some global options, such asoptions(blogdown.hugo.version)
, which makes sure you will use a specific version of Hugo for this site in the future.- serve
Whether to start a local server to serve the site. By default, this function will ask you in an interactive R session if you want to serve the site.
- path
The path to the new file under the
content
directory.- kind
The content type to create, i.e., the Hugo archetype. If the archetype is a page bundle archetype, it should end with a slash, e.g.,
post/
.- open
Whether to open the new file after creating it. By default, it is opened in an interactive R session.
- title
The title of the post.
The author of the post.
- categories
A character vector of category names.
A character vector of tag names.
- date
The date of the post.
- time
Whether to include the time of the day in the
date
field of the post. IfTRUE
, thedate
will be of the format %Y-%m-%dT%H:%M:%S%z (e.g., 2001-02-03T04:05:06-0700). Alternatively, it can take a character string to be appended to thedate
. It can be important and helpful to include the time in the date of a post. For example, if your website is built on a server (such as Netlify or Vercel) and your local timezone is ahead of UTC, your local date may be a future date on the server, and Hugo will not build future posts by default (unless you use the-F
flag).- file
The filename of the post. By default, the filename will be automatically generated from the title by replacing non-alphanumeric characters with dashes, e.g.
title = 'Hello World'
may create a filecontent/post/2016-12-28-hello-world.md
. The date of the formYYYY-mm-dd
will be prepended if the filename does not start with a date.- slug
The slug of the post. By default (
NULL
), the slug is generated from the filename by removing the date and filename extension, e.g., iffile = 'post/2020-07-23-hi-there.md'
,slug
will behi-there
. Setslug = ''
if you do not want it.- title_case
A function to convert the title to title case. If
TRUE
, the function istools::toTitleCase()
). This argument is not limited to title case conversion. You can provide an arbitrary R function to convert the title.- subdir
If specified (not
NULL
), the post will be generated under a subdirectory undercontent/
. It can be a nested subdirectory likepost/joe/
.- ext
The filename extension (e.g.,
.md
,.Rmd
, or.Rmarkdown
). Ignored iffile
has been specified.- to
A format to convert to.
- unsafe
Whether to enable unsafe operations, such as overwriting Markdown source documents. If you have backed up the website, or the website is under version control, you may try
unsafe = TRUE
.- host, port
The host IP address and port; see
servr::server_config()
.
Functions
hugo_cmd()
: Run an arbitrary Hugo command.hugo_version()
: Return the version number of Hugo if possible, which is extracted from the output ofhugo_cmd('version')
.hugo_available()
: Check if Hugo of a certain version (or above ifexact = FALSE
) is available.hugo_build()
: Build a plain Hugo website. Note that the functionbuild_site()
first compiles Rmd files, and then calls Hugo viahugo_build()
to build the site.new_site()
: Create a new site (skeleton) viahugo new site
. The directory of the new site should be empty,new_content()
: Create a new (R) Markdown file viahugo new
(e.g. a post or a page).new_post()
: A wrapper function to create a new post under thecontent/post/
directory vianew_content()
. If your post will use R code chunks, you can setext = '.Rmd'
or the global optionoptions(blogdown.ext = '.Rmd')
in your~/.Rprofile
. Similarly, you can setoptions(blogdown.author = 'Your Name')
so that the author field is automatically filled out when creating a new post.hugo_convert()
: A wrapper function to convert source content to different formats viahugo convert
.hugo_server()
: Start a Hugo server.
References
The full list of Hugo commands: https://gohugo.io/commands, and themes: https://themes.gohugo.io.
Examples
blogdown::hugo_available("1.2.3")
#> [1] FALSE
if (interactive()) blogdown::new_site()