From f0f28244ce8aa6ea4fffc08c7f9e688b4a8daeb9 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Mon, 20 May 2024 14:55:39 -0400 Subject: [PATCH] Message when reading/writing home page (#2544) --- NEWS.md | 1 + R/build-home-index.R | 9 +++++++++ tests/testthat/_snaps/build-home-index.md | 12 ++++++++++++ tests/testthat/test-build-home-index.R | 13 +++++++++++-- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 43dd3b98d..6715d2320 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* `build_home_index()` now reports when rendering the home page (#2544). * Bootstrap 3 has been deprecated. It was superseded in December 2021, and now we're starting to more directly encourage folks to move away from it. * Improve HTML5 compliance (#2369): * No longer support IE9 or earlier diff --git a/R/build-home-index.R b/R/build-home-index.R index 2a75c9d9f..3ed407bdb 100644 --- a/R/build-home-index.R +++ b/R/build-home-index.R @@ -8,11 +8,15 @@ build_home_index <- function(pkg = ".", quiet = TRUE) { data <- data_home(pkg) if (is.null(src_path)) { + cli::cli_inform("Reading {.file DESCRIPTION}") data$index <- linkify(pkg$desc$get_field("Description", "")) } else { + cli::cli_inform("Reading {src_path(path_rel(src_path, pkg$src_path))}") local_options_link(pkg, depth = 0L) data$index <- markdown_body(src_path) } + + cur_digest <- file_digest(dst_path) render_page(pkg, "home", data, "index.html", quiet = quiet) strip_header <- isTRUE(pkg$meta$home$strip_header) @@ -28,6 +32,11 @@ build_home_index <- function(pkg = ".", quiet = TRUE) { logo = logo_path(pkg, depth = 0) ) + new_digest <- file_digest(dst_path) + if (cur_digest != new_digest) { + writing_file(path_rel(dst_path, pkg$dst_path), "index.html") + } + invisible() } diff --git a/tests/testthat/_snaps/build-home-index.md b/tests/testthat/_snaps/build-home-index.md index 833f84e7a..510a7c5b3 100644 --- a/tests/testthat/_snaps/build-home-index.md +++ b/tests/testthat/_snaps/build-home-index.md @@ -1,3 +1,15 @@ +# messages about reading and writing + + Code + build_home_index(pkg) + Message + Reading 'DESCRIPTION' + Writing `index.html` + Code + build_home_index(pkg) + Message + Reading 'DESCRIPTION' + # data_home_sidebar() works by default Code diff --git a/tests/testthat/test-build-home-index.R b/tests/testthat/test-build-home-index.R index 858e8b556..3fc5f6808 100644 --- a/tests/testthat/test-build-home-index.R +++ b/tests/testthat/test-build-home-index.R @@ -1,3 +1,12 @@ +test_that("messages about reading and writing", { + pkg <- local_pkgdown_site(test_path("assets/home-index-rmd")) + + expect_snapshot({ + build_home_index(pkg) + build_home_index(pkg) + }) +}) + test_that("title and description come from DESCRIPTION by default", { pkg <- as_pkgdown(test_path("assets/home-index-rmd")) expect_equal(data_home(pkg)$pagetitle, "A test package") @@ -24,7 +33,7 @@ test_that("version formatting in preserved", { expect_equal(pkg$version, "1.0.0-9000") suppressMessages(init_site(pkg)) - build_home_index(pkg, quiet = TRUE) + suppressMessages(build_home_index(pkg)) index <- read_lines(path(pkg$dst_path, "index.html")) expect_true(any(grepl("1.0.0-9000", index, fixed = TRUE))) }) @@ -47,7 +56,7 @@ test_that("data_home_sidebar() can be removed", { # nor later -- so probably not to be tested here?! dir_create(path(pkg$dst_path)) - build_home_index(pkg) + suppressMessages(build_home_index(pkg)) html <- xml2::read_html(path(pkg$dst_path, "index.html")) expect_equal(xpath_length(html, ".//aside/*"), 0) })