Skip to content

Commit

Permalink
dir() and dir(full.names = TRUE) can return paths of different orders…
Browse files Browse the repository at this point in the history
…, e.g.,

> dir(adir)
[1] "default.md" "Rmd"

> dir(adir, full.names = TRUE)
[1] "archetypes/Rmd" "themes/hugo-lithium/archetypes/default.md"

so we need to use dir(full.names = TRUE) and then basename() to get the base filenames, instead of using dir()
  • Loading branch information
yihui committed Feb 3, 2021
1 parent 4aa6ffe commit 46e0b3c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions inst/scripts/new_post.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ lang = blogdown:::get_lang()
adir = blogdown:::theme_dir()
adir = if (length(adir)) file.path(adir, 'archetypes')
adir = c('archetypes', adir)
suff = ifelse(utils::file_test('-d', dir(adir, full.names = TRUE)), '/', '')
adir = dir(adir, full.names = TRUE)
adir = paste0(basename(adir), ifelse(utils::file_test('-d', adir), '/', ''))

shiny::runGadget(
miniUI::miniPage(miniUI::miniContentPanel(
txt_input('title', 'Title', placeholder = 'Post Title'),
Expand All @@ -28,7 +30,7 @@ shiny::runGadget(
sel_input('tag', 'Tags', meta$tags),
shiny::selectInput(
'kind', 'Archetype', width = '98%',
choices = unique(c('', xfun::sans_ext(paste0(dir(adir), suff))))
choices = unique(c('', adir))
),
height = '70px'
),
Expand Down

0 comments on commit 46e0b3c

Please sign in to comment.