hugo_cmd: Run Hugo commands

View source: R/hugo.R

hugo_cmdR Documentation

Run Hugo commands


Wrapper functions to run Hugo commands via system2('hugo', ...).




hugo_available(version = "0.0.0", exact = FALSE)

  local = FALSE,
  args = getOption("blogdown.hugo.args"),
  baseURL = NULL,
  relativeURLs = NULL

  dir = ".",
  force = NA,
  install_hugo = TRUE,
  format = "yaml",
  sample = TRUE,
  theme = "yihui/hugo-lithium",
  hostname = "",
  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())

  kind = "",
  open = interactive(),
  author = getOption(""),
  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 to be passed to system2('hugo', ...), e.g. new_content(path) is basically hugo_cmd(c('new', path)) (i.e. run the command hugo new path).


A version number.


If FALSE, check if the current Hugo version is equal to or higher than the specified version. If TRUE, check if the exact version is available.


Whether to build the site for local preview (if TRUE, all drafts and future posts will also be built).


A character vector of command-line arguments to be passed to hugo, e.g., c("--minify", "--quiet").

baseURL, relativeURLs

Custom values of baseURL and relativeURLs to override Hugo's default and the settings in the site's config file.


The directory of the new site.


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/or ‘README’ files.


Whether to install Hugo automatically if it is not found.


The format of the configuration file, e.g., 'yaml' or 'toml' (the value TRUE will be treated as 'yaml', and FALSE means 'toml'). Note that the frontmatter of the new (R) Markdown file created by new_content() always uses YAML instead of TOML or JSON.


Whether to add sample content. Hugo creates an empty site by default, but this function adds sample content by default.


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 form user/repo@branch). You can also specify a full URL to the zip file or tarball of the theme. If theme = NA, no themes will be installed, and you have to manually install a theme.


Where to find the theme. Defaults to; specify if you wish to use an instance of GitHub Enterprise. You can also specify the full URL of the zip file or tarball in theme, in which case this argument is ignored.


Whether to copy the example in the ‘exampleSite’ directory if it exists in the theme. Not all themes provide example sites.


Whether to keep the empty directories generated by Hugo.


Whether to convert the metadata of all posts to YAML.


Whether to create a Netlify config file ‘netlify.toml’.


Whether to create a ‘.Rprofile’ file. If TRUE, a sample ‘.Rprofile’ will be created. It contains some global options, such as options(blogdown.hugo.version), which makes sure you will use a specific version of Hugo for this site in the future.


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.


The path to the new file under the ‘content’ directory.


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/.


Whether to open the new file after creating it. By default, it is opened in an interactive R session.


The title of the post.


The author of the post.


A character vector of category names.


A character vector of tag names.


The date of the post.


Whether to include the time of the day in the date field of the post. If TRUE, the date 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 the date. 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).


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 file ‘content/post/’. The date of the form YYYY-mm-dd will be prepended if the filename does not start with a date.


The slug of the post. By default (NULL), the slug is generated from the filename by removing the date and filename extension, e.g., if file = 'post/', slug will be hi-there. Set slug = '' if you do not want it.


A function to convert the title to title case. If TRUE, the function is tools::toTitleCase()). This argument is not limited to title case conversion. You can provide an arbitrary R function to convert the title.


If specified (not NULL), the post will be generated under a subdirectory under ‘content/’. It can be a nested subdirectory like ‘post/joe/’.


The filename extension (e.g., ‘.md’, ‘.Rmd’, or ‘.Rmarkdown’). Ignored if file has been specified.


A format to convert to.


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().


  • hugo_cmd(): Run an arbitrary Hugo command.

  • hugo_version(): Return the version number of Hugo if possible, which is extracted from the output of hugo_cmd('version').

  • hugo_available(): Check if Hugo of a certain version (or above if exact = FALSE) is available.

  • hugo_build(): Build a plain Hugo website. Note that the function build_site() first compiles Rmd files, and then calls Hugo via hugo_build() to build the site.

  • new_site(): Create a new site (skeleton) via hugo new site. The directory of the new site should be empty,

  • new_content(): Create a new (R) Markdown file via hugo new (e.g. a post or a page).

  • new_post(): A wrapper function to create a new post under the ‘content/post/’ directory via new_content(). If your post will use R code chunks, you can set ext = '.Rmd' or the global option options(blogdown.ext = '.Rmd') in your ‘~/.Rprofile’. Similarly, you can set options( = '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 via hugo convert.

  • hugo_server(): Start a Hugo server.


The full list of Hugo commands:, and themes:


if (interactive()) blogdown::new_site()

blogdown documentation built on July 9, 2023, 5:28 p.m.

Related to hugo_cmd in blogdown...