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

fix: add some workaround to have search in wrongly configurated navbar #114

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading