diff --git a/DESCRIPTION b/DESCRIPTION index 8622968ef..d74d442c1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -90,7 +90,7 @@ BugReports: https://github.com/rstudio/bookdown/issues SystemRequirements: Pandoc (>= 1.17.2) RoxygenNote: 7.2.3 Encoding: UTF-8 -Config/Needs/book: remotes, webshot +Config/Needs/book: remotes, webshot, svglite Config/Needs/website: pkgdown, tidyverse/tidytemplate, rstudio/quillt Config/testthat/edition: 3 VignetteBuilder: knitr diff --git a/R/bs4_book.R b/R/bs4_book.R index 9f9b13403..e03673b47 100644 --- a/R/bs4_book.R +++ b/R/bs4_book.R @@ -419,16 +419,37 @@ tweak_navbar <- function(html, toc, active = "", rmd_index = NULL, repo = NULL) repo$subdir <- paste0(repo$subdir, "/") } - repo_edit <- paste0(repo$base, "/edit/", repo$branch, "/", repo$subdir, rmd_index[[active]]) - repo_view <- paste0(repo$base, "/blob/", repo$branch, "/", repo$subdir, rmd_index[[active]]) + if(grepl("dev.azure", repo$base)) { + repo_edit <- paste0(repo$base, "?path=/", rmd_index[[active]], "&version=GB", + repo$branch) + repo_view <- repo_edit + } else if(grepl("bitbucket", repo$base)){ + repo_edit <- paste0(repo$base, "/src/", repo$branch, "/", repo$subdir, rmd_index[[active]], + "?mode=edit&at=", repo$branch) + repo_view <- paste0(repo$base, "/src/", repo$branch, "/", repo$subdir, rmd_index[[active]]) + } else { + repo_edit <- paste0(repo$base, "/edit/", repo$branch, "/", repo$subdir, rmd_index[[active]]) + repo_view <- paste0(repo$base, "/blob/", repo$branch, "/", repo$subdir, rmd_index[[active]]) + } + } else { repo_edit <- NULL repo_view <- NULL } if (!is.null(repo$base)) { - icon <- repo$icon %n% - ifelse(grepl("github\\.com", repo$base), "fab fa-github", "fab fa-gitlab") + icon <- repo$icon %n% { + if(grepl("github\\.com", repo$base)) { + "fab fa-github" + } else if (grepl("dev.azure", repo$base)) { + "fab fa-microsoft" + } else if (grepl("bitbucket", repo$base)) { + "fab fa-bitbucket" + } else { + "fab fa-gitlab" + } + } + template_link_icon(html, ".//a[@id='book-repo']", icon) template_link_icon(html, ".//a[@id='book-source']", icon) template_link_icon(html, ".//a[@id='book-edit']", icon) @@ -547,6 +568,7 @@ template_link <- function(html, xpath, href) { xml2::xml_remove(xml2::xml_parent(node)) } else { xml2::xml_attr(node, "href") <- href + xml2::xml_attr(node, "target") <- "_blank" } } diff --git a/man/publish_book.Rd b/man/publish_book.Rd index 091c75a04..856ae16a1 100644 --- a/man/publish_book.Rd +++ b/man/publish_book.Rd @@ -23,12 +23,16 @@ published to account or any single account already associated with \item{server}{Server to publish to (by default beta.rstudioconnect.com but any RStudio Connect server can be published to).} -\item{render}{Rendering behavior for site: "none" to upload a -static version of the current contents of the site directory; -"local" to render the site locally then upload it; "server" to -render the site on the server. Note that for "none" and "local" -R scripts (.R) and markdown documents (.Rmd and .md) will not be -uploaded to the server.} +\item{render}{Rendering behavior for site: +\itemize{ +\item \code{"none"} uploads a static version of the current contents of +the site directory. +\item \code{"local"} renders the site locally then uploads it. +\item \code{"server"} uploads the source of the site to render on the server. +} + +Note that for \code{"none"} and \code{"local"} source files (e.g. \code{.R}, \code{.Rmd} and +\code{.md}) will not be uploaded to the server.} } \description{ Publish a book to the web. Note that you should be sure to render all diff --git a/tests/testthat/test-bs4_book.R b/tests/testthat/test-bs4_book.R index 294b22bde..0da3ff259 100644 --- a/tests/testthat/test-bs4_book.R +++ b/tests/testthat/test-bs4_book.R @@ -82,6 +82,36 @@ test_that("bs4_book() repo specification works - GitLab", { ) }) +test_that("bs4_book() repo specification works - Azure Devops", { + skip_if_bs4_book_deps_missing() + book <- local_bs4_book( + output_options = list( + repo = "https://dev.azure.com/elenasaletter/_git/test_book" + ) + ) + html <- xml2::read_html(file.path(book, "_book", "index.html")) + + expect_equal( + xml2::xml_attr(xml2::xml_child(xml2::xml_find_first(html, "//a[@id='book-repo']")), "class"), + "fab fa-microsoft" + ) +}) + +test_that("bs4_book() repo specification works - Bitbucket", { + skip_if_bs4_book_deps_missing() + book <- local_bs4_book( + output_options = list( + repo = "https://bitbucket.org/test-book/test_book/src/master/" + ) + ) + html <- xml2::read_html(file.path(book, "_book", "index.html")) + + expect_equal( + xml2::xml_attr(xml2::xml_child(xml2::xml_find_first(html, "//a[@id='book-repo']")), "class"), + "fab fa-bitbucket" + ) +}) + test_that("bs4_book() repo specification works - custom icon", { skip_if_bs4_book_deps_missing() book <- local_bs4_book( @@ -118,6 +148,42 @@ test_that("bs4_book() repo specification works - custom icon GitHub", { ) }) +test_that("bs4_book() repo specification works - custom icon - Azure Devops", { + skip_if_bs4_book_deps_missing() + book <- local_bs4_book( + output_options = list( + repo = list( + base = "https://dev.azure.com/elenasaletter/_git/test_book", + icon = "fas fa-air-freshener" + ) + ) + ) + html <- xml2::read_html(file.path(book, "_book", "index.html")) + + expect_equal( + xml2::xml_attr(xml2::xml_child(xml2::xml_find_first(html, "//a[@id='book-repo']")), "class"), + "fas fa-air-freshener" + ) +}) + +test_that("bs4_book() repo specification works - custom icon - Bitbucket", { + skip_if_bs4_book_deps_missing() + book <- local_bs4_book( + output_options = list( + repo = list( + base = "https://bitbucket.org/test-book/test_book/src/master/", + icon = "fas fa-air-freshener" + ) + ) + ) + html <- xml2::read_html(file.path(book, "_book", "index.html")) + + expect_equal( + xml2::xml_attr(xml2::xml_child(xml2::xml_find_first(html, "//a[@id='book-repo']")), "class"), + "fas fa-air-freshener" + ) +}) + test_that("bs4_book() metadata tweaking works -- index", { skip_if_bs4_book_deps_missing() book <- local_bs4_book(description = "A very nice book.", url = 'https://example.com/')