diff --git a/R/init.R b/R/init.R index bff37086a..c639cad54 100644 --- a/R/init.R +++ b/R/init.R @@ -72,6 +72,10 @@ copy_assets <- function(pkg = ".") { copy_asset_dir(pkg, assets) } + if (has_versions(pkg)) { + copy_asset_dir(pkg, path_pkgdown("version-selector")) + } + # extras copy_asset_dir(pkg, "pkgdown", file_regexp = "^extra") # site assets @@ -157,3 +161,9 @@ is_non_pkgdown_site <- function(dst_path) { length(top_level) >= 1 && !"pkgdown.yml" %in% path_file(top_level) } + +has_versions <- function(pkg = ".") { + pkg <- as_pkgdown(pkg) + + file.exists(path(pkg$src_path, "pkgdown", "assets", "versions.json")) +} diff --git a/R/render.R b/R/render.R index 5b861a2db..abbc29505 100644 --- a/R/render.R +++ b/R/render.R @@ -107,6 +107,7 @@ data_template <- function(pkg = ".", depth = 0L) { css = path_first_existing(pkg$src_path, "pkgdown", "extra.css"), js = path_first_existing(pkg$src_path, "pkgdown", "extra.js") ) + out$version_selector <- has_versions(pkg) out$includes <- purrr::pluck(pkg, "meta", "template", "includes", .default = list()) out$yaml <- purrr::pluck(pkg, "meta", "template", "params", .default = list()) # Force inclusion so you can reliably refer to objects inside yaml diff --git a/inst/BS3/templates/head.html b/inst/BS3/templates/head.html index 540c5531d..5bdcb5835 100644 --- a/inst/BS3/templates/head.html +++ b/inst/BS3/templates/head.html @@ -56,6 +56,10 @@ {{#js}}{{/js}} {{/extra}} +{{#version_selector}} + +{{/version_selector}} + {{#opengraph}} {{#description}} diff --git a/inst/BS5/templates/head.html b/inst/BS5/templates/head.html index 56d7259cb..dde030991 100644 --- a/inst/BS5/templates/head.html +++ b/inst/BS5/templates/head.html @@ -46,6 +46,10 @@ {{#js}}{{/js}} {{/extra}} +{{#version_selector}} + +{{/version_selector}} + {{#opengraph}} {{#description}} diff --git a/inst/BS5/templates/navbar.html b/inst/BS5/templates/navbar.html index b3959c708..bab3649f4 100644 --- a/inst/BS5/templates/navbar.html +++ b/inst/BS5/templates/navbar.html @@ -4,7 +4,9 @@ {{#includes}}{{{before_title}}}{{/includes}} {{#site}}{{title}}{{/site}} - {{#package}}{{version}}{{/package}} + + {{#package}}{{version}}{{/package}} + {{#includes}}{{{before_navbar}}}{{/includes}}