Skip to content

Commit

Permalink
Don't call init_site() when lazy = TRUE + use posix line end + do…
Browse files Browse the repository at this point in the history
…cument `init_site()` + speed cli console output (#2642)

* use Posix line ending in pkgdown

* Use `withr::local_options(cli.num_colors = num_col, .local_envir = .frame)` in `section_init()`

* Document `init_site()` usage.

* Only call `init_site()` when lazy = FALSE, since `build_home()` will call it anyway if necessary.

* Add `local_options_console()` to `init_site()`

* Apply suggestions from code review

Co-authored-by: Hadley Wickham <[email protected]>

---------

Co-authored-by: Hadley Wickham <[email protected]>
  • Loading branch information
olivroy and hadley authored Jun 7, 2024
1 parent 8defd98 commit 2c8d15d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,11 @@ build_site_local <- function(pkg = ".",

pkgdown_sitrep(pkg)

init_site(pkg)
if (!lazy) {
# Only force init_site() if `!lazy`
# if site is not initialized, it will be in build_home()
init_site(pkg, override)
}

build_home(pkg, override = override, preview = FALSE)
build_reference(
Expand Down
7 changes: 7 additions & 0 deletions R/context.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ section_init <- function(pkg,

local_envvar_pkgdown(pkg, .frame)
local_options_link(pkg, depth = depth, .frame = .frame)
cache_cli_colours(.frame = .frame)

pkg
}

cache_cli_colours <- function(.frame = parent.frame()) {
# https://github.com/r-lib/cli/issues/607
num_col <- getOption("cli.num_colors", default = cli::num_ansi_colors())
withr::local_options(cli.num_colors = num_col, .local_envir = .frame)
}

local_options_link <- function(pkg, depth, .frame = parent.frame()) {
article_index <- article_index(pkg)
Rdname <- get_rdname(pkg$topics)
Expand Down
9 changes: 9 additions & 0 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
#' * copies CSS/JS assets and extra files, and
#' * runs `build_favicons()`, if needed.
#'
#' Typically, you will not need to call this function directly, as all `build_*()`
#' functions will run `init_site()` if needed.
#'
#' The only good reasons to call `init_site()` directly are the following:
#' * If you add or modify a package logo.
#' * If you add or modify `pkgdown/extra.scss`.
#' * If you modify `template.bslib` variables in `_pkgdown.yml`.
#'
#' See `vignette("customise")` for the various ways you can customise the
#' display of your site.
#'
Expand All @@ -24,6 +32,7 @@ init_site <- function(pkg = ".", override = list()) {
# This is the only user facing function that doesn't call section_init()
# because section_init() can conditionally call init_site()
rstudio_save_all()
cache_cli_colours()
pkg <- as_pkgdown(pkg, override = override)

cli::cli_rule("Initialising site")
Expand Down
2 changes: 2 additions & 0 deletions R/theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ build_bslib <- function(pkg = ".", call = caller_env()) {

data_deps <- function(pkg, depth) {
if (!file_exists(data_deps_path(pkg))) {
# this is unlikely to occur after #2439 and #2571
cli::cli_abort(
"Run {.fn pkgdown::init_site} first.",
.internal = TRUE,
call = caller_env()
)
}
Expand Down
10 changes: 10 additions & 0 deletions man/init_site.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkgdown.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
LineEndingConversion: Posix

BuildType: Package
PackageUseDevtools: Yes
Expand Down

0 comments on commit 2c8d15d

Please sign in to comment.