diff --git a/Hi b/Hi new file mode 100644 index 000000000..1bbbabedf --- /dev/null +++ b/Hi @@ -0,0 +1 @@ +/tmp/RtmpnPKaoc/filec11448ecabfd/README.md diff --git a/R/clean.R b/R/clean.R index 6116f3ae8..6c4ba235d 100644 --- a/R/clean.R +++ b/R/clean.R @@ -15,8 +15,8 @@ clean_site <- function(pkg = ".", quiet = FALSE) { if (!dir_exists(pkg$dst_path)) return(invisible()) - top_level <- dir_ls(pkg$dst_path) - top_level <- top_level[!path_file(top_level) %in% c("CNAME", "dev")] + check_dest_is_pkgdown(pkg) + top_level <- dest_files(pkg) is_dir <- is_dir(top_level) dir_delete(top_level[is_dir]) @@ -24,3 +24,25 @@ clean_site <- function(pkg = ".", quiet = FALSE) { invisible(TRUE) } + +check_dest_is_pkgdown <- function(pkg) { + if (file_exists(path(pkg$dst_path, "pkgdown.yml"))) { + return() + } + + cli::cli_abort(c( + "{.file {pkg$dst_path}} is non-empty and not built by pkgdown", + "!" = "Make sure it contains no important information \\ + and use {.run pkgdown::clean_site()} to delete its contents." + ) + ) +} + +dest_files <- function(pkg) { + if (!dir_exists(pkg$dst_path)) { + character() + } else { + top_level <- dir_ls(pkg$dst_path) + top_level[!path_file(top_level) %in% c("CNAME", "dev")] + } +} diff --git a/R/context.R b/R/context.R index ea30307eb..a0fd58e45 100644 --- a/R/context.R +++ b/R/context.R @@ -5,8 +5,8 @@ section_init <- function(pkg, rstudio_save_all() pkg <- as_pkgdown(pkg, override = override) - if (dir_exists(pkg$dst_path)) { - check_dest_is_pkgdown(pkg) + if (length(dest_files(pkg)) > 0) { + check_dest_is_pkgdown(pkg) } else { init_site(pkg) } @@ -24,25 +24,6 @@ section_init <- function(pkg, pkg } -check_dest_is_pkgdown <- function(pkg) { - top_level <- dir_ls(pkg$dst_path) - top_level <- top_level[!path_file(top_level) %in% c("CNAME", "dev", "deps")] - if (length(top_level) == 0) { - return(invisible()) - } - - if ("pkgdown.yml" %in% path_file(top_level)) { - return(invisible()) - } - - cli::cli_abort(c( - "{.file {pkg$dst_path}} is non-empty and not built by pkgdown", - "!" = "Make sure it contains no important information \\ - and use {.run pkgdown::clean_site()} to delete its contents." - ) - ) -} - local_options_link <- function(pkg, depth, .frame = parent.frame()) { article_index <- article_index(pkg) Rdname <- get_rdname(pkg$topics)