Skip to content

Commit

Permalink
Inform user when bslib files are created (#2525)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored May 10, 2024
1 parent e933529 commit a7bb4e4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
25 changes: 25 additions & 0 deletions R/theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@ build_bslib <- function(pkg = ".") {
pkg <- as_pkgdown(pkg)
bs_theme <- bs_theme(pkg)

cur_deps <- find_deps(pkg)
cur_digest <- purrr::map_chr(cur_deps, file_digest)

deps <- bslib::bs_theme_dependencies(bs_theme)
deps <- lapply(deps, htmltools::copyDependencyToDir, file.path(pkg$dst_path, "deps"))
deps <- lapply(deps, htmltools::makeDependencyRelative, pkg$dst_path)

new_deps <- find_deps(pkg)
new_digest <- purrr::map_chr(cur_deps, file_digest)

all_deps <- union(new_deps, cur_deps)
diff <- (cur_digest[all_deps] == new_digest[all_deps])
changed <- all_deps[!diff | is.na(diff)]

if (length(changed) > 0) {
purrr::walk(changed, function(dst) {
cli::cli_inform("Updating {dst_path(path_rel(dst, pkg$dst_path))}")
})
}

head <- htmltools::renderDependencies(deps, srcType = "file")
write_lines(head, data_deps_path(pkg))
}
Expand All @@ -31,6 +47,15 @@ data_deps_path <- function(pkg) {
file.path(pkg$dst_path, "deps", "data-deps.txt")
}

find_deps <- function(pkg) {
deps_path <- path(pkg$dst_path, "deps")
if (!dir_exists(deps_path)) {
character()
} else {
dir_ls(deps_path, type = "file", recurse = TRUE)
}
}

bs_theme <- function(pkg = ".") {
pkg <- as_pkgdown(pkg)

Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/_snaps/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@
Copying <pkgdown>/BS3/assets/pkgdown.js to pkgdown.js
Copying pkgdown/extra.css to extra.css

---

Code
init_site(pkg)
Message
-- Initialising site -----------------------------------------------------------
Copying <pkgdown>/BS5/assets/link.svg to link.svg
Copying <pkgdown>/BS5/assets/pkgdown.js to pkgdown.js
Copying pkgdown/extra.css to extra.css
Updating deps/bootstrap-5.3.1/bootstrap.bundle.min.js
Updating deps/bootstrap-5.3.1/bootstrap.bundle.min.js.map
Updating deps/bootstrap-5.3.1/bootstrap.min.css
Updating deps/jquery-3.6.0/jquery-3.6.0.js
Updating deps/jquery-3.6.0/jquery-3.6.0.min.js
Updating deps/jquery-3.6.0/jquery-3.6.0.min.map

# site meta doesn't break unexpectedly

Code
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-init.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
test_that("informative print method", {
pkg <- local_pkgdown_site(test_path("assets/init-extra-1"))
expect_snapshot(init_site(pkg))

pkg <- local_pkgdown_site(test_path("assets/init-extra-1"), meta = "
template:
bootstrap: 5
")
expect_snapshot(init_site(pkg))
})

test_that("extra.css and extra.js copied and linked", {
Expand Down

0 comments on commit a7bb4e4

Please sign in to comment.