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

Support removing components from the navbar #1517

Merged
merged 5 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# pkgdown (development version)

* Make navbar specification more flexible: it is now possible to not include
all default components in the navbar structure, but pkgdown will throw a warning. (#1517)

* Make footer specification more flexible: users can now
* change the placement of elements on the left and right
* add text to the left and right (or even remove/replace default text)
Expand Down
5 changes: 3 additions & 2 deletions R/build-reference-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ check_missing_topics <- function(rows, pkg) {

missing <- !in_index & !pkg$topics$internal
if (any(missing)) {
text <- sprintf("Topics missing from index: %s", unname(pkg$topics$name[missing]))
if (on_ci()) {
stop(c("Topics missing from index: ", unname(pkg$topics$name[missing])))
abort(text)
} else {
warn(c("Topics missing from index: ", unname(pkg$topics$name[missing])))
warn(text)
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions R/build.r
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
#' * News (if present).
#' * An icon linking to the source repository (currently only GitHub and GitLab are supported)
#'
#' You can override (but not remove) these defaults with the `navbar` field.
#' You can override (and even remove) these defaults with the `navbar` field.
#' It has two primary
#' components: `structure` and `components`. These components interact in
#' a somewhat complicated way, but the complexity allows you to make minor
Expand All @@ -130,8 +130,7 @@
#' The `structure` defines the layout of the navbar, i.e. the order
#' of the components, and whether they're right aligned or left aligned.
#' You can use this component to change the order of the default components,
#' and to add your own components.
#' Any unplaced components go to the right of the left navbar.
#' remove some default components and add your own components.
#'
#' ```
#' navbar:
Expand Down
4 changes: 1 addition & 3 deletions R/navbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ data_navbar <- function(pkg = ".", depth = 0L) {
components[names(components_meta)] <- components_meta
components <- purrr::compact(components)

# Any unplaced components go to the right of the left navbar
right_comp <- intersect(structure$right, names(components))
left_comp <- intersect(structure$left, names(components))
extra_comp <- setdiff(names(components), c(left_comp, right_comp))

# Backward compatiblity
left <- navbar$left %||% components[c(left_comp, extra_comp)]
left <- navbar$left %||% components[left_comp]
right <- navbar$right %||% components[right_comp]

list(
maelle marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
5 changes: 2 additions & 3 deletions man/build_site.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions tests/testthat/_snaps/navbar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# data_navbar() works by default

Code
data_navbar(pkg)
Output
$type
[1] "default"

$left
[1] "<li>\n <a href=\"reference/index.html\">Reference</a>\n</li>\n<li>\n <a href=\"news/index.html\">Changelog</a>\n</li>"

$right
[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>"


# data_navbar() can re-order default elements

Code
data_navbar(pkg)
Output
$type
[1] "default"

$left
[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>\n<li>\n <a href=\"reference/index.html\">Reference</a>\n</li>"

$right
[1] "<li>\n <a href=\"news/index.html\">Changelog</a>\n</li>"


# data_navbar()can remove elements

Code
data_navbar(pkg)
Output
$type
[1] "default"

$left
[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 change: 1 addition & 0 deletions tests/testthat/assets/news-multi-page/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Package: testpackage
Version: 1.0.0
Title: A test package
URL: https://github.com/r-lib/pkgdown
Description: A test package
Authors@R: c(
person("Hadley", "Wickham", , "hadley@rstudio.com", role = c("aut", "cre")),
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-navbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,20 @@ test_that("can control articles navbar through articles meta", {

})

test_that("data_navbar() works by default", {
pkg <- as_pkgdown(test_path("assets/news-multi-page"))
expect_snapshot(data_navbar(pkg))
})

test_that("data_navbar() can re-order default elements", {
pkg <- as_pkgdown(test_path("assets/news-multi-page"))
pkg$meta$navbar$structure$right <- c("news")
pkg$meta$navbar$structure$left <- c("github", "reference")
expect_snapshot(data_navbar(pkg))
})

test_that("data_navbar()can remove elements", {
pkg <- as_pkgdown(test_path("assets/news-multi-page"))
pkg$meta$navbar$structure$left <- c("github")
expect_snapshot(data_navbar(pkg))
})