From 95c460f2dc6d01825a6dfb432fd879cd319c8dc2 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 28 May 2024 08:41:22 -0500 Subject: [PATCH] Only extract lifecycle badges from description Fixes #2584 --- NEWS.md | 2 +- R/package.R | 4 +++- tests/testthat/test-package.R | 15 +++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 947cf3e70..dc2c477e8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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). diff --git a/R/package.R b/R/package.R index baa61970e..d8832adea 100644 --- a/R/package.R +++ b/R/package.R @@ -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)) { diff --git a/tests/testthat/test-package.R b/tests/testthat/test-package.R index 5a262a6d1..ef068eb64 100644 --- a/tests/testthat/test-package.R +++ b/tests/testthat/test-package.R @@ -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", {