Skip to content

Commit

Permalink
close #391: check the minimal Hugo version specified by the theme, an…
Browse files Browse the repository at this point in the history
…d update Hugo if necessary
  • Loading branch information
yihui committed Jun 26, 2019
1 parent 570d7e7 commit b5e310d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: blogdown
Type: Package
Title: Create Blogs and Websites with R Markdown
Version: 0.13.1
Version: 0.13.2
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
person("Beilei", "Bian", role = "ctb"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# CHANGES IN blogdown VERSION 0.14

## NEW FEATURES

- `new_site()` and `install_theme()` will check the minimal Hugo version specified by the theme, and automatically update Hugo if the current installed version of Hugo is not sufficient (thanks, @apreshill, #391).

# CHANGES IN blogdown VERSION 0.13

Expand Down
11 changes: 10 additions & 1 deletion R/hugo.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,12 @@ new_site = function(
#' before you try \code{force = TRUE}.
#' @param update_config Whether to update the \code{theme} option in the site
#' configurations.
#' @param update_hugo Whether to automatically update Hugo if the theme requires
#' a higher version of Hugo than the existing version in your system.
#' @export
install_theme = function(
theme, hostname = 'github.com', theme_example = FALSE, update_config = TRUE, force = FALSE
theme, hostname = 'github.com', theme_example = FALSE, update_config = TRUE,
force = FALSE, update_hugo = TRUE
) {
r = '^([^/]+/[^/@]+)(@.+)?$'
r_zip = "\\.zip$"
Expand Down Expand Up @@ -202,6 +205,12 @@ install_theme = function(
'and at least take a look at the config file config.toml of the example site, ',
'because not all Hugo themes work with any config files.', call. = FALSE
)
# check the minimal version of Hugo required by the theme
if (update_hugo && file.exists(theme_cfg <- file.path(zipdir, 'theme.toml'))) {
if (!is.null(minver <- parse_toml(theme_cfg)[['min_version']])) {
if (hugo_version() < minver) update_hugo()
}
}
newdir = sub(tmpdir, '.', zipdir, fixed = TRUE)
newdir = gsub('-[a-f0-9]{12,40}$', '', newdir)
newdir = gsub(sprintf('-%s$', branch), '', newdir)
Expand Down
5 changes: 4 additions & 1 deletion man/install_theme.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b5e310d

Please sign in to comment.