Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds host to formals of install_theme() and new_site() #265

Merged
merged 6 commits into from Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions R/hugo.R
Expand Up @@ -83,6 +83,8 @@ change_config = function(name, value) {
#' @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.
#' @param hostname Where to find the theme. Defaults to \code{github.com}; specify
#' if you wish to use an instance of GitHub Enterprise.
#' @references The full list of Hugo commands: \url{https://gohugo.io/commands},
#' and themes: \url{http://themes.gohugo.io}.
#' @export
Expand All @@ -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', theme_example = TRUE, serve = interactive(),
hostname = 'github.com'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes a little more sense to move this argument closer to theme (e.g. right after theme).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do!

) {
files = grep('[.]Rproj$', list.files(dir), invert = TRUE, value = TRUE)
files = setdiff(files, c('LICENSE', 'README', 'README.md'))
Expand All @@ -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')
Expand All @@ -135,7 +138,10 @@ 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, theme_example = FALSE, update_config = TRUE, force = FALSE,
hostname = 'github.com'
) {
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'")
Expand All @@ -146,10 +152,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))]
Expand Down
4 changes: 2 additions & 2 deletions man/find_yaml.Rd

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

4 changes: 2 additions & 2 deletions man/html_page.Rd

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

23 changes: 13 additions & 10 deletions man/hugo_cmd.Rd

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

3 changes: 2 additions & 1 deletion man/install_hugo.Rd

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

6 changes: 5 additions & 1 deletion man/install_theme.Rd

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

8 changes: 4 additions & 4 deletions man/shortcode.Rd

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