From d9669b14986f564f43131e0f16f71a8bc952ff2c Mon Sep 17 00:00:00 2001 From: elena Date: Thu, 23 Nov 2023 15:19:11 +0100 Subject: [PATCH 1/5] expand repo links --- R/bs4_book.R | 27 +++++++++++++++++++++++---- man/publish_book.Rd | 16 ++++++++++------ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/R/bs4_book.R b/R/bs4_book.R index 9f9b13403..97c96c072 100644 --- a/R/bs4_book.R +++ b/R/bs4_book.R @@ -419,16 +419,35 @@ 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]]) + repo_view <- repo_edit + } else if(grepl("bitbucket", repo$base)){ + repo_edit <- paste0(repo$base, "/browse/", rmd_index[[active]]) + repo_view <- repo_edit + } 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("dev.azure", 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) 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 From 7597ca499bfeeee0f74c13707dad6210b4047ec0 Mon Sep 17 00:00:00 2001 From: elena Date: Thu, 23 Nov 2023 15:44:04 +0100 Subject: [PATCH 2/5] add svglite in suggests --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 8622968ef..9cd2de811 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -78,6 +78,7 @@ Suggests: rsconnect (>= 0.4.3), servr (>= 0.13), shiny, + svglite, tibble, testit (>= 0.9), tufte, From f83237100934c6ee98437c251c6bf1ea4c3a5300 Mon Sep 17 00:00:00 2001 From: elena Date: Thu, 23 Nov 2023 16:56:12 +0100 Subject: [PATCH 3/5] open link in a new tab --- R/bs4_book.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/bs4_book.R b/R/bs4_book.R index 97c96c072..5fd5c527a 100644 --- a/R/bs4_book.R +++ b/R/bs4_book.R @@ -566,6 +566,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" } } From af0908b88727ced4a1069bceb00e3ea6207881aa Mon Sep 17 00:00:00 2001 From: elena Date: Fri, 24 Nov 2023 16:11:11 +0100 Subject: [PATCH 4/5] svglite book needs --- DESCRIPTION | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9cd2de811..d74d442c1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -78,7 +78,6 @@ Suggests: rsconnect (>= 0.4.3), servr (>= 0.13), shiny, - svglite, tibble, testit (>= 0.9), tufte, @@ -91,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 From 5e095329ef5dec113bcc0d0f98c31b6e12b64115 Mon Sep 17 00:00:00 2001 From: elena Date: Mon, 27 Nov 2023 12:34:37 +0100 Subject: [PATCH 5/5] update urls & add tests --- R/bs4_book.R | 10 +++--- tests/testthat/test-bs4_book.R | 66 ++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/R/bs4_book.R b/R/bs4_book.R index 5fd5c527a..e03673b47 100644 --- a/R/bs4_book.R +++ b/R/bs4_book.R @@ -420,11 +420,13 @@ tweak_navbar <- function(html, toc, active = "", rmd_index = NULL, repo = NULL) } if(grepl("dev.azure", repo$base)) { - repo_edit <- paste0(repo$base, "?path=/", rmd_index[[active]]) + 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, "/browse/", rmd_index[[active]]) - repo_view <- repo_edit + 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]]) @@ -441,7 +443,7 @@ tweak_navbar <- function(html, toc, active = "", rmd_index = NULL, repo = NULL) "fab fa-github" } else if (grepl("dev.azure", repo$base)) { "fab fa-microsoft" - } else if (grepl("dev.azure", repo$base)) { + } else if (grepl("bitbucket", repo$base)) { "fab fa-bitbucket" } else { "fab fa-gitlab" 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/')