The function serve_site()
executes the server command of a static site
generator (e.g., hugo server
or jekyll server
) to start a
local web server, which watches for changes in the site, rebuilds the site if
necessary, and refreshes the web page automatically; stop_server()
stops the web server.
serve_site(..., .site_dir = NULL)stop_server()
Arguments passed to servr::server_config()
(only
arguments host
, port
, browser
, daemon
, and
interval
are supported).
Directory to search for site configuration file. It defaults
to getwd()
, and can also be specified via the global option
blogdown.site_root
.
By default, the server also watches for changes in R Markdown files, and
recompile them automatically if they are modified. This means they will be
automatically recompiled once you save them. If you do not like this
behavior, you may set options(blogdown.knit.on_save = FALSE)
(ideally
in your .Rprofile
). When this feature is disabled, you will have to
manually compile Rmd documents, e.g., by clicking the Knit button in RStudio.
The site generator is defined by the global R option
blogdown.generator
, with the default being 'hugo'
. You may use
other site generators including jekyll
and hexo
, e.g.,
options(blogdown.generator = 'jekyll')
. You can define command-line
arguments to be passed to the server of the site generator via the global R
option blogdown.X.server
, where X
is hugo
,
jekyll
, or hexo
. The default for Hugo is
options(blogdown.hugo.server = c('-D', '-F', '--navigateToChanged'))
(see the documentation of Hugo server at
https://gohugo.io/commands/hugo_server/ for the meaning of these
arguments).