Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creation of faulty site #2439

Merged
merged 5 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/build-articles.R
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ rmarkdown_template <- function(pkg, name, data, depth) {
build_articles_index <- function(pkg = ".") {
pkg <- as_pkgdown(pkg)

dir_create(path(pkg$dst_path, "articles"))
create_subdir(pkg$dst_path, "articles")
render_page(
pkg,
"article-index",
Expand Down
2 changes: 1 addition & 1 deletion R/build-news.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ build_news <- function(pkg = ".",
return()

cli::cli_rule("Building news")
dir_create(path(pkg$dst_path, "news"))
create_subdir(pkg$dst_path, "news")

switch(news_style(pkg$meta),
single = build_news_single(pkg),
Expand Down
2 changes: 1 addition & 1 deletion R/build-reference.R
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ examples_env <- function(pkg, seed = 1014L, devel = TRUE, envir = parent.frame()
#' @rdname build_reference
build_reference_index <- function(pkg = ".") {
pkg <- section_init(pkg, depth = 1L)
dir_create(path(pkg$dst_path, "reference"))
create_subdir(pkg$dst_path, "reference")

# Copy icons, if needed
src_icons <- path(pkg$src_path, "icons")
Expand Down
2 changes: 1 addition & 1 deletion R/build-tutorials.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ build_tutorials <- function(pkg = ".", override = list(), preview = NA) {
}

cli::cli_rule("Building tutorials")
dir_create(path(pkg$dst_path, "tutorials"))
create_subdir(pkg$dst_path, "tutorials")

data <- purrr::transpose(tutorials)

Expand Down
4 changes: 3 additions & 1 deletion R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ init_site <- function(pkg = ".") {
pkg <- as_pkgdown(pkg)

if (is_non_pkgdown_site(pkg$dst_path)) {
cli::cli_abort(
cli::cli_abort(c(
"{.file {pkg$dst_path}} is non-empty and not built by pkgdown",
i = "Make sure no important information, and use {.run pkgdown::clean_site()} to clear"
),
call = caller_env()
)
}
Expand Down
9 changes: 9 additions & 0 deletions R/utils-fs.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ file_copy_to <- function(pkg,
file_copy(from_paths[!eq], to_paths[!eq], overwrite = overwrite)
}

# Checks init_site() first.
create_subdir <- function(dest_base, subdir) {
if (!fs::dir_exists(dest_base)) {
init_site()
olivroy marked this conversation as resolved.
Show resolved Hide resolved
}
dir_create(path(dest_base, subdir))

}

out_of_date <- function(source, target) {
if (!file_exists(target))
return(TRUE)
Expand Down
Loading