diff --git a/NAMESPACE b/NAMESPACE index b5c4203db..6e2bdfb2f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -125,6 +125,7 @@ export(build_site) export(build_site_github_pages) export(build_tutorials) export(check_pkgdown) +export(clean_cache) export(clean_site) export(data_template) export(deploy_site_github) diff --git a/NEWS.md b/NEWS.md index 01a508bd7..6bd90a976 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* New `clean_cache()` function removes the contents of the cache directory (#2718). * pkgdown now depends on R >= 4.0.0 (#2714) # pkgdown 2.1.0 diff --git a/R/clean.R b/R/clean.R index 8f781e54e..b8472fb34 100644 --- a/R/clean.R +++ b/R/clean.R @@ -4,6 +4,7 @@ #' #' @param quiet If `TRUE`, suppresses a message. #' @inheritParams build_site +#' @rdname clean #' @export clean_site <- function(pkg = ".", quiet = FALSE) { @@ -27,6 +28,30 @@ clean_site <- function(pkg = ".", quiet = FALSE) { invisible(TRUE) } +#' Clean cache +#' +#' Delete all files in the pkgdown cache directory. +#' +#' @rdname clean +#' @export +clean_cache <- function(pkg = ".", quiet = FALSE) { + + pkg <- as_pkgdown(pkg) + cache_path <- tools::R_user_dir("pkgdown", "cache") + + if (dir_exists(cache_path)) { + if (!quiet) { + cli::cli_inform( + "Cleaning {.pkg {pkg$package}} cache files from {.path {cache_path}}" + ) + } + + dir_delete(cache_path) + } + + invisible(TRUE) +} + check_dest_is_pkgdown <- function(pkg) { if (file_exists(path(pkg$dst_path, "pkgdown.yml"))) { return() @@ -45,6 +70,6 @@ dest_files <- function(pkg) { character() } else { top_level <- dir_ls(pkg$dst_path) - top_level[!path_file(top_level) %in% c("CNAME", "dev")] + top_level[!path_file(top_level) %in% c("CNAME", "dev")] } } diff --git a/man/clean_site.Rd b/man/clean.Rd similarity index 76% rename from man/clean_site.Rd rename to man/clean.Rd index d8e73f3cf..b6d8b0710 100644 --- a/man/clean_site.Rd +++ b/man/clean.Rd @@ -2,9 +2,12 @@ % Please edit documentation in R/clean.R \name{clean_site} \alias{clean_site} +\alias{clean_cache} \title{Clean site} \usage{ clean_site(pkg = ".", quiet = FALSE) + +clean_cache(pkg = ".", quiet = FALSE) } \arguments{ \item{pkg}{Path to package.} @@ -13,4 +16,6 @@ clean_site(pkg = ".", quiet = FALSE) } \description{ Delete all files in \verb{docs/} (except for \code{CNAME}). + +Delete all files in the pkgdown cache directory. }