From 78869beec6484c3c1c3b088a5450002636278553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 16 Feb 2021 14:59:43 +0100 Subject: [PATCH 01/22] start --- NEWS.md | 5 +++++ R/build-home-index.R | 6 +++--- R/build-home.R | 3 ++- R/build.r | 13 +++++++++++++ R/markdown.R | 12 ++++++++++++ tests/testthat/_snaps/data_home_sidebar.md | 10 +++++----- tests/testthat/test-data_home_sidebar.R | 13 ++++++++----- 7 files changed, 48 insertions(+), 14 deletions(-) diff --git a/NEWS.md b/NEWS.md index a4fd5ba7b..34ad8b201 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # pkgdown (development version) +* Make footer specification more flexible: users can now + * change the placement of elements on the left and right + * add sentences to the left and right + * pkgdown can now use the templates "in-header.html"/"after-head.html", "before-body.html" and "after-body.html" whose content will be placed (similarly to bookdown options `in_header`, `before_body` and `after_body`), @@ -9,6 +13,7 @@ right below the opening `` tag; and before the closing tag `` (#148 * Links for GitHub Enterprise and GitLab Enterprise repositories are detected by assuming such host address begin with `github.` or `gitlab.` (@ijlyttle, #1452). + * Make sidebar specification more flexible: users can now * change the order of sidebar elements * add custom sidebar sections (title, text that has to be HTML) diff --git a/R/build-home-index.R b/R/build-home-index.R index 706caba6e..de806be4b 100644 --- a/R/build-home-index.R +++ b/R/build-home-index.R @@ -135,12 +135,12 @@ default_sidebar_structure <- function() { data_home_component <- function(component, component_name, pkg) { - if (!all(c("title", "html") %in% names(component))) { + if (!all(c("title", "text") %in% names(component))) { abort( sprintf( "Can't find %s for the component %s", paste0( - c("title", "html")[!c("title", "html") %in% names(component)], + c("title", "text")[!c("title", "text") %in% names(component)], collapse = " nor " ), pkgdown_field(pkg = pkg, "home", "sidebar", "components", component_name) @@ -148,7 +148,7 @@ data_home_component <- function(component, component_name, pkg) { ) } - sidebar_section(component$title, bullets = component$html) + sidebar_section(component$title, bullets = markdown_text2(component$text)) } data_home_sidebar_links <- function(pkg = ".") { diff --git a/R/build-home.R b/R/build-home.R index 921471872..7bfb1c580 100644 --- a/R/build-home.R +++ b/R/build-home.R @@ -127,6 +127,7 @@ #' The example below creates a sidebar whose only components will be the #' authors section, a custom section, and a Dev Status section if there are #' badges. +#' The `text` can be Markdown or HTML. #' #' ``` #' home: @@ -135,7 +136,7 @@ #' components: #' custom: #' title: Funding -#' html: We are grateful for funding! +#' text: We are *grateful* for funding! #' ``` #' #' You can provide a ready-made sidebar HTML: diff --git a/R/build.r b/R/build.r index 1bb197569..e66eccb54 100644 --- a/R/build.r +++ b/R/build.r @@ -309,6 +309,19 @@ #' deploy: #' install_metadata: true #' ``` +#' @section YAML config - footer: +#' By default, the footer is automatically populated with: +#' * the names of the authors, on the left; +#' * a reference to pkgdown, on the right. +#' +#' ``` +#' footer: +#' left: +#' structure: [authors, legal] +#' components: +#' legal: +#' text: Provided without ***any warranty***. +#' ``` #' #' @section Options: #' Users with limited internet connectivity can disable CRAN checks by setting diff --git a/R/markdown.R b/R/markdown.R index 38a27f55a..b92a8b916 100644 --- a/R/markdown.R +++ b/R/markdown.R @@ -68,3 +68,15 @@ markdown_text <- function(text, ...) { write_lines(text, path = tmp) markdown(tmp, ...) } + + +markdown_text2 <- function(text, ...) { + html <- markdown_text(text, ...) + html %>% + xml2::read_html() %>% + xml2::xml_child() %>% # body + xml2::xml_child() %>% # p + xml2::xml_contents() %>% + as.character() %>% + paste(collapse = "") +} diff --git a/tests/testthat/_snaps/data_home_sidebar.md b/tests/testthat/_snaps/data_home_sidebar.md index 70e17c2b8..bc75a2374 100644 --- a/tests/testthat/_snaps/data_home_sidebar.md +++ b/tests/testthat/_snaps/data_home_sidebar.md @@ -35,12 +35,12 @@ # data_home_sidebar() can get a custom component Code - xml2::xml_find_first(result, ".//div[@class='fancy-section']") + xml2::xml_find_first(xml2::xml_find_first(result, + ".//div[@class='fancy-section']"), ".//ul") Output {html_node} -
- [1]

Fancy section

- [2] +