diff --git a/NEWS.md b/NEWS.md index eeefa08547..f7e645adca 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # pkgdown (development version) +* New translation for "Search site", the label applied to the search box for screenreaders. This was previously incorrectly labelled as "Toggle navigation" (#2320). +* You can now choose where the search box is placed with the "search" navbar component. This has been documented for a very long time, but as far as I can tell, never worked (#2320). If you have made your own template with a custom `navbar`, you will need to remove the `
` with `role="search"` to avoid getting two search boxes. * The mobile version of pkgdown sites no longer has a scrollburglar (a small amount of horizontal scroll) (#2179, @netique). # pkgdown 2.0.9 diff --git a/R/navbar.R b/R/navbar.R index 8c1b316273..2bfbafc38c 100644 --- a/R/navbar.R +++ b/R/navbar.R @@ -31,7 +31,7 @@ navbar_style <- function(navbar = list(), theme = "_default", bs_version = 3) { navbar_structure <- function() { print_yaml(list( left = c("intro", "reference", "articles", "tutorials", "news"), - right = "github" + right = c("search", "github") )) } @@ -104,6 +104,11 @@ navbar_components <- function(pkg = ".") { menu <- list() menu$reference <- menu_link(tr_("Reference"), "reference/index.html") + # in BS3, search is hardcoded in the template + if (pkg$bs_version == 5) { + menu$search <- list(search = NULL) + } + if (!is.null(pkg$tutorials)) { menu$tutorials <- menu(tr_("Tutorials"), menu_links(pkg$tutorials$title, pkg$tutorials$file_out) @@ -191,6 +196,23 @@ menu_spacer <- function() { menu_text("---------") } +menu_search <- function(depth = 0) { + paste0( + '
  • \n', + '\n', + '
  • ' + ) +} + bs4_navbar_links_html <- function(links) { as.character(bs4_navbar_links_tags(links), options = character()) } @@ -208,6 +230,10 @@ bs4_navbar_links_tags <- function(links, depth = 0L) { # function for links tackle_link <- function(x, index, is_submenu, depth) { + if (has_name(x, "search")) { + return(htmltools::HTML(menu_search(depth))) + } + if (!is.null(x$menu)) { if (is_submenu) { @@ -316,7 +342,8 @@ pkg_navbar <- function(meta = NULL, vignettes = pkg_navbar_vignettes(), src_path = file_temp(), meta = meta, vignettes = vignettes, - repo = list(url = list(home = github_url)) + repo = list(url = list(home = github_url)), + bs_version = 5 ), class = "pkgdown" ) diff --git a/R/render.R b/R/render.R index 2b88b588e9..00c32b6de8 100644 --- a/R/render.R +++ b/R/render.R @@ -89,7 +89,6 @@ data_template <- function(pkg = ".", depth = 0L) { out$translate <- list( skip = tr_("Skip to contents"), toggle_nav = tr_("Toggle navigation"), - search_for = tr_("Search for"), on_this_page = tr_("On this page"), source = tr_("Source"), abstract = tr_("Abstract"), diff --git a/R/tweak-navbar.R b/R/tweak-navbar.R index 25a43a463c..cb391490be 100644 --- a/R/tweak-navbar.R +++ b/R/tweak-navbar.R @@ -24,7 +24,7 @@ navbar_links_haystack <- function(html, pkg, path) { get_hrefs <- function(nav_item, pkg = pkg) { href <- xml2::xml_attr(xml2::xml_child(nav_item), "href") - if (href != "#") { + if (!is.na(href) && href != "#") { links <- href } else { # links in a drop-down diff --git a/inst/BS5/templates/navbar.html b/inst/BS5/templates/navbar.html index 8ddf40473d..b8a50fd61a 100644 --- a/inst/BS5/templates/navbar.html +++ b/inst/BS5/templates/navbar.html @@ -18,10 +18,6 @@ {{/left}} - - {{#right}}