Skip to content

Commit dde4610

Browse files
Only remove trailing slashes in tidyverse_url() (#1527)
* Don't use ui_*() functions inside ui_code_block() * only remove trailing slash in tv urls * `site_url` doesn't exist yet * Be less opinionated about trailing slash * Don't strip trailing slash in pkgdown_url() * Add a NEWS bullet * Add a test Co-authored-by: Jenny Bryan <[email protected]>
1 parent 695664a commit dde4610

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# usethis (development version)
22

3+
pkgdown-related functions no longer automatically strip a trailing slash from the pkgdown site URL, in order to play more nicely with CRAN's URL checks (#1526).
4+
35
`edit_pkgdown_config()` is a new function that opens the pkgdown YAML configuration file for the current Project, if such a file exists.
46

57
The error thrown when reporting an unsupported GitHub configuration has been fixed for forward compatibility with a future version of rlang, i.e. what is anticipated to be rlang v1.0.0.

R/code-of-conduct.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use_code_of_conduct <- function(contact, path = NULL) {
4242

4343
href <- pkgdown_url(pedantic = TRUE) %||%
4444
"https://contributor-covenant.org/version/2/0"
45+
href <- sub("/$", "", href)
4546
href <- paste0(href, "/CODE_OF_CONDUCT.html")
4647

4748
ui_todo("Don't forget to describe the code of conduct in your README:")

R/pkgdown.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ use_pkgdown_github_pages <- function() {
7474
site <- use_github_pages()
7575
use_github_action("pkgdown")
7676

77-
site_url <- sub("/$", "", site$html_url)
78-
site_url <- tidyverse_url(url = site_url, tr = tr)
77+
site_url <- tidyverse_url(url = site$html_url, tr = tr)
7978
use_pkgdown_url(url = site_url, tr = tr)
8079

8180
if (tr$repo_owner %in% c("tidyverse", "tidymodels", "r-lib")) {
@@ -124,13 +123,14 @@ tidyverse_url <- function(url, tr = NULL) {
124123
!tr$repo_owner %in% c("tidyverse", "r-lib", "tidymodels")) {
125124
return(url)
126125
}
126+
127127
custom_url <- glue("https://{tr$repo_name}.{tr$repo_owner}.org")
128-
if (url == custom_url) {
128+
if (grepl(glue("{custom_url}/?"), url)) {
129129
return(url)
130130
}
131131
if (ui_yeah("
132132
{ui_value(tr$repo_name)} is owned by the {ui_value(tr$repo_owner)} GitHub \\
133-
organization
133+
organization.
134134
Shall we configure {ui_value(custom_url)} as the (eventual) \\
135135
pkgdown URL?")) {
136136
custom_url
@@ -173,16 +173,16 @@ pkgdown_url <- function(pedantic = FALSE) {
173173

174174
meta <- pkgdown_config_meta()
175175
url <- meta$url
176-
if (is.null(url)) {
177-
if (pedantic) {
178-
ui_warn("
179-
pkgdown config does not specify the site's {ui_field('url')}, \\
180-
which is optional but recommended")
181-
}
182-
NULL
183-
} else {
184-
gsub("/$", "", url)
176+
if (!is.null(url)) {
177+
return(url)
185178
}
179+
180+
if (pedantic) {
181+
ui_warn("
182+
pkgdown config does not specify the site's {ui_field('url')}, \\
183+
which is optional but recommended")
184+
}
185+
NULL
186186
}
187187

188188
# travis ----

tests/testthat/test-pkgdown.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ test_that("pkgdown_url() returns correct data, warns if pedantic", {
6767
expect_equal(pkgdown_url(), "https://usethis.r-lib.org")
6868

6969
# config has url with trailing slash
70-
writeLines("url: https://usethis.r-lib.org/", pkgdown_config_path())
71-
expect_equal(pkgdown_url(), "https://usethis.r-lib.org")
70+
writeLines("url: https://malcolmbarrett.github.io/tidysmd/", pkgdown_config_path())
71+
expect_equal(pkgdown_url(), "https://malcolmbarrett.github.io/tidysmd/")
72+
})
73+
74+
test_that("tidyverse_url() leaves trailing slash alone, almost always", {
75+
url <- "https://malcolmbarrett.github.io/tidysmd/"
76+
out <- tidyverse_url(url, tr = list(repo_name = "REPO", repo_owner = "OWNER"))
77+
expect_equal(out, url)
7278
})

0 commit comments

Comments
 (0)