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 4 commits
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Preview links now work once again (#2435).
* `build_home()` no longer renders Github issue and pull request templates (@hsloot, #2362)
* It is now easier to preview parts of the website locally interactively. `build_reference_index()` and friends will call `init_site()` internally instead of erroring (@olivroy, #2329).

# pkgdown 2.0.8

Expand Down
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", pkg)
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", pkg)

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", pkg)

# 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", pkg)

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, pkg) {
olivroy marked this conversation as resolved.
Show resolved Hide resolved
if (!fs::dir_exists(dest_base)) {
init_site(pkg)
}
dir_create(path(dest_base, subdir))

}

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