diff --git a/NEWS.md b/NEWS.md index 912ba9775..979a0e0d8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* New `clean_site(force = TRUE)` for cleaning of `docs/` regardless of whether it was built by pkgdown (#2827). * Links to favicons in page headers were updated to reflect changes to https://realfavicongenerator.net/ (#2804). Favicons should be re-generated by manually removing the `pkgdown/favicon` directory and then running `pkgdown::build_favicons()`. * The language of the site is set from the first `Language:` in the `DESCRIPTION` if it is available and no other language is specified (@jonthegeek, #2808). diff --git a/R/clean.R b/R/clean.R index b8472fb34..6ed83b5b8 100644 --- a/R/clean.R +++ b/R/clean.R @@ -3,10 +3,11 @@ #' Delete all files in `docs/` (except for `CNAME`). #' #' @param quiet If `TRUE`, suppresses a message. +#' @param force If `TRUE`, delete contents of `docs` even if it is not a pkgdown site. #' @inheritParams build_site #' @rdname clean #' @export -clean_site <- function(pkg = ".", quiet = FALSE) { +clean_site <- function(pkg = ".", quiet = FALSE, force = FALSE) { pkg <- as_pkgdown(pkg) @@ -17,7 +18,7 @@ clean_site <- function(pkg = ".", quiet = FALSE) { if (!dir_exists(pkg$dst_path)) return(invisible()) top_level <- dest_files(pkg) - if (length(top_level) > 0) { + if (length(top_level) > 0 && !force) { check_dest_is_pkgdown(pkg) } @@ -60,7 +61,7 @@ check_dest_is_pkgdown <- function(pkg) { 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." + and use {.run pkgdown::clean_site(force = TRUE)} to delete its contents." ) ) } diff --git a/man/clean.Rd b/man/clean.Rd index b6d8b0710..43572143a 100644 --- a/man/clean.Rd +++ b/man/clean.Rd @@ -5,7 +5,7 @@ \alias{clean_cache} \title{Clean site} \usage{ -clean_site(pkg = ".", quiet = FALSE) +clean_site(pkg = ".", quiet = FALSE, force = FALSE) clean_cache(pkg = ".", quiet = FALSE) } @@ -13,6 +13,8 @@ clean_cache(pkg = ".", quiet = FALSE) \item{pkg}{Path to package.} \item{quiet}{If \code{TRUE}, suppresses a message.} + +\item{force}{If \code{TRUE}, delete contents of \code{docs} even if it is not a pkgdown site.} } \description{ Delete all files in \verb{docs/} (except for \code{CNAME}).