build_site | R Documentation |
Build the site through Hugo, and optionally (re)build R Markdown files.
build_site(local = FALSE, run_hugo = TRUE, build_rmd = FALSE, ...)
local |
Whether to build the website locally. This argument is passed to
|
run_hugo |
Whether to run |
build_rmd |
Whether to (re)build R Markdown files. By default, they are
not built. See ‘Details’ for how |
... |
Other arguments to be passed to |
You can use serve_site()
to preview your website locally, and
build_site()
to build the site for publishing. However, if you use a
web publishing service like Netlify, you do not need to build the site
locally, but can build it on the cloud. See Section 1.7 of the blogdown
book for more information:
https://bookdown.org/yihui/blogdown/workflow.html.
For R Markdown posts, there are a few possible rendering methods: html
(the default), markdown
, and custom
. The method can be set in
the global option blogdown.method
(usually in the
‘.Rprofile’ file), e.g., options(blogdown.method =
"custom")
.
For the html
method, ‘.Rmd’ posts are rendered to ‘.html’
via rmarkdown::render()
, which means Markdown is
processed through Pandoc. For the markdown
method, ‘.Rmd’ is
rendered to ‘.md’, which will typically be rendered to HTML later by the
site generator such as Hugo.
For all rendering methods, a custom R script ‘R/build.R’ will be
executed if you have provided it under the root directory of the website
(e.g. you can compile Rmd to Markdown through
knitr::knit()
and build the site via
hugo_cmd()
). The custom
method means it is entirely up
to this R script how a website is rendered. The script is executed via
command line Rscript "R/build.R"
, which means it is executed in a
separate R session. The value of the argument local
is passed to the
command line (you can retrieve the command-line arguments via
commandArgs(TRUE)
). For other rendering methods, the R script
‘R/build2.R’ (if exists) will be executed after Hugo has built the site.
This can be useful if you want to post-process the site.
When build_rmd = TRUE
, all Rmd files will be (re)built. You can set
the global option blogdown.files_filter
to a function to determine
which Rmd files to build when build_rmd = TRUE
. This function takes a
vector of Rmd file paths, and should return a subset of these paths to be
built. By default, options(blogdown.files_filter = identity
.
You can use blogdown::filter_newfile
, which means to build new
Rmd files that have not been built before, or
blogdown::filter_timestamp
to build Rmd files if their time
stamps (modification time) are newer than their output files, or
blogdown::filter_md5sum
, which is more robust in determining if
an Rmd file has been modified (hence needs to be rebuilt).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.