Skip to content

Commit

Permalink
Fix navbar customization logic (#1574)
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Mar 25, 2021
1 parent fe799d3 commit ff86fa3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions R/navbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ data_navbar <- function(pkg = ".", depth = 0L) {

# Take structure as is from meta
navbar <- purrr::pluck(pkg, "meta", "navbar")
structure <- navbar$structure %||% navbar_structure()
structure <- modify_list(navbar_structure_defaults(), navbar$structure)

# Merge components from meta
components <- navbar_components(pkg)
Expand Down Expand Up @@ -66,10 +66,14 @@ render_navbar_links <- function(x, depth = 0L, bs_version) {
# Default navbar ----------------------------------------------------------

navbar_structure <- function() {
print_yaml(list(
print_yaml(navbar_structure_defaults())
}

navbar_structure_defaults <- function() {
list(
left = c("intro", "reference", "articles", "tutorials", "news"),
right = "github"
))
)
}

navbar_components <- function(pkg = ".") {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/navbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
[1] "<li>\n <a href=\"https://github.com/r-lib/pkgdown/\">\n <span class=\"fab fa-github fa-lg\"></span>\n \n </a>\n</li>"
$right
[1] ""
[1] "<li>\n <a href=\"reference/index.html\">Reference</a>\n</li>"

1 change: 1 addition & 0 deletions tests/testthat/test-navbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ test_that("data_navbar() can re-order default elements", {
test_that("data_navbar()can remove elements", {
pkg <- as_pkgdown(test_path("assets/news-multi-page"))
pkg$meta$navbar$structure$left <- c("github")
pkg$meta$navbar$structure$right <- c("reference")
expect_snapshot(data_navbar(pkg))
})

0 comments on commit ff86fa3

Please sign in to comment.