Skip to content

Commit

Permalink
fix #414: indicate if an archetype is a page bundle archetype in the …
Browse files Browse the repository at this point in the history
…"New Post" addin; if it is, add a trailing slash, so I know the actual post to be created is `dir/index.md` but only pass `dir/` to `hugo new`
  • Loading branch information
yihui committed Nov 13, 2019
1 parent 0f66552 commit a93ae13
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: blogdown
Type: Package
Title: Create Blogs and Websites with R Markdown
Version: 0.16.1
Version: 0.16.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
3 changes: 3 additions & 0 deletions NEWS.md
@@ -1,5 +1,8 @@
# CHANGES IN blogdown VERSION 0.17

## BUG FIXES

- The "New Post" addin in RStudio works with page bundle archetypes now (thanks, @malcolmbarrett and @apreshill, #414).

# CHANGES IN blogdown VERSION 0.16

Expand Down
9 changes: 8 additions & 1 deletion R/hugo.R
Expand Up @@ -232,7 +232,9 @@ install_theme = function(


#' @param path The path to the new file under the \file{content} directory.
#' @param kind The content type to create.
#' @param kind The content type to create, i.e., the Hugo archetype. If the
#' archetype is a page bundle archetype, it should end with a slash, e.g.,
#' \code{post/}.
#' @param open Whether to open the new file after creating it. By default, it is
#' opened in an interactive R session.
#' @export
Expand All @@ -243,6 +245,11 @@ new_content = function(path, kind = '', open = interactive()) {
path2 = with_ext(path, '.md')
file = content_file(path)
file2 = content_file(path2)
if (grepl('/$', kind)) {
file2 = file.path(dirname(file2), 'index.md')
path2 = dirname(path2)
kind = sub('/$', '', kind)
}
hugo_cmd(c('new', shQuote(path2), if (kind != '') c('-k', kind)))
hugo_toYAML(file2)
file.rename(file2, file)
Expand Down
3 changes: 2 additions & 1 deletion inst/scripts/new_post.R
Expand Up @@ -9,6 +9,7 @@ xfun::in_dir(blogdown:::site_root(), local({
adir = blogdown:::theme_flag()
adir = if (length(adir) == 4) file.path(adir[2], adir[4], 'archetypes')
adir = c('archetypes', adir)
suff = ifelse(utils::file_test('-d', dir(adir, full.names = TRUE)), '/', '')
shiny::runGadget(
miniUI::miniPage(miniUI::miniContentPanel(
txt_input('title', 'Title', placeholder = 'Post Title'),
Expand All @@ -26,7 +27,7 @@ xfun::in_dir(blogdown:::site_root(), local({
sel_input('tag', 'Tags', meta$tags),
shiny::selectInput(
'kind', 'Archetype', width = '98%',
choices = unique(c('', xfun::sans_ext(dir(adir))))
choices = unique(c('', xfun::sans_ext(paste0(dir(adir), suff))))
),
height = '70px'
),
Expand Down

0 comments on commit a93ae13

Please sign in to comment.