diff --git a/DESCRIPTION b/DESCRIPTION index 7c336301..a0d7b109 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,6 +7,7 @@ Authors@R: c( person("Beilei", "Bian", role = "ctb"), person("Forest", "Fang", role = "ctb"), person("Hiroaki", "Yutani", role = "ctb"), + person("Ian", "Lyttle", role = "ctb"), person("JJ", "Allaire", role = "ctb"), person("Kevin", "Ushey", role = "ctb"), person(family = "RStudio Inc", role = "cph"), diff --git a/NEWS.md b/NEWS.md index 15f04472..266f00a3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,9 @@ ## NEW FEATURES -- Added a `title_case` argument to the `new_post()` function; if \code{TRUE}, the post title will be converted to title case. See `?blogdown::new_post` for details. +- Added a `title_case` argument to the `new_post()` function; if `TRUE`, the post title will be converted to title case. See `?blogdown::new_post` for details. + +- Added a `hostname` argument to `install_theme()` and `new_site()`, as a complement to the `theme` argument. The default `hostname` is `'github.com'`; if you have access to GitHub Enterprise, you can use this to specify it instead (thanks, @ijlyttle, #264). # CHANGES IN blogdown VERSION 0.5 diff --git a/R/hugo.R b/R/hugo.R index 253b634a..ad27d48e 100644 --- a/R/hugo.R +++ b/R/hugo.R @@ -80,6 +80,8 @@ change_config = function(name, value) { #' after \code{@@}, i.e. \code{theme} can be of the form #' \code{user/repo@@branch}). If \code{theme = NA}, no themes will be #' installed, and you have to manually install a theme. +#' @param hostname Where to find the theme. Defaults to \code{github.com}; specify +#' if you wish to use an instance of GitHub Enterprise. #' @param theme_example Whether to copy the example in the \file{exampleSite} #' directory if it exists in the theme. Not all themes provide example sites. #' @param serve Whether to start a local server to serve the site. @@ -92,7 +94,8 @@ change_config = function(name, value) { #' if (interactive()) new_site() new_site = function( dir = '.', install_hugo = TRUE, format = 'toml', sample = TRUE, - theme = 'yihui/hugo-lithium-theme', theme_example = TRUE, serve = interactive() + theme = 'yihui/hugo-lithium-theme', hostname = 'github.com', theme_example = TRUE, + serve = interactive() ) { files = grep('[.]Rproj$', list.files(dir), invert = TRUE, value = TRUE) files = setdiff(files, c('LICENSE', 'README', 'README.md')) @@ -108,7 +111,7 @@ new_site = function( # remove Hugo's default archetype (I think draft: true is a confusing default) unlink(file.path('archetypes', 'default.md')) if (is.character(theme) && length(theme) == 1 && !is.na(theme)) - install_theme(theme, theme_example) + install_theme(theme, theme_example, hostname = hostname) if (sample) { d = file.path('content', 'blog') @@ -135,7 +138,9 @@ new_site = function( #' @param update_config Whether to update the \code{theme} option in the site #' configurations. #' @export -install_theme = function(theme, theme_example = FALSE, update_config = TRUE, force = FALSE) { +install_theme = function( + theme, hostname = 'github.com', theme_example = FALSE, update_config = TRUE, force = FALSE +) { r = '^([^/]+/[^/@]+)(@.+)?$' if (!is.character(theme) || length(theme) != 1 || !grepl(r, theme)) { warning("'theme' must be a character string of the form 'user/repo' or 'user/repo@branch'") @@ -146,10 +151,9 @@ install_theme = function(theme, theme_example = FALSE, update_config = TRUE, for theme = gsub(r, '\\1', theme) dir_create('themes') in_dir('themes', { + url = sprintf('https://%s/%s/archive/%s.zip', hostname, theme, branch) zipfile = sprintf('%s.zip', basename(theme)) - download2( - sprintf('https://github.com/%s/archive/%s.zip', theme, branch), zipfile, mode = 'wb' - ) + download2(url, zipfile, mode = 'wb') files = utils::unzip(zipfile) zipdir = dirname(files) zipdir = zipdir[which.min(nchar(zipdir))] diff --git a/man/hugo_cmd.Rd b/man/hugo_cmd.Rd index 774cf54b..21c2e28f 100644 --- a/man/hugo_cmd.Rd +++ b/man/hugo_cmd.Rd @@ -18,8 +18,8 @@ hugo_version() hugo_build(local = FALSE) new_site(dir = ".", install_hugo = TRUE, format = "toml", - sample = TRUE, theme = "yihui/hugo-lithium-theme", theme_example = TRUE, - serve = interactive()) + sample = TRUE, theme = "yihui/hugo-lithium-theme", hostname = "github.com", + theme_example = TRUE, serve = interactive()) new_content(path, kind = "default", open = interactive()) @@ -62,6 +62,9 @@ after \code{@}, i.e. \code{theme} can be of the form \code{user/repo@branch}). If \code{theme = NA}, no themes will be installed, and you have to manually install a theme.} +\item{hostname}{Where to find the theme. Defaults to \code{github.com}; specify +if you wish to use an instance of GitHub Enterprise.} + \item{theme_example}{Whether to copy the example in the \file{exampleSite} directory if it exists in the theme. Not all themes provide example sites.} diff --git a/man/install_theme.Rd b/man/install_theme.Rd index cda112a7..a6236601 100644 --- a/man/install_theme.Rd +++ b/man/install_theme.Rd @@ -4,7 +4,8 @@ \alias{install_theme} \title{Install a Hugo theme from Github} \usage{ -install_theme(theme, theme_example = FALSE, update_config = TRUE, force = FALSE) +install_theme(theme, hostname = "github.com", theme_example = FALSE, + update_config = TRUE, force = FALSE) } \arguments{ \item{theme}{A Hugo theme on Github (a chararacter string of the form @@ -13,6 +14,9 @@ after \code{@}, i.e. \code{theme} can be of the form \code{user/repo@branch}). If \code{theme = NA}, no themes will be installed, and you have to manually install a theme.} +\item{hostname}{Where to find the theme. Defaults to \code{github.com}; specify +if you wish to use an instance of GitHub Enterprise.} + \item{theme_example}{Whether to copy the example in the \file{exampleSite} directory if it exists in the theme. Not all themes provide example sites.}