Skip to content

Commit

Permalink
Switch to code @yihui wrote in the PR review (after testing it)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcolladotor committed Feb 27, 2018
1 parent 74a3a51 commit 7b18d1d
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions R/hugo.R
Expand Up @@ -190,20 +190,12 @@ install_theme = function(theme, theme_example = FALSE, update_config = TRUE, for
#' (e.g. a post or a page).
new_content = function(path, kind = 'default', open = interactive()) {
if (missing(kind)) kind = default_kind(path)
## Hugo doesn't work well with non .md file terminations
## So for those cases we will temporarely change the file termination
## to md, run hugo, then change back the file termination.
path_temp = gsub(paste0(tools::file_ext(path), '$'), 'md', path)
file.copy(path, path_temp)
if(path_temp != path) on.exit(unlink(path_temp), add = TRUE)
hugo_cmd(c('new', shQuote(path_temp), c('-k', kind)))

file_temp = content_file(path_temp)
if(path_temp != path) on.exit(unlink(file_temp), add = TRUE)
## If we do this after fixing the file termination it doesn't work
hugo_toYAML(file_temp)
file = gsub('md$', tools::file_ext(path), file_temp)
file.copy(file_temp, file)
path2 = with_ext(path, '.md')
file = content_file(path)
file2 = content_file(path2)
hugo_cmd(c('new', shQuote(path2), c('-k', kind)))
hugo_toYAML(file2)
file.rename(file2, file)
if (open) open_file(file)
file
}
Expand Down

0 comments on commit 7b18d1d

Please sign in to comment.