Skip to content

Commit

Permalink
Refine reference index section collation (#1936)
Browse files Browse the repository at this point in the history
Fixes #1935
  • Loading branch information
hadley authored Dec 2, 2021
1 parent e9324b2 commit 3e17275
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# pkgdown (development version)

* Reference sections are de-duplicated correctly (#1935).

* Usage sections only generated for topics that have them; usage correctly
displayed with BS3 (#1931)

Expand Down
9 changes: 5 additions & 4 deletions R/build-reference-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ data_reference_index_rows <- function(section, index, pkg) {
if (has_name(section, "contents")) {
check_all_characters(section$contents, index, pkg)
contents <- purrr::imap(section$contents, content_info, pkg = pkg, section = index)
names <- unlist(purrr::map(contents, "name"))
contents <- contents[!duplicated(names)]
names <- unique(names)
contents <- purrr::map(contents, function(x) x[names(x) != "name"])
contents <- do.call(rbind, contents)
contents <- contents[!duplicated(contents$name), , drop = FALSE]

names <- contents$name
contents$name <- NULL

rows[[3]] <- list(
topics = purrr::transpose(contents),
names = names,
Expand Down
4 changes: 2 additions & 2 deletions R/topics.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ content_info <- function(content_entry, index, pkg, section) {
tibble::tibble(
path = topics$file_out,
aliases = purrr::map2(topics$funs, topics$name, ~ if (length(.x) > 0) .x else .y),
name = list(topics$name),
name = topics$name,
title = topics$title,
icon = find_icons(topics$alias, path(pkg$src_path, "icons"))
)
Expand All @@ -196,7 +196,7 @@ content_info <- function(content_entry, index, pkg, section) {
tibble::tibble(
path = rd_href,
aliases = rd_aliases,
name = list(content_entry = NULL),
name = content_entry,
title = sprintf("%s (from %s)", rd_title, pkg_name),
icon = list(content_entry = NULL)
)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/_snaps/build-reference-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
- c
- e
- '?'
- rlang::is_installed()
- bslib::bs_add_rules
row_has_icons: no
has_icons: no
Expand Down

0 comments on commit 3e17275

Please sign in to comment.