diff --git a/NEWS.md b/NEWS.md index 43dd3b98d..310ebf2bc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # pkgdown (development version) +* Custom navbars that specify `icon` but not `aria-label` will now generate a message reminding you to provide one for to improve accessibility (#2533). +* `init_site()` will no longer automatically build favicons on CI systems (e.g. GHA). This is an expensive operation that uses an external service so it should only be run locally (#2553). +* `build_home_index()` now reports when rendering the home page (#2544). * Bootstrap 3 has been deprecated. It was superseded in December 2021, and now we're starting to more directly encourage folks to move away from it. * Improve HTML5 compliance (#2369): * No longer support IE9 or earlier diff --git a/R/build-articles.R b/R/build-articles.R index 1b56b752e..6ce95d7d3 100644 --- a/R/build-articles.R +++ b/R/build-articles.R @@ -88,9 +88,9 @@ #' #' ## Missing topics #' -#' pkgdown will warn if there are (non-internal) articles that aren't listed -#' in the articles index. You can suppress such warnings by listing the -#' affected articles in a section with `title: internal` (case sensitive); +#' pkgdown will warn if there are (non-internal) articles that aren't listed +#' in the articles index. You can suppress such warnings by listing the +#' affected articles in a section with `title: internal` (case sensitive); #' this section will not be displayed on the index page. #' #' # External files @@ -248,10 +248,8 @@ build_article <- function(name, front <- rmarkdown::yaml_front_matter(input_path) # Take opengraph from article's yaml front matter - front_opengraph <- check_open_graph(front$opengraph %||% list()) - data$opengraph <- utils::modifyList( - data$opengraph %||% list(), front_opengraph - ) + front_opengraph <- check_open_graph(front$opengraph, input) + data$opengraph <- modify_list(data$opengraph, front_opengraph) # Allow users to opt-in to their own template ext <- purrr::pluck(front, "pkgdown", "extension", .default = "html") diff --git a/R/build-favicons.R b/R/build-favicons.R index 8bdca8f5b..0200268c9 100644 --- a/R/build-favicons.R +++ b/R/build-favicons.R @@ -84,11 +84,11 @@ build_favicons <- function(pkg = ".", overwrite = FALSE) { cli::cli_abort("API request failed.", .internal = TRUE) } - tmp <- withr::local_tempdir() + tmp <- withr::local_tempfile() result <- httr::RETRY( "GET", result$favicon$package_url, - httr::write_disk(tmp), + httr::write_disk(tmp, overwrite = TRUE), quiet = TRUE ) diff --git a/R/build-home-authors.R b/R/build-home-authors.R index 75af5b16b..fd48e90c8 100644 --- a/R/build-home-authors.R +++ b/R/build-home-authors.R @@ -292,7 +292,7 @@ citation_auto <- function(pkg) { ) } -# helpers ----------------------------------------------------------------- +# helpers ------------------------------------------------------------------------- # Not strictly necessary, but produces a simpler data structure testing remove_orcid <- function(x) { @@ -301,4 +301,4 @@ remove_orcid <- function(x) { names(out) <- NULL } out -} \ No newline at end of file +} diff --git a/R/build-home-index.R b/R/build-home-index.R index 2a75c9d9f..3ed407bdb 100644 --- a/R/build-home-index.R +++ b/R/build-home-index.R @@ -8,11 +8,15 @@ build_home_index <- function(pkg = ".", quiet = TRUE) { data <- data_home(pkg) if (is.null(src_path)) { + cli::cli_inform("Reading {.file DESCRIPTION}") data$index <- linkify(pkg$desc$get_field("Description", "")) } else { + cli::cli_inform("Reading {src_path(path_rel(src_path, pkg$src_path))}") local_options_link(pkg, depth = 0L) data$index <- markdown_body(src_path) } + + cur_digest <- file_digest(dst_path) render_page(pkg, "home", data, "index.html", quiet = quiet) strip_header <- isTRUE(pkg$meta$home$strip_header) @@ -28,6 +32,11 @@ build_home_index <- function(pkg = ".", quiet = TRUE) { logo = logo_path(pkg, depth = 0) ) + new_digest <- file_digest(dst_path) + if (cur_digest != new_digest) { + writing_file(path_rel(dst_path, pkg$dst_path), "index.html") + } + invisible() } diff --git a/R/build-home.R b/R/build-home.R index 8c085e59c..29e885970 100644 --- a/R/build-home.R +++ b/R/build-home.R @@ -15,40 +15,40 @@ #' iterating when experimenting with site styles. #' #' # Home page -#' +#' #' The main content of the home page (`index.html`) is generated from #' `pkgdown/index.md`, `index.md`, or `README.md`, in that order. -#' Most packages will use `README.md` because that's also displayed by GitHub -#' and CRAN. Use `index.md` if you want your package website to look -#' different to your README, and use `pkgdown/index.md` if you don't want that +#' Most packages will use `README.md` because that's also displayed by GitHub +#' and CRAN. Use `index.md` if you want your package website to look +#' different to your README, and use `pkgdown/index.md` if you don't want that #' file to live in your package root directory. -#' -#' If you use `index.Rmd` or `README.Rmd` it's your responsibility to knit -#' the document to create the corresponding `.md`. pkgdown does not do this +#' +#' If you use `index.Rmd` or `README.Rmd` it's your responsibility to knit +#' the document to create the corresponding `.md`. pkgdown does not do this #' for you because it only touches files in the `doc/` directory. -#' -#' Extra markdown files in the base directory (e.g. `ROADMAP.md`) or in +#' +#' Extra markdown files in the base directory (e.g. `ROADMAP.md`) or in #' `.github/` (e.g. `CODE_OF_CONDUCT.md`) are copied by `build_home()` to `docs/` and converted to HTML. -#' -#' The home page also features a sidebar with information extracted from the -#' package. You can tweak it via the configuration file, to help make the home +#' +#' The home page also features a sidebar with information extracted from the +#' package. You can tweak it via the configuration file, to help make the home #' page an as informative as possible landing page. -#' +#' #' ## Images and figures -#' -#' If you want to include images in your `README.md`, they must be stored +#' +#' If you want to include images in your `README.md`, they must be stored #' somewhere in the package so that they can be displayed on the CRAN website. -#' The best place to put them is `man/figures`. If you are generating figures +#' The best place to put them is `man/figures`. If you are generating figures #' with R Markdown, make sure you set up `fig.path` as followed: -#' +#' #' ``` r #' knitr::opts_chunk$set( #' fig.path = "man/figures/" #' ) #' ``` -#' +#' #' This should usually go in a chunk with `include = FALSE`. -#' +#' #' ```` markdown #' ```{r chunk-name, include=FALSE}`r ''` #' knitr::opts_chunk$set( @@ -56,27 +56,27 @@ #' ) #' ``` #' ```` -#' +#' #' ## Package logo -#' +#' #' If you have a package logo, you can include it at the top of your README #' in a level-one heading: -#' +#' #' ``` markdown #' # pkgdown #' ``` -#' +#' #' [init_site()] will also automatically create a favicon set from your package logo. -#' +#' #' ## YAML config - title and description -#' +#' #' By default, the page title and description are extracted automatically from #' the `Title` and `Description` fields `DESCRIPTION` (stripping single quotes -#' off quoted words). CRAN ensures that these fields don't contain phrases -#' like "R package" because that's obvious on CRAN. To make your package more -#' findable on search engines, it's good practice to override the `title` and +#' off quoted words). CRAN ensures that these fields don't contain phrases +#' like "R package" because that's obvious on CRAN. To make your package more +#' findable on search engines, it's good practice to override the `title` and #' `description`, thinking about what people might search for: -#' +#' #' ```yaml #' home: #' title: An R package for pool-noodle discovery @@ -85,45 +85,45 @@ #' using this package to automatically discover and add pool-noodles #' to your growing collection. #' ``` -#' -#' (Note the use of YAML's `>` i.e. "YAML pipes"; this is a convenient way of +#' +#' (Note the use of YAML's `>` i.e. "YAML pipes"; this is a convenient way of #' writing paragraphs of text.) -#' +#' #' ## Dev badges -#' +#' #' pkgdown identifies badges in three ways: -#' -#' - Any image-containing links between `` and -#' ``, as e.g. created by `usethis::use_readme_md()` -#' or `usethis::use_readme_rmd()`. There should always be an empty line after -#' the `` line. If you divide badges into paragraphs, +#' +#' - Any image-containing links between `` and +#' ``, as e.g. created by `usethis::use_readme_md()` +#' or `usethis::use_readme_rmd()`. There should always be an empty line after +#' the `` line. If you divide badges into paragraphs, #' make sure to add an empty line before the `` line. -#' +#' #' - Any image-containing links within `
`. -#' +#' #' - Within the first paragraph, if it only contains image-containing links. -#' +#' #' Identified badges are **removed** from the _main content_. #' They are shown or not in the _sidebar_ depending on the development mode and #' sidebar customization, see the sidebar section. -#' +#' #' # Authors -#' +#' #' By default, pkgdown will display author information in three places: -#' +#' #' * the sidebar, #' * the left part side of the footer, #' * the author page. -#' -#' This documentation describes how to customise the overall author display. -#' See `?build_home` and `?build_site` for details about changing the location +#' +#' This documentation describes how to customise the overall author display. +#' See `?build_home` and `?build_site` for details about changing the location #' of the authors information within the home sidebar and the site footer. -#' +#' #' ## Authors ORCID and bio -#' -#' Author ORCID identification numbers in the `DESCRIPTION` are linked using +#' +#' Author ORCID identification numbers in the `DESCRIPTION` are linked using #' the ORCID logo: -#' +#' #' ```r #' Authors@R: c( #' person("Hadley", "Wickham", , "hadley@rstudio.com", role = c("aut", "cre"), @@ -134,11 +134,11 @@ #' ) #' ) #' ``` -#' -#' If you want to add more details about authors or their involvement with the -#' package, you can use the comment field, which will be rendered on the +#' +#' If you want to add more details about authors or their involvement with the +#' package, you can use the comment field, which will be rendered on the #' authors page. -#' +#' #' ```r #' Authors@R: c( #' person("Hadley", "Wickham", , "hadley@rstudio.com", role = c("aut", "cre"), @@ -149,49 +149,49 @@ #' ) #' ) #' ``` -#' +#' #' ## Additional control via YAML -#' -#' You can control additinal aspects of the authors display via the `authors` +#' +#' You can control additinal aspects of the authors display via the `authors` #' YAML field: -#' +#' #' * display of each author in the footer, sidebar and authors page, #' * which authors (by role) are displayed in the sidebar and footer, -#' * text before authors in the footer, +#' * text before authors in the footer, #' * text before and after authors in the sidebar, #' * text before and after authors on the authors page. -#' -#' You can modify how each author's name is displayed by adding a subsection -#' for `authors`. Each entry in `authors` should be named the author's name +#' +#' You can modify how each author's name is displayed by adding a subsection +#' for `authors`. Each entry in `authors` should be named the author's name #' (matching `DESCRIPTION`) and can contain `href` and/or `html` fields: -#' +#' #' * If `href` is provided, the author's name will be linked to this URL. #' * If `html` is provided, it will be shown instead of the author's name. #' This is particularly useful if you want to display the logo of a corporate -#' sponsor. Use an absolute URL to an image, not a relative link. Use an empty -#' alternative text rather than no alternative text so a screen-reader would +#' sponsor. Use an absolute URL to an image, not a relative link. Use an empty +#' alternative text rather than no alternative text so a screen-reader would #' skip over it. -#' +#' #' ```yaml #' authors: #' firstname lastname: #' href: "http://name-website.com" #' html: "" #' ``` -#' -#' -#' By default, the "developers" list shown in the sidebar and footer is -#' populated by the maintainer ("cre"), authors ("aut"), and funder ("fnd") +#' +#' +#' By default, the "developers" list shown in the sidebar and footer is +#' populated by the maintainer ("cre"), authors ("aut"), and funder ("fnd") #' from the `DESCRIPTION`. You could choose other roles for filtering. #' With the configuration below: -#' -#' * only the maintainer and funder(s) appear in the footer, after the text +#' +#' * only the maintainer and funder(s) appear in the footer, after the text #' "Crafted by", #' * all authors and contributors appear in the sidebar, #' * the authors list on the sidebar is preceded and followed by some text, #' * the authors list on the authors page is preceded and followed by some text. -#' -#' +#' +#' #' ```yaml #' authors: #' footer: @@ -204,32 +204,32 @@ #' before: "This package is proudly brought to you by:" #' after: "See the [changelog](news/index.html) for other contributors. :pray:" #' ``` -#' -#' If you want to filter authors based on something else than their roles, -#' consider using a custom sidebar/footer component +#' +#' If you want to filter authors based on something else than their roles, +#' consider using a custom sidebar/footer component #' (see `?build_home`/`?build_site`, respectively). -#' +#' #' # Sidebar -#' +#' #' You can customise the homepage sidebar with the `home.sidebar` field. -#' It's made up of two pieces: `structure`, which defines the overall layout, -#' and `components`, which defines what each piece looks like. This organisation -#' makes it easy to mix and match the pkgdown defaults with your own +#' It's made up of two pieces: `structure`, which defines the overall layout, +#' and `components`, which defines what each piece looks like. This organisation +#' makes it easy to mix and match the pkgdown defaults with your own #' customisations. -#' +#' #' This is the default structure: -#' +#' #' ``` yaml #' home: #' sidebar: #' structure: [links, license, community, citation, authors, dev] #' ``` -#' +#' #' These are drawn from seven built-in components: -#' -#' - `links`: automated links generated from `URL` and `BugReports` fields +#' +#' - `links`: automated links generated from `URL` and `BugReports` fields #' from `DESCRIPTION` plus manual links from the `home.links` field: -#' +#' #' ``` yaml #' home: #' links: @@ -238,26 +238,26 @@ #' - text: Roadmap #' href: /roadmap.html #' ``` -#' -#' - `license`: Licensing information if `LICENSE`/`LICENCE` or +#' +#' - `license`: Licensing information if `LICENSE`/`LICENCE` or #' `LICENSE.md`/`LICENCE.md` files are present. -#' -#' - `community`: links to to `.github/CONTRIBUTING.md`, +#' +#' - `community`: links to to `.github/CONTRIBUTING.md`, #' `.github/CODE_OF_CONDUCT.md`, etc. -#' -#' - `citation`: link to package citation information. Uses either +#' +#' - `citation`: link to package citation information. Uses either #' `inst/CITATION` or, if absent, information from the `DESCRIPTION`. -#' +#' #' - `authors`: selected authors from the `DESCRIPTION`. -#' -#' - `dev`: development status badges extracted from `README.md`/`index.md`. -#' This is only shown for "development" versions of websites; see -#' "Development mode" in `?build_site` for details. -#' +#' +#' - `dev`: development status badges extracted from `README.md`/`index.md`. +#' This is only shown for "development" versions of websites; see +#' "Development mode" in `?build_site` for details. +#' #' - `toc`: a table of contents for the README (not shown by default). -#' +#' #' You can also add your own components, where `text` is markdown text: -#' +#' #' ``` yaml #' home: #' sidebar: @@ -267,17 +267,17 @@ #' title: Funding #' text: We are *grateful* for funding! #' ``` -#' +#' #' Alternatively, you can provide a ready-made sidebar HTML: -#' +#' #' ``` yaml #' home: #' sidebar: #' html: path-to-sidebar.html #' ``` -#' +#' #' Or completely remove it: -#' +#' #' ``` yaml #' home: #' sidebar: FALSE diff --git a/R/build-news.R b/R/build-news.R index 6ef5c0514..f50bb302f 100644 --- a/R/build-news.R +++ b/R/build-news.R @@ -182,12 +182,12 @@ data_news <- function(pkg = list()) { sections <- sections[!is.na(versions)] if (length(sections) == 0) { - cli::cli_warn(c( + cli::cli_warn(c( "No version headings found in {src_path('NEWS.md')}", i = "See {.help pkgdown::build_news} for expected structure." )) } - + versions <- versions[!is.na(versions)] show_dates <- purrr::pluck(pkg, "meta", "news", "cran_dates", .default = !is_testing()) diff --git a/R/build-redirects.R b/R/build-redirects.R index 2486afd54..d73e32dbe 100644 --- a/R/build-redirects.R +++ b/R/build-redirects.R @@ -1,24 +1,24 @@ #' Build redirects -#' +#' #' @description -#' If you change the structure of your documentation (by renaming vignettes or +#' If you change the structure of your documentation (by renaming vignettes or #' help topics) you can setup redirects from the old content to the new content. -#' One or several now-absent pages can be redirected to a new page (or to a new -#' section of a new page). This works by creating a html page that performs a -#' "meta refresh", which isn't the best way of doing a redirect but works +#' One or several now-absent pages can be redirected to a new page (or to a new +#' section of a new page). This works by creating a html page that performs a +#' "meta refresh", which isn't the best way of doing a redirect but works #' everywhere that you might deploy your site. -#' -#' The syntax is the following, with old paths on the left, and new paths or +#' +#' The syntax is the following, with old paths on the left, and new paths or #' URLs on the right. -#' +#' #' ```yaml #' redirects: #' - ["articles/old-vignette-name.html", "articles/new-vignette-name.html"] #' - ["articles/another-old-vignette-name.html", "articles/new-vignette-name.html"] #' - ["articles/yet-another-old-vignette-name.html", "https://pkgdown.r-lib.org/dev"] #' ``` -#' -#' If for some reason you choose to redirect an existing page make sure to +#' +#' If for some reason you choose to redirect an existing page make sure to #' exclude it from the search index, see `?build_search`. #' #' @inheritParams as_pkgdown diff --git a/R/build-reference-index.R b/R/build-reference-index.R index 8e2ef7500..67e257ba5 100644 --- a/R/build-reference-index.R +++ b/R/build-reference-index.R @@ -137,7 +137,7 @@ check_missing_topics <- function(rows, pkg, error_call = caller_env()) { if (any(missing)) { config_abort( - pkg, + pkg, c( "{sum(missing)} topic{?s} missing from index: {.val {pkg$topics$name[missing]}}.", i = "Either use {.code @keywords internal} to drop from index, or" diff --git a/R/build-reference.R b/R/build-reference.R index d0baf52ce..3e34118da 100644 --- a/R/build-reference.R +++ b/R/build-reference.R @@ -200,7 +200,7 @@ build_reference <- function(pkg = ".", lazy = lazy, examples_env = examples_env, run_dont_run = run_dont_run - )) + )) preview_site(pkg, "reference", preview = preview) } @@ -295,7 +295,7 @@ build_reference_topic <- function(topic, ), error = function(err) { cli::cli_abort( - "Failed to parse Rd in {.file {topic$file_in}}", + "Failed to parse Rd in {.file {topic$file_in}}", parent = err, call = quote(build_reference()) ) diff --git a/R/build-search-docs.R b/R/build-search-docs.R index 6711edcef..2b97a3a7c 100644 --- a/R/build-search-docs.R +++ b/R/build-search-docs.R @@ -39,7 +39,7 @@ build_sitemap <- function(pkg = ".") { doc <- xml2::read_xml( paste0("Site built with pkgdown {version}.
+# check_opengraph validates inputs + + Code + check_open_graph_(list(foo = list()), ) + Condition + Warning in `check_open_graph_()`: + '_pkgdown.yml': Unsupported template.opengraph field: "foo". + Output + named list() + Code + check_open_graph_(list(foo = list(), bar = list())) + Condition + Warning in `check_open_graph_()`: + '_pkgdown.yml': Unsupported template.opengraph fields: "foo" and "bar". + Output + named list() + Code + check_open_graph_(list(twitter = 1)) + Condition + Error in `check_open_graph_()`: + ! '_pkgdown.yml': template.opengraph.twitter must be a list, not a double vector. + Code + check_open_graph_(list(twitter = list())) + Condition + Error in `check_open_graph_()`: + ! '_pkgdown.yml': opengraph.twitter must include either creator or site. + Code + check_open_graph_(list(image = 1)) + Condition + Error in `check_open_graph_()`: + ! '_pkgdown.yml': template.opengraph.image must be a list, not a double vector. + diff --git a/tests/testthat/assets/articles/vignettes/bad-opengraph.Rmd b/tests/testthat/assets/articles/vignettes/bad-opengraph.Rmd new file mode 100644 index 000000000..f6f31e13f --- /dev/null +++ b/tests/testthat/assets/articles/vignettes/bad-opengraph.Rmd @@ -0,0 +1,7 @@ +--- +title: "Introduction to poolnoodlr" +description: "A brief introduction to pool noodles in R." +author: "Mara Averick" +opengraph: + twitter: 1 +--- \ No newline at end of file diff --git a/tests/testthat/test-build-articles.R b/tests/testthat/test-build-articles.R index 198382568..6d6e112d4 100644 --- a/tests/testthat/test-build-articles.R +++ b/tests/testthat/test-build-articles.R @@ -21,7 +21,7 @@ test_that("image links relative to output", { # knitr::include_graphics() "../reference/figures/kitten.jpg", "another-kitten.jpg", - # rmarkdown image + # rmarkdown image "../reference/figures/kitten.jpg", "another-kitten.jpg", # magick::image_read() @@ -292,3 +292,9 @@ test_that("output is reproducible by default, i.e. 'seed' is respected", { expect_snapshot(cat(output)) }) + +test_that("reports on bad open graph meta-data", { + pkg <- local_pkgdown_site(test_path("assets/articles")) + suppressMessages(init_site(pkg)) + expect_snapshot(build_article(pkg = pkg, name = "bad-opengraph"), error = TRUE) +}) diff --git a/tests/testthat/test-build-home-authors.R b/tests/testthat/test-build-home-authors.R index 0782e3190..a13d95322 100644 --- a/tests/testthat/test-build-home-authors.R +++ b/tests/testthat/test-build-home-authors.R @@ -4,7 +4,7 @@ test_that("authors page includes inst/AUTHORS", { suppressMessages(build_citation_authors(pkg)) lines <- read_lines(path(pkg$dst_path, "authors.html")) - expect_true(any(grepl("Hello", lines))) + expect_match(lines, "
Hello", all = FALSE) }) # authors -------------------------------------------------------------------- @@ -127,10 +127,10 @@ test_that("bibtex is escaped", { ' textVersion = ""', ')' )) - + suppressMessages(init_site(pkg)) suppressMessages(build_citation_authors(pkg)) html <- xml2::read_html(path(pkg$dst_path, "authors.html")) - + expect_match(xpath_text(html, "//pre"), "<&>", fixed = TRUE) }) diff --git a/tests/testthat/test-build-home-index.R b/tests/testthat/test-build-home-index.R index 858e8b556..15ba3f433 100644 --- a/tests/testthat/test-build-home-index.R +++ b/tests/testthat/test-build-home-index.R @@ -1,3 +1,12 @@ +test_that("messages about reading and writing", { + pkg <- local_pkgdown_site(test_path("assets/home-index-rmd")) + + expect_snapshot({ + build_home_index(pkg) + build_home_index(pkg) + }) +}) + test_that("title and description come from DESCRIPTION by default", { pkg <- as_pkgdown(test_path("assets/home-index-rmd")) expect_equal(data_home(pkg)$pagetitle, "A test package") @@ -11,7 +20,7 @@ test_that("title and description come from DESCRIPTION by default", { test_that("math is handled", { pkg <- local_pkgdown_site(test_path("assets/home-readme-rmd"), clone = TRUE) write_lines(c("$1 + 1$"), path(pkg$src_path, "README.md")) - + suppressMessages(init_site(pkg)) suppressMessages(build_home_index(pkg)) @@ -24,7 +33,7 @@ test_that("version formatting in preserved", { expect_equal(pkg$version, "1.0.0-9000") suppressMessages(init_site(pkg)) - build_home_index(pkg, quiet = TRUE) + suppressMessages(build_home_index(pkg)) index <- read_lines(path(pkg$dst_path, "index.html")) expect_true(any(grepl("1.0.0-9000", index, fixed = TRUE))) }) @@ -47,7 +56,7 @@ test_that("data_home_sidebar() can be removed", { # nor later -- so probably not to be tested here?! dir_create(path(pkg$dst_path)) - build_home_index(pkg) + suppressMessages(build_home_index(pkg)) html <- xml2::read_html(path(pkg$dst_path, "index.html")) expect_equal(xpath_length(html, ".//aside/*"), 0) }) diff --git a/tests/testthat/test-build-reference-index.R b/tests/testthat/test-build-reference-index.R index 1f7c8ace9..8bd73f716 100644 --- a/tests/testthat/test-build-reference-index.R +++ b/tests/testthat/test-build-reference-index.R @@ -71,10 +71,10 @@ test_that("errors well when a content entry is empty", { - title: bla contents: - aname - - + - ") suppressMessages(init_site(pkg)) - + expect_snapshot(build_reference_index(pkg), error = TRUE) }) diff --git a/tests/testthat/test-build-reference.R b/tests/testthat/test-build-reference.R index 24d376919..7efb599cf 100644 --- a/tests/testthat/test-build-reference.R +++ b/tests/testthat/test-build-reference.R @@ -53,7 +53,7 @@ test_that(".Rd without usage doesn't get Usage section", { pkg <- local_pkgdown_site(test_path("assets/reference")) suppressMessages(init_site(pkg)) suppressMessages(build_reference(pkg, topics = "e")) - + html <- xml2::read_html(path(pkg$dst_path, "reference", "e.html")) expect_equal(xpath_length(html, "//div[@id='ref-usage']"), 0) clean_site(pkg, quiet = TRUE) @@ -122,7 +122,7 @@ test_that("title and page title escapes html", { pkg <- local_pkgdown_site(test_path("assets/reference")) suppressMessages(init_site(pkg)) suppressMessages(build_reference(pkg, topics = "g")) - + html <- xml2::read_html(path(pkg$dst_path, "reference", "g.html")) expect_equal(xpath_text(html, "//title", trim = TRUE), "g <-> h — g • testpackage") expect_equal(xpath_text(html, "//h1", trim = TRUE), "g <-> h") diff --git a/tests/testthat/test-build-search-docs.R b/tests/testthat/test-build-search-docs.R index e8205f4cc..6bec99bbe 100644 --- a/tests/testthat/test-build-search-docs.R +++ b/tests/testthat/test-build-search-docs.R @@ -53,4 +53,4 @@ test_that("build_search() builds the expected search.json with no URL", { test_that("url_node gives informative error", { expect_snapshot(url_node("<"), error = TRUE) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-check.R b/tests/testthat/test-check.R index 7a09611d4..a0b3a7e3c 100644 --- a/tests/testthat/test-check.R +++ b/tests/testthat/test-check.R @@ -1,6 +1,6 @@ test_that("sitrep complains about BS3", { pkg <- local_pkgdown_site(test_path("assets/open-graph"), meta = " - template: + template: bootstrap: 3 ") expect_snapshot(pkgdown_sitrep(pkg)) diff --git a/tests/testthat/test-config.R b/tests/testthat/test-config.R index 1e38b5961..2a2e1742a 100644 --- a/tests/testthat/test-config.R +++ b/tests/testthat/test-config.R @@ -30,10 +30,10 @@ test_that("config_check_list gives informative errors", { pkg <- local_pkgdown_site() config_check_list_ <- function(...) { config_check_list(..., error_pkg = pkg, error_path = "path") - } + } expect_snapshot(error = TRUE, { config_check_list_(1, has_names = "x") config_check_list_(list(x = 1, y = 1), has_names = c("y", "z")) }) -}) +}) diff --git a/tests/testthat/test-init.R b/tests/testthat/test-init.R index 5316b2258..1f8aa314f 100644 --- a/tests/testthat/test-init.R +++ b/tests/testthat/test-init.R @@ -57,11 +57,11 @@ test_that("site meta doesn't break unexpectedly", { test_that("site meta includes vignette subdirectories", { pkg <- local_pkgdown_site() - vig_path <- path(pkg$src_path, "vignettes") + vig_path <- path(pkg$src_path, "vignettes") dir_create(path(vig_path, "a")) file_create(path(vig_path, "a", c("a.Rmd", "b.Rmd"))) pkg <- as_pkgdown(pkg$src_path) meta <- site_meta(pkg) expect_equal(meta$articles, list("a/a" = "a/a.html", "a/b" = "a/b.html")) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-markdown.R b/tests/testthat/test-markdown.R index af42a8c2b..3b79607ca 100644 --- a/tests/testthat/test-markdown.R +++ b/tests/testthat/test-markdown.R @@ -1,13 +1,12 @@ -test_that("handles empty inputs", { - expect_equal(markdown_text_inline(""), NULL) - expect_equal(markdown_text_inline(NULL), NULL) - - expect_equal(markdown_text_block(NULL), NULL) - expect_equal(markdown_text_block(""), NULL) +test_that("handles empty inputs (returns NULL)", { + expect_null(markdown_text_inline("")) + expect_null(markdown_text_inline(NULL)) + expect_null(markdown_text_block(NULL)) + expect_null(markdown_text_block("")) path <- withr::local_tempfile() file_create(path) - expect_equal(markdown_body(path), NULL) + expect_null(markdown_body(path)) }) test_that("header attributes are parsed", { diff --git a/tests/testthat/test-navbar-menu.R b/tests/testthat/test-navbar-menu.R index bfeb4a635..5152b2f37 100644 --- a/tests/testthat/test-navbar-menu.R +++ b/tests/testthat/test-navbar-menu.R @@ -44,6 +44,14 @@ test_that("bullet class varies based on depth", { ) }) +test_that("icons warn if no aria-label", { + reset_message_verbosity("icon-aria-label") + + expect_snapshot({ + . <- navbar_html(menu_icon("fa-question", "https://example.com", NULL)) + }) +}) + test_that("icons extract base iconset class automatically", { expect_match( navbar_html(menu_icon("fa-question", "https://example.com", "label")), @@ -80,11 +88,11 @@ test_that("simple components don't change without warning", { test_that("navbar_html_text() combines icons and text", { expect_equal(navbar_html_text(list(text = "a")), 'a') expect_equal( - navbar_html_text(list(icon = "fas-github")), + navbar_html_text(list(icon = "fas-github", `aria-label` = "github")), '' ) expect_equal( - navbar_html_text(list(text = "a", icon = "fas-github")), + navbar_html_text(list(text = "a", icon = "fas-github", `aria-label` = "github")), ' a' ) }) diff --git a/tests/testthat/test-navbar.R b/tests/testthat/test-navbar.R index 8b2c524b6..4ced204ab 100644 --- a/tests/testthat/test-navbar.R +++ b/tests/testthat/test-navbar.R @@ -82,7 +82,7 @@ test_that("data_navbar() works by default", { test_that("data_navbar() can re-order default elements", { pkg <- local_pkgdown_site(meta = " - template: + template: bootstrap: 5 repo: url: @@ -187,7 +187,7 @@ test_that("dropdowns on right are right-aligned", { articles = menu_submenu("Articles", list(menu_heading("A"), menu_heading("B"))) ) pkg <- list(bs_version = 5) - + right <- xml2::read_html(render_navbar_links(x, pkg = pkg, side = "right")) left <- xml2::read_html(render_navbar_links(x, pkg = pkg, side = "left")) diff --git a/tests/testthat/test-render.R b/tests/testthat/test-render.R index 95cf03f4f..1b3cfcd7f 100644 --- a/tests/testthat/test-render.R +++ b/tests/testthat/test-render.R @@ -69,3 +69,17 @@ test_that("can include text in header, before body, and after body", { c("in header", "before body", "after body") ) }) + +test_that("check_opengraph validates inputs", { + check_open_graph_ <- function(...) { + check_open_graph(..., path = "_pkgdown.yml") + } + + expect_snapshot(error = TRUE, { + check_open_graph_(list(foo = list()), ) + check_open_graph_(list(foo = list(), bar = list())) + check_open_graph_(list(twitter = 1)) + check_open_graph_(list(twitter = list())) + check_open_graph_(list(image = 1)) + }) +}) diff --git a/tests/testthat/test-repo.R b/tests/testthat/test-repo.R index 8ac2a0f40..45f68a720 100644 --- a/tests/testthat/test-repo.R +++ b/tests/testthat/test-repo.R @@ -61,7 +61,7 @@ test_that("repo_source() is robust to trailing slash", { meta <- function(x) { list(repo = list(url = list(source = x))) - } + } source <- "Source:
a
"
expect_equal(repo_source(meta("http://example.com"), "a"), source)
expect_equal(repo_source(meta("http://example.com/"), "a"), source)
diff --git a/tests/testthat/test-usage.R b/tests/testthat/test-usage.R
index 2f9b01258..dea67d31a 100644
--- a/tests/testthat/test-usage.R
+++ b/tests/testthat/test-usage.R
@@ -5,7 +5,7 @@ test_that("usage escapes special characters", {
usage2html <- function(x) {
rd <- rd_text(paste0("\\usage{", x, "}"), FALSE)[[1]]
- as_data(rd)
+ as_data(rd)
}
expect_snapshot({
@@ -13,7 +13,7 @@ test_that("usage escapes special characters", {
cat(strip_html_tags(usage2html("# <>\nx")))
"Unparseable"
cat(strip_html_tags(usage2html("# <>\n<")))
- })
+ })
})
test_that("S4 methods gets comment", {