Skip to content

Commit

Permalink
Only extract lifecycle badges from description
Browse files Browse the repository at this point in the history
Fixes #2584
  • Loading branch information
hadley committed May 28, 2024
1 parent e808ba8 commit 95c460f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pkgdown (development version)

* `build_reference_index()` now displays lifecycle badges next to the function name (#2123). You can now also use `has_lifecycle()` to select functions by their lifecycle status.
* `build_reference_index()` now displays function lifecycle badges next to the function name (#2123). The badges are extracted only from the function description. You can now also use `has_lifecycle()` to select functions by their lifecycle status.
* `build_articles()` now recognises a new `external-articles` top-level field that allows you to define articles that live in other packages (#2028).
* New light switch makes it easy for users to switch between light and dark themes for the website (based on work in bslib by @gadenbuie). For now this behaviour is opt-in with `template.light-switch: true` but in the future we may turn it on automatically. See the customization vignette for details (#1696).
* The search dropdown has been tweaked to look more like the other navbar menu items (#2338).
Expand Down
4 changes: 3 additions & 1 deletion R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ extract_source <- function(x) {
}

extract_lifecycle <- function(x) {
fig <- extract_figure(x)
desc <- purrr::keep(x, inherits, "tag_description")
fig <- extract_figure(desc)

if (!is.null(fig) && length(fig) > 0 && length(fig[[1]]) > 0) {
path <- as.character(fig[[1]][[1]])
if (grepl("lifecycle", path)) {
Expand Down
15 changes: 11 additions & 4 deletions tests/testthat/test-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ test_that("read_meta() errors gracefully if _pkgdown.yml failed to parse", {

# lifecycle ---------------------------------------------------------------

test_that("can extract lifecycle badges", {
expect_equal(
extract_lifecycle(rd_text(lifecycle::badge("deprecated"))),
"deprecated"
test_that("can extract lifecycle badges from description", {
rd_desc <- rd_text(
paste0("\\description{", lifecycle::badge("deprecated"), "}"),
fragment = FALSE
)
rd_param <- rd_text(
paste0("\\arguments{\\item{pkg}{", lifecycle::badge("deprecated"), "}}"),
fragment = FALSE
)

expect_equal(extract_lifecycle(rd_desc), "deprecated")
expect_equal(extract_lifecycle(rd_param), NULL)
})

test_that("malformed figures fail gracefully", {
Expand Down

0 comments on commit 95c460f

Please sign in to comment.