From 39083f38bbb2de2e1126529392bddf3e6e262ab4 Mon Sep 17 00:00:00 2001 From: Salim B Date: Fri, 12 May 2023 17:53:18 +0200 Subject: [PATCH] Remove unwanted linebreaks from parsing DESCRIPTION (#2247) --- DESCRIPTION | 2 +- NEWS.md | 1 + R/build-home-citation.R | 4 +++- R/build-home-index.R | 6 +++--- R/build-home-license.R | 2 +- R/package.R | 4 ++-- R/utils.R | 2 ++ 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2fdc4994f..25e38d08e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,7 +23,7 @@ Imports: bslib (>= 0.3.1), callr (>= 3.7.3), cli, - desc, + desc (>= 1.4.0), digest, downlit (>= 0.4.0), fs (>= 1.4.0), diff --git a/NEWS.md b/NEWS.md index e163a8488..f8c48d88c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* Avoid unwanted linebreaks from parsing `DESCRIPTION` (@salim-b, #2247). * Remove redundant entries in the documentation index when multiple explicit `@usage` tags are provided (@klmr, #2302) * The article index now sorts vignettes and non-vignette articles alphabetically by their filename (literally, their `basename()`), by default (@jennybc, #2253). diff --git a/R/build-home-citation.R b/R/build-home-citation.R index e3b7116b3..1e1c2543c 100644 --- a/R/build-home-citation.R +++ b/R/build-home-citation.R @@ -15,6 +15,8 @@ create_citation_meta <- function(path) { meta$Encoding <- "UTF-8" } + if (!is.null(meta$Title)) meta$Title <- str_squish(meta$Title) + meta } @@ -45,7 +47,6 @@ data_citations <- function(pkg = ".") { } citation_auto(pkg) - } citation_provided <- function(src_path) { @@ -70,6 +71,7 @@ citation_auto <- function(pkg) { lib.loc = path_dir(pkg$src_path) ) cit_info$`Date/Publication` <- cit_info$`Date/Publication` %||% Sys.time() + if (!is.null(cit_info$Title)) cit_info$Title <- str_squish(cit_info$Title) cit <- utils::citation(auto = cit_info) list( diff --git a/R/build-home-index.R b/R/build-home-index.R index ac2fa76ab..3c39aca2a 100644 --- a/R/build-home-index.R +++ b/R/build-home-index.R @@ -14,7 +14,7 @@ build_home_index <- function(pkg = ".", quiet = TRUE) { data <- data_home(pkg) if (is.null(src_path)) { - data$index <- linkify(pkg$desc$get("Description")[[1]]) + data$index <- linkify(pkg$desc$get_field("Description", "")) } else { local_options_link(pkg, depth = 0L) data$index <- markdown_body(src_path) @@ -45,10 +45,10 @@ data_home <- function(pkg = ".") { print_yaml(list( pagetitle = pkg$meta$home[["title"]] %||% - cran_unquote(pkg$desc$get("Title")[[1]]), + cran_unquote(pkg$desc$get_field("Title", "")), sidebar = data_home_sidebar(pkg), opengraph = list(description = pkg$meta$home[["description"]] %||% - cran_unquote(pkg$desc$get("Description")[[1]])), + cran_unquote(pkg$desc$get_field("Description", ""))), has_trailingslash = pkg$meta$template$trailing_slash_redirect %||% FALSE )) } diff --git a/R/build-home-license.R b/R/build-home-license.R index 7c9d81eaa..04f772c82 100644 --- a/R/build-home-license.R +++ b/R/build-home-license.R @@ -21,7 +21,7 @@ build_home_license <- function(pkg) { data_home_sidebar_license <- function(pkg = ".") { pkg <- as_pkgdown(pkg) - link <- autolink_license(pkg$desc$get("License")[[1]]) + link <- autolink_license(pkg$desc$get_field("License", "")) license_md <- path_first_existing(pkg$src_path, c("LICENSE.md", "LICENCE.md")) if (!is.null(license_md)) { diff --git a/R/package.R b/R/package.R index 12035a7cc..82c9c83f6 100644 --- a/R/package.R +++ b/R/package.R @@ -31,7 +31,7 @@ as_pkgdown <- function(pkg = ".", override = list()) { meta[["url"]] <- sub("/$", "", meta[["url"]]) } - package <- desc$get("Package")[[1]] + package <- desc$get_field("Package") version <- desc$get_field("Version") bs_version <- check_bootstrap_version(meta$template$bootstrap, pkg) @@ -199,7 +199,7 @@ extract_title <- function(x) { x %>% purrr::detect(inherits, "tag_title") %>% flatten_text(auto_link = FALSE) %>% - str_trim() + str_squish() } extract_source <- function(x) { diff --git a/R/utils.R b/R/utils.R index 2d5b64419..6ace99a97 100644 --- a/R/utils.R +++ b/R/utils.R @@ -40,6 +40,8 @@ is_syntactic <- function(x) x == make.names(x) str_trim <- function(x) gsub("^\\s+|\\s+$", "", x) +str_squish <- function(x) str_trim(gsub("\\s+", " ", x)) + # devtools metadata ------------------------------------------------------- system_file <- function(..., package) {