Skip to content

Commit

Permalink
fix: add some workaround to have search in wrongly configurated navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Jul 5, 2024
1 parent ad32476 commit f5aaab7
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion R/build-site.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ build_ropensci_docs <- function(path = ".", destination = NULL, install = FALSE,
#NB: pkgdown uses utils::modifyList() to merge _pkgdown.yml values with overrides.
#This will recursively merge lists, and delete values that are 'NULL' in overrides.


override <- list(
template = list(
package = "rotemplate",
Expand All @@ -68,6 +67,11 @@ build_ropensci_docs <- function(path = ".", destination = NULL, install = FALSE,
destination = destination
)

navbar_config <- fixup_navbar_config(path)
if (!is.null(navbar_config)) {
override$navbar <- modifyList(override$navbar, navbar_config)
}

math_config <- get_math_rendering(path)
if (!is.null(math_config)) {
override$template$`math-rendering` <- math_config
Expand Down Expand Up @@ -105,6 +109,44 @@ build_ropensci_docs <- function(path = ".", destination = NULL, install = FALSE,
invisible(pkg$dst_path)
}

fixup_navbar_config <- function(path) {

pkgdown_yml <- pkgdown_config_path(path = path)
if (is.null(pkgdown_yml)) {
return(NULL)
}

pkgdown_config <- yaml::read_yaml(pkgdown_yml)
if (is.null(pkgdown_config)) {
return(NULL)
}

if (is.null(pkgdown_config$navbar)) {
return(NULL)
}

if (!is.null(pkgdown_config$navbar$structure)) {
all_components <- c(
pkgdown_config$navbar$structure$left,
pkgdown_config$navbar$structure$right
)
if (!("search" %in% all_components)) {
pkgdown_config$navbar$structure$right <- c(pkgdown_config$navbar$structure$right, "search")
return(pkgdown_config$navbar)
}
}

uses_old_syntax <- !is.null(pkgdown_config$navbar$left) ||
!is.null(pkgdown_config$navbar$right)
if (uses_old_syntax) {
warning("Update the pkgdown navbar configuration, see https://pkgdown.r-lib.org/articles/customise.html#navbar-heading")
}


return(NULL)

}

# we need this to keep supporting the old syntax we had set up
# TODO: PR to packages using it so we can remove those lines!
get_math_rendering <- function(path){
Expand Down

0 comments on commit f5aaab7

Please sign in to comment.