blogdown (version 0.9)

hugo_cmd: Run Hugo commands

Description

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

Usage

hugo_cmd(...)

hugo_version()

hugo_build(local = FALSE)

new_site(dir = ".", install_hugo = TRUE, format = "toml", sample = TRUE, theme = "yihui/hugo-lithium", hostname = "github.com", theme_example = TRUE, serve = interactive())

new_content(path, kind = "default", open = interactive())

new_post(title, kind = "default", open = interactive(), author = getOption("blogdown.author"), categories = NULL, tags = NULL, date = Sys.Date(), 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 basically hugo_cmd(c('new', path)) (i.e. run the command hugo new path).

local

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

dir

The directory of the new site. It should be empty or only contain hidden files, RStudio project (*.Rproj) files, LICENSE, and/or README/README.md.

install_hugo

Whether to install Hugo automatically if it is not found.

format

The format of the configuration file. Note that the frontmatter of the new (R) Markdown file created by new_content() always uses YAML instead of TOML.

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 chararacter 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 of the theme. If theme = 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 in theme, 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.

serve

Whether to start a local server to serve the site.

path

The path to the new file under the content directory.

kind

The content type to create.

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.

author

The author of the post.

categories

A character vector of category names.

tags

A character vector of tag names.

date

The date of the post.

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 file content/post/2016-12-28-hello-world.md. The date of the form YYYY-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., if file = 'post/2015-07-23-hi-there.md', slug will be hi-there. Set slug = '' if you do not want it.

title_case

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.

subdir

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

ext

The filename extension (e.g., .md, .Rmd, or .Rmarkdown). Ignored if file 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 of hugo_cmd('version').

  • 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(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 via hugo convert.

  • hugo_server: Start a Hugo server.

References

The full list of Hugo commands: https://gohugo.io/commands, and themes: http://themes.gohugo.io.

Examples

Run this code
# NOT RUN {
library(blogdown)
if (interactive()) new_site()
# }

Run the code above in your browser using DataLab