Create Blogs and Websites with R Markdown
knitr::current_input()
doesn't work in inline R expressions in YAML metadata of Rmd posts (thanks, @brshallo, #647).The bookdown config file _bookdown.yml
under the site root directory is recognized now. For example, you can customize the figure label in _bookdown.yml
(thanks, @luofeicq, rbind/yihui#167).
The internal function scan_yaml()
uses cache in the current R session now. Other functions (e.g., find_yaml()
, count_yaml()
, and the "New Post" addin in RStudio) based on this function should be much faster when there are a lot of files to scan for more than once.
For Hugo versions from 0.89.0 to 0.89.2, new_content()
failed to identify new content files if they were created with archetypes (thanks, @maelle, #685).
When creating new posts, YAML metadata inherited from Hugo archetypes could be mangled (thanks, @llrs, #684).
The version
argument of find_hugo()
allows for the prefix v
in the version number now, e.g., find_hugo('v0.89.2')
is equivalent to find_hugo('0.89.2')
. This is also true to other functions that use find_hugo()
, such as remove_hugo()
.
Clarified write_toml()
's error message that Hugo >= 0.37 is required to run this function (thanks, @pssguy, #665).
install_hugo()
did not work for Hugo v0.20.3
.
new_post()
failed to correctly detect the path of the new post with Hugo >= 0.89.3 (thanks, @rcarboni, #667).
Deal with the new security policy in Hugo 0.91.0 by renaming the internal environment variable BLOGDOWN_POST_RELREF
(in the shortcode layouts/shortcodes/blogdown/postref.html
) to HUGO_BLOGDOWN_POST_RELREF
(thanks, @Nitheshnirmal #672, @gergiu #673).
The config file config/_default/config.yaml
(or .toml
) is supported now; blogdown no longer requires that config.yaml
(or .toml
) is under the root directory of the website project. Note that if config.yaml
is present under both the root directory and the config/_default/
directory, blogdown will only recognize the former, and you may want to delete the former if you actually intend to use the latter (thanks, @Athanasiamo @maelle #611, @diegouriarte #598).
install_hugo()
can automatically correct the version number X.Y
to X.Y.0
when X.Y
does not exist but X.Y.0
does. For example, install_hugo('0.87')
will actually install the version 0.87.0
.
Added a global option blogdown.server.first
, which can be specified as a function to run before serving the site. For example, you can sync a JS file to the static/
directory with options(blogdown.server.first = function() { file.copy('../foo/bar.js', './static/js/', overwrite = TRUE) })
each time before you serve the site.
Added arguments arch
and os
to install_hugo()
so that users can choose the architecture and operating system names manually. For example, blogdown::install_hugo(extended = FALSE, arch = '64bit', os = 'FreeBSD')
would install hugo_*_FreeBSD-64bit.tar.gz
(*
denotes a version number) from https://github.com/gohugoio/hugo/releases.
Added a new function hugo_installers()
to print out the information about available Hugo installers of a certain version. This can be helpful when install_hugo()
fails, e.g., the installer for a certain os
or arch
is not available.
new_post()
or the RStudio addin "New Post"), the default post filename will be generated from the post title but it will exclude all non-alphanumeric characters. Previously the exclusion of these characters failed under certain locales (e.g., UTF-8 or a locale that has native support for multibyte characters). Now the default filename will no longer contain non-alphanumeric characters except dashes (thanks, yingjie, https://d.cosx.org/d/422702)..knit.md$
and .utf8.md$
no longer need to be ignored in ignoreFiles
in the Hugo config file now. There is no harm to ignore them anyway. If you have ignored them, you do not need to update your config (#609).The global option blogdown.subdir_fun
can be a function that takes the post title as the input and returns a path of subdirectory under which the new post is to be created via the "New Post" addin in RStudio. The "New Post" addin failed to add the subdirectory defined by this function to the choices of the "Subdirectory" select input if the subdirectory does not exist in the choices, therefore it could not really be used. Now the subdirectory is corrected added, and can be used (thanks, @datawookie, #656).
install_hugo()
stopped working with Hugo v0.89.0 (thanks, @martinolmos, #664).
On Windows, new_post()
may fail to open the new post if the filename contains multibyte characters (thanks, yingjie, https://d.cosx.org/d/422702).
Added a new function check_vercel()
to check the Vercel config vercel.json
, and a new function config_vercel()
to create vercel.json
that contains the Hugo version (thanks, @chuxinyuan, #648). Vercel (https://vercel.com) is service similar to Netlify.
Added an argument time
to new_post()
to optionally include the local time in the date
field of the new post with new_post(time = TRUE)
. The value of this argument can also be set via the global option in .Rprofile
, e.g., options(blogdown.time = TRUE)
(it is FALSE
by default). See the help page ?blogdown::new_post
for more information (thanks, @earfanfan, #625).
The duplicated config/
directory is deleted from the theme now (thanks, @shirdekel, #644).
The categories
and tags
fields in archetypes were not respected when creating new posts (thanks, Conor Neilson, https://stackoverflow.com/q/68879106/559676).
check_config()
now checks for baseURL
that only provides a domain name but lacks the https
(or http
) protocol, e.g., baseURL: example.com/
is typically not a valid URL, but should be https://example.com/
instead (thanks, @apreshill, #616).Fixed a new issue with blogdown::new_site(theme = "wowchemy/starter-hugo-academic")
(#638). To avoid similar issues with the academic theme in the future, we recommend that you consider using the hugo-apero/hugo-apero
theme instead.
install_hugo()
can install the correct version of Hugo on a machine with an ARM processor now (thanks, @r-saikat, #636).
clean_duplicates()
now correctly deletes duplicated .html
file instead of .md
when blogdown.method
option is set to markdown
(thanks, @apreshill, #628).
clean_duplicates()
also correctly deletes unused directories like *_files/header-attrs
associated with .html
output files (thanks, @apreshill, #632).
check_config()
will suggest ignoring the renv
folder and the renv.lock
file in the Hugo config if renv is used in the project (thanks, @solarchemist, #597).
check_content()
will also discover problematic YAML metadata of posts that is not a list (thanks, msmielak, https://stackoverflow.com/q/66857582/559676).
New project menu in RStudio IDE now allows to select for keeping config.toml
(thanks, @ogansser, #606).
The method
argument of build_site()
has been removed (it was defunct in blogdown v1.2). Please set the build method in the global option options(blogdown.method = )
instead.
The use_brew
argument of install_hugo()
has been removed.
check_content()
will ignore renv
folders when looking for Rmd/md files to be checked (thanks, @solarchemist, #597).
The RStudio addin "Update Metadata" does not work when the global option blogdown.rename_file
is not set (thanks, @brshallo, #605).
The RStudio addin "New Post" does not work when the YAML metadata of a post only contains a string. Normally the metadata should be a list (thanks, msmielak, https://stackoverflow.com/q/66857582/559676).
When .Rmd
is not ignored in the ignoreFiles
field in the site config file (this can be detected by blogdown::check_site()
and you should fix it), .Rmd
files may be copied to the public/
directory when building the site via blogdown::build_site()
, which can cause problems when blogdown::serve_site()
is running, i.e., .Rmd
files will be rendered to the rmarkdown::html_document()
format by rmarkdown::render()
. As a result, the corresponding web pages will not be rendered by Hugo but only Pandoc, and they will lose the site style or shortcodes (thanks, @ogansser, #610 #608). Now blogdown::check_site()
should detect this problem and recommend fixes.
Added the argument force
back to install_hugo()
. If the specified version of Hugo has been installed, install_hugo()
will not reinstall it unless force = TRUE
(thanks, @cderv, #575).
The new option options(blogdown.knit.serve_site = FALSE)
can be used to prevent blogdown from starting the web server automatically when the Knit button is clicked in RStudio and the site has not been served yet (thanks, @Athanasiamo, #572). By default, the web server will be started (if not already started) so the page being knitted can be previewed.
Added a new global option blogdown.site_root
, which can be used to specify the root directory of the website. This can be useful when the website source directory is not the root directory of a project but a subdirectory (thanks, @wjakethompson, #581).
Added a new global option blogdown.markdown.format
to allow users to customize Pandoc's Markdown output format. When using the file extension .Rmarkdown
or options(blogdown.method = 'markdown')
, an R Markdown file is first compiled to Markdown. This Markdown file needs to go through another conversion when it contains Markdown features that are only available to Pandoc but not other Markdown renderers such as Hugo/Goldmark, such as citations or fenced Divs. The new global option controls the Pandoc output format. By default, its value is c('gfm', '+footnotes', '+tex_math_dollars')
for Pandoc 2.10.1 and later when the Markdown document contains bibliography or fenced Divs, otherwise it is NULL
. With earlier versions of Pandoc, it will be c('gfm')
only. If you want the conversion to be always performed, you may set this global option to a value that is not NULL
, e.g., options(blogdown.markdown.format = c('gfm', '+footnotes', '+tex_math_dollars', '+smart'))
.
The method
argument of build_site()
is now defunct (it was deprecated in blogdown v1.0), and will be removed in a future version. Please set the build method in the global option options(blogdown.method = )
instead.
The use_brew
argument of install_hugo()
is defunct now, and will be removed in a future version.
The update_hugo()
function is defunct. Please use install_hugo()
instead.
The scripts R/build.R
and R/build2.R
are no longer executed when a document is compiled via the Knit button in RStudio. They will be executed only when building the whole site via build_site()
(e.g., Ctrl/Cmd + Shift + B
in RStudio).
check_config()
will now correctly check for both missing and unneeded values in the ignoreFiles
field in the config file.
When serving the site with blogdown::serve_site()
with 'blogdown.knit.on_save'
option being TRUE
, Rmd files in renv/
or packrat/
folder are now correctly ignored and not rebuilt (#593).
For .Rmarkdown
posts, the Markdown extension tex_math_dollars
should not be used when post-processing the .markdown
output file with Pandoc < v2.10.1 (thanks, @lz100, #578).
The new_post()
function does not work with bundle archetypes (thanks, @maelle, #577).
install_theme()
will now remove the .github/
folder if one exists in the theme repo as it is only useful to the theme developer (#584).
Plots generated from R code chunks in posts cannot be previewed on RStudio Server (thanks, @cderv @datawookie #587).
The error "RStudio is not running" should be suppressed when building the site in a non-interactive R session (thanks, @kcarnold, #596).
The theme gcushen/hugo-academic
is now correctly automatically redirected to wowchemy/starter-academic
with correct default git branch when installing with new_site()
or install_theme()
.
Also try to move config/_default/config.yaml
to the root dir when installing a theme. Previously, only config.toml
was moved (thanks, @andreashandel, #546).
When installing a theme, delete figure
shortcodes that uses http
resources because the figure paths could be mangled on Windows (thanks, @andreashandel, #546).
When clicking the Knit button in RStudio to knit a post, the normal knitting process is shown (such as the progress bar) instead of being suppressed (thanks, @Athanasiamo, #572).
The command blogdown:::preview_site()
is no longer called or displayed in the R console when users click the Knit button after the server has been started (thanks, @apreshill, #543).
The config option ignoreErrors
will be set to "error-remote-getjson"
when running blogdown::serve_site()
. This is to prevent Hugo errors in fetching remote resources such as Tweets (thanks, @earfanfan https://d.cosx.org/d/422065 and dhonda https://stackoverflow.com/q/64601786/559676).
Added new arguments args
, baseURL
, and relativeURLs
to the hugo_build()
function to allow users to pass more command-line arguments to Hugo and adjust the configurations baseURL
and relativeURLs
temporarily when building a site.
Added the ...
argument to build_site()
, to pass more arguments to the hugo_build()
function, e.g., blogdown::build_site(relativeURLs = TRUE)
.
Added a global option blogdown.server.verbose
to print the web server messages in real time when the server is running. Once enabled (via options(blogdown.server.verbose = TRUE)
), you will see messages in the R console like "Change detected, rebuilding site" whenever you make changes to any files (thanks, @apreshill @cderv, #555).
Added a new global option blogdown.protect.math
(defaults to TRUE
) to control whether to protect LaTeX math expressions in a pair of backticks when the post output format is Markdown instead of HTML. The reason to protect math expressions is to avoid the Markdown renderer's treatment of the math content as normal Markdown content, which may mangle the math expressions. If the math expression is protected, it needs to be unprotected later. See https://yihui.org/en/2018/07/latex-math-markdown/ for more information. Note that this option is only relevant to those who use the source format .Rmarkdown
or the build method options(blogdown.method = 'markdown')
(thanks, @bensoltoff #466, @mrkaye97 #567).
bundle_site()
also moves the .html
output files and the *_files/
/*_cache/
directories associated with .Rmd
source posts to page bundles. Previously, only .Rmd
files are moved (thanks, @llrs, #568).
Fixed a bug of install_theme()
when the theme archive contains theme files directly instead of a theme folder (thanks, Stefan Musch, https://stackoverflow.com/q/65702805/559676).
Fixed a bug that causes HTML widgets to fail to render in the Markdown output files with htmltools >= 0.5.1.
Fixed a bug on Windows that causes check_gitignore()
to error when it shouldn't (#571).
rsconnect::deploySite()
(e.g., when you call rmarkdown::publish_site(render = TRUE)
), blogdown::build_site()
will use the argument relativeURLs = TRUE
, to make Hugo generate relative URLs that work with any base URL (note that this depends on how well a specific Hugo theme supports relative URLs).check_netlify()
and check_config()
do not open files anymore in the IDE if no TODO items were found in them (#569).
The internal functions md5sum_filter()
and timestamp_filter()
have been removed. They were renamed to filter_md5sum()
and filter_timestamp()
, respectively, and exported in blogdown 1.0. Please use these exported functions instead if you relied on the internal functions previously.
Added a function check_site()
to provide diagnostics for a website project, which may help reveal potential problems in various places. It runs a series of checks on the config file (config.yaml
or config.toml
), the .gitignore
file, the Hugo installation and version, the netlify.toml
file, and content files. See the help page ?blogdown::check_site
for more info.
Documented and exported the internal function find_hugo()
to find the Hugo executable. If multiple versions of Hugo are installed, find_hugo()
can also find a specific version of Hugo, e.g., blogdown::find_hugo('0.25.1')
. You may use blogdown::find_hugo('all')
to find all possible versions of Hugo currently installed.
Added a function remove_hugo()
to remove Hugo (thanks, @cderv, #504).
The file format .Rmarkdown
supports HTML widgets and citations now, just like the .Rmd
format. If you are not familiar with the .Rmarkdown
format, you may see https://bookdown.org/yihui/blogdown/output-format.html.
Added a function config_netlify()
to help users create the config file netlify.toml
for Netlify. It sets the build
commands properly for different deploy contexts, and writes the local Hugo version to the config file, so make sure Netlify uses the same version of Hugo as your local environment. See the help page ?blogdown::config_netlify
for details.
Added a function config_Rprofile()
to help create or modify the .Rprofile
file. In particular, it will try to set the option blogdown.hugo.version
in it, if the option has not been set. See the help page ?blogdown::config_Rprofile
for details.
Added an argument netlify = TRUE
to new_site()
to create netlify.toml
by default.
Added an argument .Rprofile = TRUE
to new_site()
to create the .Rprofile
file by default. This file contains a few sample global options that could affect blogdown's behavior, e.g., the option blogdown.hugo.version
is set to the current Hugo version, so that a site will not be affected by future Hugo updates and will always use the fixed version of Hugo. This file is provided so that users are better aware of some of these options, and can change them if they want.
Exported the function filter_newfile()
, which returns paths of source files that have not been knitted (i.e., their output files do not exist).
The build_rmd
argument of build_site()
can take a function as its value now (thanks, Tyler Smith). The function is expected to take a vector of paths of all R Markdown files under the content/
directory, and returns a vector of paths of R Markdown files to be built. This argument can also take one of the aliases "timestamp"
, which is equivalent to blogdown::filter_timestamp
, newfile
(equivalent to blogdown::filter_newfile
), and "md5sum"
(equivalent to blogdown::filter_md5sum
). For example, blogdown::build_site(build_rmd = "timestamp")
means to build all R Markdown files if they are older than their output files (by comparing modification times).
When opening a blogdown website project in RStudio, you can specify a number of files to be automatically opened every time via the global option blogdown.initial_files
in your .Rprofile
. This option can take a vector of file paths, e.g., options(blogdown.initial_files = c('config.yaml', '.Rprofile', 'content/post/my-first-post/index.Rmd'))
(files that do not exist will be ignored). Alternatively, this option can take a function that returns a vector of file paths, e.g., options(blogdown.initial_files = blogdown:::initial_files)
.
Added a new argument .site_dir
to serve_site()
, so users will be able to specify the site root directory (thanks, @Bijaelo, #527).
Added a new argument force
to new_site()
to allow users to create a new site under a nonempty directory with force = TRUE
if they are sure the site can be safely created under the directory (i.e., Hugo will not possibly override existing files). In an interactive R session, it will ask users if they want force = TRUE
when the directory is not empty.
install_hugo()
no longer installs Hugo via Homebrew by default on macOS, but just downloads binaries from Hugo's Github releases, which gives you a stable version of Hugo. The use_brew
argument of install_hugo()
has been deprecated. Installing Hugo via Homebrew often leads to accidental updates of Hugo, which may break your existing sites. If you must install Hugo via Homebrew and want to fix its version, you can run brew pin hugo
, so it will not be updated by accident in the future (e.g., via brew upgrade
).
By default, install_hugo()
installs Hugo to ~/.local/share/Hugo
on Linux now, instead of ~/bin
.
install_hugo()
installs the hugo
executable to a directory with the directory name being the Hugo version number, e.g., ~/Library/Application Support/Hugo/0.76.5
, or ~/.local/share/Hugo/0.25.1
. This makes it possible to install multiple versions of Hugo on the same computer.
When starting to serve the site, serve_site()
will compile Rmd files that do not have output files initially (thanks, Hannah Wang, https://stackoverflow.com/q/64420476/559676).
The default value of the global option blogdown.serve_site.startup
was changed from TRUE
to FALSE
, meaning that the site will not by served by default when the RStudio project is first opened. If you want the previous behavior, you may set options(blogdown.serve_site.startup = TRUE)
in your .Rprofile
.
The method
argument of build_site()
was deprecated. The build method can only be specified via the global option blogdown.method
now, e.g., you may set options(blogdown.method = 'custom')
in .Rprofile
. A new possible build method named markdown
was added. When you set options(blogdown.method = 'markdown')
, .Rmd
posts will be compiled to .md
(by default, they are compiled to .html
since the default option is blogdown.method = 'html'
). This provides another way to render R Markdown to Markdown instead of HTML. Previously, the only way to achieve this was to use the file extension .Rmarkdown
(this way still works).
The function update_hugo()
and the argument force
of install_hugo()
have been deprecated. If you want to update Hugo to a newer version, you can call install_hugo()
and specify a desired version.
The functions md5sum_filter
and timestamp_filter
have been renamed to filter_md5sum
and filter_timestamp
, respectively.
serve_site()
fails to start the server when the config file contains a baseURL
value that includes a subpath in it (thanks, @giabaio #254, @ShixiangWang #494).
serve_site()
and hugo_build()
fail to resolve URLs when relativeURLs
is configured to true
(thanks, @TianyiShi2001, #506).
The "Insert Image" addin works with posts that are index pages of leaf bundles now. The images are added to the images/
folder under the post directory by default instead of the top-level static/
directory (thanks, @amssljc, #499).
For a post that is the index page of a bundle, its images could not be displayed when the post content is displayed on other pages such as the home page (thanks, @andremrsantos #501, Fabio A. Cruz Sanchez https://stackoverflow.com/q/65097597/559676).
The _files/
and _cache/
folders are not correctly moved for index pages of leaf bundles when the filename of an index page contains a language code such as index.en.Rmd
(thanks, @cderv, #500).
install_hugo()
could not install the extended version of Hugo that was downloaded manually, e.g., blogdown::install_hugo('~/Downloads/hugo_extended_0.78.2_Linux-64bit.tar.gz')
would fail (thanks, Stuart, https://stackoverflow.com/q/64962659/559676).
new_post(date = "")
or new_post(date = NULL)
failed to work. In both cases, it should create a post without the date
field in the YAML metadata (thanks, Caleb Stevens, https://stackoverflow.com/q/65067164/559676).
new_site()
no longer shows Hugo messages on Windows (#532).
new_site()
can figure out the default branch name of a theme repo now, instead of assuming the master
branch is the default (thanks, @c1au6i0, #541).
For new_site(to_yaml = TRUE)
, it will also convert config.toml
to config.yaml
.
The default value of the serve
argument in new_site()
was changed from TRUE
to "ask"
in an interactive R session, which means it will ask if users want to serve the site after creating it.
The default value for the format
argument of new_site()
was changed from toml
to yaml
, which means it will generate config.yaml
instead of config.toml
by default.
new_site()
will create two sample scripts R/build.R
and R/build2.R
(they can be deleted if you don't need them). See the help page ?blogdown::build_site
for their meanings.
Autocomplete is supported for the names of important global options when typing inside options()
in RStudio, e.g., when typing options(blogdown.au)
, RStudio will show the candidate blogdown.author
.
read_toml()
and toml2yaml()
will try to preserve the original order of fields in the TOML data, instead of using the alphabetical order.
When clicking the "Build Website" button in RStudio, it will no longer open the index.html
file in the generated site folder, but emit a message telling users that this folder needs to be served before the web pages can be correctly previewed (#522).
For Jekyll sites, the arguments --watch
, --incremental
, and --livereload
are passed to jekyll serve
by default. These arguments can be set via the global R option blogdown.jekyll.server
.
The meta variable link-citations
is set to true
for the pandoc_args
argument of blogdown::html_page()
, so that links can be generated on citation items by default.
The internal function Rscript()
was removed and it is publicly available in the xfun package now. If you need this function, please use xfun::Rscript()
instead.
Removed internal functions is_windows()
, is_osx()
, and is_linux()
. They are available in the xfun package now (note that is_osx()
has become xfun::is_macos()
).