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

Don't call init_site() when lazy = TRUE + use posix line end + document init_site() + speed cli console output #2642

Merged
merged 11 commits into from
Jun 7, 2024
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.

47 changes: 24 additions & 23 deletions pkgdown.Rproj
olivroy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace

SpellingDictionary: en_AU
Version: 1.0

RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
LineEndingConversion: Posix

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace

SpellingDictionary: en_AU
Loading