From eba8eece66a546f25b41f87d438b0b5e33c1c521 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 18 Apr 2024 08:01:08 -0500 Subject: [PATCH 1/6] Describe what check_pkgdown() actually does (#2460) Fixes #2260 --- R/check.R | 9 ++++++++- man/check_pkgdown.Rd | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/R/check.R b/R/check.R index 1858ab454..08343d2da 100644 --- a/R/check.R +++ b/R/check.R @@ -1,7 +1,14 @@ #' Check `_pkgdown.yml` #' +#' @description #' Check that your `_pkgdown.yml` is valid without building the whole -#' site. +#' site. Currently this: +#' +#' * Checks the reference and article indexes to ensure that pkgdown can +#' read them, and that every documentation topic and vignette/article is +#' included in the index. +#' +#' * Validates any opengraph metadata that you might have supplied #' #' @export #' @inheritParams as_pkgdown diff --git a/man/check_pkgdown.Rd b/man/check_pkgdown.Rd index 1be57ec87..d049c9439 100644 --- a/man/check_pkgdown.Rd +++ b/man/check_pkgdown.Rd @@ -11,5 +11,11 @@ check_pkgdown(pkg = ".") } \description{ Check that your \verb{_pkgdown.yml} is valid without building the whole -site. +site. Currently this: +\itemize{ +\item Checks the reference and article indexes to ensure that pkgdown can +read them, and that every documentation topic and vignette/article is +included in the index. +\item Validates any opengraph metadata that you might have supplied +} } From b87df21d3cabfcfa757413e7ef3cfb8432536405 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 18 Apr 2024 11:28:12 -0500 Subject: [PATCH 2/6] Check navbar structure (#2467) Fixes #2312 --- NEWS.md | 1 + R/navbar.R | 16 +++++++++++----- tests/testthat/_snaps/navbar.md | 14 +++++++++++--- tests/testthat/test-navbar.R | 17 ++++++++++++++--- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/NEWS.md b/NEWS.md index 6f316e20b..5cdb677ef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* `data_template()` gives a more informative error if you've misspecified the navbar (#2312). * The skip link now becomes visible when focussed (#2138). Thanks to @glin for the styles! * `build_reference_index()` gives more informative errors if your `contents` field is malformed (#2323). * The left and right footers no longer contain an extra empty paragraph tag and the footer gains additional padding-top to keep the whitespace constant (#2381). diff --git a/R/navbar.R b/R/navbar.R index e5d670332..8c1b31627 100644 --- a/R/navbar.R +++ b/R/navbar.R @@ -54,18 +54,24 @@ navbar_links <- function(pkg, depth = 0L) { yaml_character(pkg, c("navbar", "structure", "left")), names(components) ) - # Backward compatibility left <- navbar$left %||% components[left_comp] right <- navbar$right %||% components[right_comp] list( - left = render_navbar_links(left, depth = depth, bs_version = pkg$bs_version), - right = render_navbar_links(right, depth = depth, bs_version = pkg$bs_version) + left = render_navbar_links(left, depth = depth, pkg = pkg), + right = render_navbar_links(right, depth = depth, pkg = pkg) ) } -render_navbar_links <- function(x, depth = 0L, bs_version = 3) { +render_navbar_links <- function(x, depth = 0L, pkg) { + if (!is.list(x)) { + cli::cli_abort( + "Invalid navbar specification in {pkgdown_config_href({pkg$src_path})}", + call = quote(data_template()) + ) + } + stopifnot(is.integer(depth), depth >= 0L) tweak <- function(x) { @@ -83,7 +89,7 @@ render_navbar_links <- function(x, depth = 0L, bs_version = 3) { x <- lapply(x, tweak) } - if (bs_version == 3) { + if (pkg$bs_version == 3) { rmarkdown::navbar_links_html(x) } else { bs4_navbar_links_html(x) diff --git a/tests/testthat/_snaps/navbar.md b/tests/testthat/_snaps/navbar.md index 40190cdf0..552e2a765 100644 --- a/tests/testthat/_snaps/navbar.md +++ b/tests/testthat/_snaps/navbar.md @@ -177,10 +177,18 @@ Error in `navbar_links()`: ! navbar.structure.left must be a character vector. +# data_navbar() errors with bad left/right + + Code + data_navbar(pkg) + Condition + Error in `data_template()`: + ! Invalid navbar specification in _pkgdown.yml + # render_navbar_links BS3 & BS4 default Code - cat(render_navbar_links(x, bs_version = 3)) + cat(render_navbar_links(x, pkg = list(bs_version = 3))) Output
  • Get started @@ -220,7 +228,7 @@ --- Code - cat(render_navbar_links(x, bs_version = 4)) + cat(render_navbar_links(x, pkg = list(bs_version = 4))) Output