serve_site: Live preview a site

View source: R/serve.R

serve_siteR Documentation

Live preview a site

Description

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.

Usage

serve_site(..., .site_dir = NULL)

stop_server()

Arguments

...

Arguments passed to servr::server_config() (only arguments host, port, browser, daemon, and interval are supported).

.site_dir

Directory to search for site configuration file. It defaults to getwd(), and can also be specified via the global option blogdown.site_root.

Details

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

Note

For the Hugo server, the argument --navigateToChanged is used by default, which means when you edit and save a source file, Hugo will automatically navigate the web browser to the page corresponding to this source file (if the page exists). However, due to a Hugo bug (https://github.com/gohugoio/hugo/issues/3811), this automatic navigation may not always work for R Markdown posts, and you may have to manually refresh your browser. It should work reliably for pure Markdown posts, though.


rstudio/blogdown documentation built on Feb. 5, 2024, 10:09 p.m.