r-lib / pkgdown

Generate static html documentation for an R package

Home Page:https://pkgdown.r-lib.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add toggle between development and released version websites

mccarthy-m-g opened this issue · comments

Summary

It would be nice if there was a convenient way to toggle between the development and released versions of a package's website (when both of these exist).

For example, by default the pkgdown website goes to the documentation for the released version (https://pkgdown.r-lib.org); but the development version website can be accessed by adding /dev/ to the URL (https://pkgdown.r-lib.org/dev/). However, this is a "hidden" feature, and it would be nice to make it obvious that a website for the development version is also available.

Implementation

A simple implementation would be to add links to the homepage sidebar that use pkgdown's selective HTML classes to dynamically show the appropriate link. For example, when you are on the release website you would see View in-development version in the Links sidebar; and when you are on the development website you would see View release version in the Links sidebar.

I believe the only changes needed to support this would be to update these lines to include the relevant classed links:

links <- c(
link_url(sprintf(tr_("View on %s"), repo$repo), repo$url),
link_url(tr_("Browse source code"), repo_home(pkg)),
link_url(tr_("Report a bug"), pkg$desc$get_field("BugReports", default = NULL)),
purrr::map_chr(links, ~ link_url(.$text, .$href))
)

And to add an optional class argument to the internal link_url() function:

link_url <- function(text, href) {
if (!is.null(href)) {
paste0("<a href='", href, "'>", text, "</a>")
}
}

Duplicate of #1373

Unfortunately I think it's a little trickier than you outline because we don't always know if there's a dev or released site, and we don't want to generate broken links. I think that implies we need to do something dynamically with js.