Skip to content

Commit

Permalink
Allow template packages to provide a default configuration `_pkgdown.…
Browse files Browse the repository at this point in the history
…yml` (#1565)

Co-authored-by: Hadley Wickham <h.wickham@gmail.com>
  • Loading branch information
maelle and hadley committed Mar 15, 2021
1 parent bebcebb commit 95af5d4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# pkgdown (development version)

* Allow template packages to provide a default configuration `_pkgdown.yml`,
stored in `inst/pkgdown/_pkgdown.yml`. This can be used to set (e.g.) author
definitions, Bootstrap version and variables, the sidebar, footer, navbar, etc.

Configuration parameters supplied by a template package have the lowest priority
They will be overridden by a local `_pkgdown.yml` which is in turn overridden by
`override` parameter of `build_site()`. (#1499)

* pkgdown now contains templates using Bootstrap 4 (with help from @jayhesselberth).
* Easy customisation of colours and fonts with bslib
* Thoughtful typography to make the contents as easy as possible to read, regardless of the size of your device.
Expand Down
16 changes: 9 additions & 7 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,20 @@ copy_assets <- function(pkg = ".") {

# Copy assets from package
if (!is.null(template$package)) {
copy_asset_dir(
pkg,
path_package_pkgdown(
template$package,
bs_version = pkg$bs_version,
"assets"
)
assets <- path_package_pkgdown(
template$package,
bs_version = get_bs_version(pkg),
"assets"
)

copy_asset_dir(pkg, assets)
}
}

copy_asset_dir <- function(pkg, from_dir, file_regexp = NULL) {
if (length(from_dir) == 0) {
return(character())
}
from_path <- path_abs(from_dir, pkg$src_path)
if (!file_exists(from_path)) {
return(character())
Expand Down
16 changes: 16 additions & 0 deletions R/package.r
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ as_pkgdown <- function(pkg = ".", override = list()) {
meta <- read_meta(pkg)
meta <- utils::modifyList(meta, override)

template_config <- find_template_config(meta[["template"]]$package)
meta <- modify_list(template_config, meta)

# Ensure the URL has no trailing slash
if (!is.null(meta$url)) {
meta$url <- sub("/$", "", meta$url)
Expand Down Expand Up @@ -213,3 +216,16 @@ package_vignettes <- function(path = ".") {
description = desc
)
}

find_template_config <- function(package) {
if (is.null(package)) {
return(list())
}

config <- path_package_pkgdown(package, bs_version = NULL, "_pkgdown.yml")
if (length(config) == 0) {
return(list())
}

yaml::yaml.load_file(config) %||% list()
}
5 changes: 1 addition & 4 deletions R/utils-fs.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ path_package_pkgdown <- function(package, bs_version = NULL, ...) {
return(path_package_pkgdown(package, bs_version = NULL, ...))
}

stop(
package, " does not contain ", src_path("inst/pkgdown/", ...),
call. = FALSE
)
return(character())
}

pkg_path
Expand Down
1 change: 1 addition & 0 deletions R/utils.r
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,6 @@ modify_list <- function(x, y) {
if (is.null(y)) {
return(x)
}

utils::modifyList(x, y)
}

0 comments on commit 95af5d4

Please sign in to comment.