Skip to content

Commit

Permalink
Message when reading/writing home page (#2544)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored May 20, 2024
1 parent 5761658 commit f0f2824
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions R/build-home-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
}

Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/_snaps/build-home-index.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 11 additions & 2 deletions tests/testthat/test-build-home-index.R
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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)))
})
Expand All @@ -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)
})
Expand Down

0 comments on commit f0f2824

Please sign in to comment.