diff --git a/DESCRIPTION b/DESCRIPTION index 7222eeaaa..379a92463 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,6 +45,7 @@ Suggests: diffviewer, evaluate, gert, + gt, htmltools, htmlwidgets, knitr, diff --git a/NAMESPACE b/NAMESPACE index 7ae939ddb..697768d9e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -89,6 +89,7 @@ S3method(as_html,tag_url) S3method(as_html,tag_var) S3method(as_html,tag_verb) S3method(pkgdown_print,default) +S3method(pkgdown_print,gt_tbl) S3method(pkgdown_print,htmlwidget) S3method(print,pkgdown_xml) S3method(print,print_yaml) @@ -116,6 +117,7 @@ export(build_favicons) export(build_home) export(build_home_index) export(build_news) +export(build_redirects) export(build_reference) export(build_reference_index) export(build_search) diff --git a/NEWS.md b/NEWS.md index 3490d069a..e4a732325 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ * Anchors are displayed when they're the target of a link. * `build_reference()` adds anchors to arguments making it possible to link directly to an argument, if desired. A subtle visual treatment makes it easy to see which argument is targeted (#2228). +* `build_redirects()` is now exported to make it easier to document (#2500). +* `build_reference()` now automatically renders any tables created by gt (#2326). * `build_articles()` now drops a section called "internal". This allows you to have articles that either aren't indexed at all or are included manually elsewhere in the navbar (#2205). * `as.pkgdown()` will no longer prompt you to install a missing template package from CRAN, since these are almost always found in GitHub (#2076). * `init_site()` once again describes one copy per line, and now uses a better prefix when copying assets from pkgdown itself (#2445). diff --git a/R/build-redirects.R b/R/build-redirects.R index 9bd64871f..781fb5e92 100644 --- a/R/build-redirects.R +++ b/R/build-redirects.R @@ -1,3 +1,28 @@ +#' Build redirects +#' +#' @description +#' 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 +#' everywhere that you might deploy your site. +#' +#' 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 +#' exclude it from the search index, see `?build_search`. +#' +#' @inheritParams as_pkgdown +#' @export build_redirects <- function(pkg = ".", override = list()) { pkg <- section_init(pkg, depth = 1L, override = override) diff --git a/R/build.R b/R/build.R index 97ea45a3a..ca1b44243 100644 --- a/R/build.R +++ b/R/build.R @@ -9,6 +9,7 @@ #' * [build_articles()] #' * [build_tutorials()] #' * [build_news()] +#' * [build_redirects()] #' #' See the documentation for the each function to learn how to control #' that aspect of the site. This page documents options that affect the @@ -276,27 +277,6 @@ #' install_metadata: true #' ``` #' -#' # Redirects -#' 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 -#' everywhere that you might deploy your site. -#' -#' 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 -#' exclude it from the search index, see `?build_search`. -#' #' # Options #' Users with limited internet connectivity can disable CRAN checks by setting #' `options(pkgdown.internet = FALSE)`. This will also disable some features diff --git a/R/pkgdown_print.R b/R/pkgdown_print.R index 0a107cee8..f0e6f4ea8 100644 --- a/R/pkgdown_print.R +++ b/R/pkgdown_print.R @@ -40,3 +40,15 @@ pkgdown_print.htmlwidget <- function(x, visible = TRUE) { x$height <- x$height %||% (settings$fig.height * settings$dpi) x } + +#' @export +pkgdown_print.gt_tbl <- function(x, visible = TRUE) { + if (!visible) { + return(invisible()) + } + + htmltools::div( + class = "gt-table", + gt::as_raw_html(x) + ) +} diff --git a/R/test.R b/R/test.R index e63affb14..366596151 100644 --- a/R/test.R +++ b/R/test.R @@ -82,6 +82,15 @@ NULL #' text(2, 5, "Hello", srt = 30, cex = 2) NULL +#' Test case: tables +#' +#' @name test-tables +#' @keywords internal +#' @family tests +#' @examples +#' gt::gt(head(mtcars)) +NULL + #' Test case: don't #' #' @name test-dont diff --git a/inst/BS5/assets/pkgdown.scss b/inst/BS5/assets/pkgdown.scss index 35845789f..7e14ebc11 100644 --- a/inst/BS5/assets/pkgdown.scss +++ b/inst/BS5/assets/pkgdown.scss @@ -435,6 +435,12 @@ pre { padding: 1rem 0.5rem; } +// Spacing tweaks for gt table +pre div.gt-table { + white-space: normal; + margin-top: 1rem; +} + // "Pop" code out of page margins on small screens to give a little more room @include media-breakpoint-down(sm) { // div.section div.sourceCode pre diff --git a/man/build_redirects.Rd b/man/build_redirects.Rd new file mode 100644 index 000000000..b3eb55270 --- /dev/null +++ b/man/build_redirects.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/build-redirects.R +\name{build_redirects} +\alias{build_redirects} +\title{Build redirects} +\usage{ +build_redirects(pkg = ".", override = list()) +} +\arguments{ +\item{pkg}{Path to package.} + +\item{override}{An optional named list used to temporarily override +values in \verb{_pkgdown.yml}} +} +\description{ +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 +everywhere that you might deploy your site. + +The syntax is the following, with old paths on the left, and new paths or +URLs on the right. + +\if{html}{\out{
}}\preformatted{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{html}{\out{
}} + +If for some reason you choose to redirect an existing page make sure to +exclude it from the search index, see \code{?build_search}. +} diff --git a/man/build_site.Rd b/man/build_site.Rd index 24b9bd170..50de79805 100644 --- a/man/build_site.Rd +++ b/man/build_site.Rd @@ -69,6 +69,7 @@ so it is available for vignettes.} \item \code{\link[=build_articles]{build_articles()}} \item \code{\link[=build_tutorials]{build_tutorials()}} \item \code{\link[=build_news]{build_news()}} +\item \code{\link[=build_redirects]{build_redirects()}} } See the documentation for the each function to learn how to control @@ -329,27 +330,6 @@ time (e.g. because behind a firewall or requires auth). } } -\section{Redirects}{ -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 -everywhere that you might deploy your site. - -The syntax is the following, with old paths on the left, and new paths or -URLs on the right. - -\if{html}{\out{
}}\preformatted{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{html}{\out{
}} - -If for some reason you choose to redirect an existing page make sure to -exclude it from the search index, see \code{?build_search}. -} - \section{Options}{ Users with limited internet connectivity can disable CRAN checks by setting \code{options(pkgdown.internet = FALSE)}. This will also disable some features diff --git a/man/index.Rd b/man/index.Rd index fd33381c6..71dc7bcba 100644 --- a/man/index.Rd +++ b/man/index.Rd @@ -18,6 +18,7 @@ Other tests: \code{\link{test-output-styles}}, \code{\link{test-params}}, \code{\link{test-sexpr-title}}, +\code{\link{test-tables}}, \code{\link{test-verbatim}} } \concept{tests} diff --git a/man/test-crayon.Rd b/man/test-crayon.Rd index 3a159568b..aa779cb85 100644 --- a/man/test-crayon.Rd +++ b/man/test-crayon.Rd @@ -25,6 +25,7 @@ Other tests: \code{\link{test-output-styles}}, \code{\link{test-params}}, \code{\link{test-sexpr-title}}, +\code{\link{test-tables}}, \code{\link{test-verbatim}} } \concept{tests} diff --git a/man/test-dont.Rd b/man/test-dont.Rd index 804b68984..a8be6493b 100644 --- a/man/test-dont.Rd +++ b/man/test-dont.Rd @@ -56,6 +56,7 @@ Other tests: \code{\link{test-output-styles}}, \code{\link{test-params}}, \code{\link{test-sexpr-title}}, +\code{\link{test-tables}}, \code{\link{test-verbatim}} } \concept{tests} diff --git a/man/test-figures.Rd b/man/test-figures.Rd index 5ca5d8b37..208b1a3e6 100644 --- a/man/test-figures.Rd +++ b/man/test-figures.Rd @@ -25,6 +25,7 @@ Other tests: \code{\link{test-output-styles}}, \code{\link{test-params}}, \code{\link{test-sexpr-title}}, +\code{\link{test-tables}}, \code{\link{test-verbatim}} } \concept{tests} diff --git a/man/test-links.Rd b/man/test-links.Rd index 493b035e9..6c6a9b3af 100644 --- a/man/test-links.Rd +++ b/man/test-links.Rd @@ -25,6 +25,7 @@ Other tests: \code{\link{test-output-styles}}, \code{\link{test-params}}, \code{\link{test-sexpr-title}}, +\code{\link{test-tables}}, \code{\link{test-verbatim}} } \concept{tests} diff --git a/man/test-lists.Rd b/man/test-lists.Rd index 88cbc3a54..edef2f8c7 100644 --- a/man/test-lists.Rd +++ b/man/test-lists.Rd @@ -58,6 +58,7 @@ Other tests: \code{\link{test-output-styles}}, \code{\link{test-params}}, \code{\link{test-sexpr-title}}, +\code{\link{test-tables}}, \code{\link{test-verbatim}} } \concept{tests} diff --git a/man/test-long-lines.Rd b/man/test-long-lines.Rd index 869cd3888..39cd7cb03 100644 --- a/man/test-long-lines.Rd +++ b/man/test-long-lines.Rd @@ -26,6 +26,7 @@ Other tests: \code{\link{test-output-styles}}, \code{\link{test-params}}, \code{\link{test-sexpr-title}}, +\code{\link{test-tables}}, \code{\link{test-verbatim}} } \concept{tests} diff --git a/man/test-output-styles.Rd b/man/test-output-styles.Rd index e7655192f..674cdc0ef 100644 --- a/man/test-output-styles.Rd +++ b/man/test-output-styles.Rd @@ -33,6 +33,7 @@ Other tests: \code{\link{test-long-lines}}, \code{\link{test-params}}, \code{\link{test-sexpr-title}}, +\code{\link{test-tables}}, \code{\link{test-verbatim}} } \concept{tests} diff --git a/man/test-params.Rd b/man/test-params.Rd index 3c75c26f7..3439897b3 100644 --- a/man/test-params.Rd +++ b/man/test-params.Rd @@ -20,6 +20,7 @@ Other tests: \code{\link{test-long-lines}}, \code{\link{test-output-styles}}, \code{\link{test-sexpr-title}}, +\code{\link{test-tables}}, \code{\link{test-verbatim}} } \concept{tests} diff --git a/man/test-sexpr-title.Rd b/man/test-sexpr-title.Rd index 039fbf19d..ad502afa3 100644 --- a/man/test-sexpr-title.Rd +++ b/man/test-sexpr-title.Rd @@ -17,6 +17,7 @@ Other tests: \code{\link{test-long-lines}}, \code{\link{test-output-styles}}, \code{\link{test-params}}, +\code{\link{test-tables}}, \code{\link{test-verbatim}} } \concept{tests} diff --git a/man/test-tables.Rd b/man/test-tables.Rd new file mode 100644 index 000000000..5a27a2ad9 --- /dev/null +++ b/man/test-tables.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/test.R +\name{test-tables} +\alias{test-tables} +\title{Test case: tables} +\description{ +Test case: tables +} +\examples{ +gt::gt(head(mtcars)) +} +\seealso{ +Other tests: +\code{\link{index}}, +\code{\link{test-crayon}}, +\code{\link{test-dont}}, +\code{\link{test-figures}}, +\code{\link{test-links}}, +\code{\link{test-lists}}, +\code{\link{test-long-lines}}, +\code{\link{test-output-styles}}, +\code{\link{test-params}}, +\code{\link{test-sexpr-title}}, +\code{\link{test-verbatim}} +} +\concept{tests} +\keyword{internal} diff --git a/man/test-verbatim.Rd b/man/test-verbatim.Rd index 96d22b3c3..a2d74128b 100644 --- a/man/test-verbatim.Rd +++ b/man/test-verbatim.Rd @@ -47,7 +47,8 @@ Other tests: \code{\link{test-long-lines}}, \code{\link{test-output-styles}}, \code{\link{test-params}}, -\code{\link{test-sexpr-title}} +\code{\link{test-sexpr-title}}, +\code{\link{test-tables}} } \concept{tests} \keyword{internal} diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 74a8c8353..1cecac508 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -53,13 +53,8 @@ reference: desc: Build a complete site or one of its components. contents: - build_site - - build_articles - - build_favicons - - build_home - - build_news - - build_tutorials - - build_reference - - build_search + - starts_with("build_") + - -build_site_github_pages - init_site - preview_site - pkgdown_sitrep