Skip to content

Commit a485fea

Browse files
committed
fix: simplify URL selection
1 parent f3f4ce6 commit a485fea

File tree

2 files changed

+13
-52
lines changed

2 files changed

+13
-52
lines changed

R/render.R

+11-11
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,7 @@ render <- function(path = ".",
5757
config <- file.path(path, "_quarto.yml")
5858
config_contents <- read_yaml(config)
5959

60-
if (is.null(site_url)) {
61-
if (nzchar(Sys.getenv("BABELQUARTO_TESTS_URL")) || !on_ci()) {
62-
site_url <- site_url %||% config_contents[[type]][["site-url"]] %||% ""
63-
} else {
64-
# no end slash
65-
# for deploy previews
66-
# either root website (Netlify deploys)
67-
# or something else
68-
site_url <- Sys.getenv("BABELQUARTO_CI_URL", "")
69-
}
70-
}
60+
site_url <- site_url %||% site_url(config_contents, type)
7161
site_url <- sub("/$", "", site_url)
7262

7363
output_dir <- config_contents[["project"]][["output-dir"]] %||%
@@ -188,6 +178,16 @@ render <- function(path = ".",
188178

189179
}
190180

181+
site_url <- function(config_contents, type) {
182+
183+
if (nzchar(Sys.getenv("BABELQUARTO_CI_URL"))) {
184+
return(Sys.getenv("BABELQUARTO_CI_URL"))
185+
}
186+
187+
config_contents[[type]][["site-url"]] %||% ""
188+
189+
}
190+
191191
render_quarto_lang <- function(language_code, path, output_dir, type) {
192192

193193
temporary_directory <- withr::local_tempdir()

tests/testthat/test-render.R

+2-41
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
test_that("render_book() works", {
2-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
3-
42
parent_dir <- withr::local_tempdir()
53
project_dir <- "blop"
64
quarto_multilingual_book(
@@ -23,8 +21,6 @@ test_that("render_book() works", {
2321
})
2422

2523
test_that("render_book() works - change link", {
26-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
27-
2824
parent_dir <- withr::local_tempdir()
2925
project_dir <- "blop"
3026
quarto_multilingual_book(
@@ -48,8 +44,6 @@ test_that("render_book() works - change link", {
4844
})
4945

5046
test_that("render_book() works -- chapters in folders", {
51-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
52-
5347
parent_dir <- withr::local_tempdir()
5448
project_dir <- "blop"
5549
quarto_multilingual_book(
@@ -88,8 +82,6 @@ test_that("render_book() works -- chapters in folders", {
8882
})
8983

9084
test_that("render_website() works", {
91-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
92-
9385
parent_dir <- withr::local_tempdir()
9486
project_dir <- "blop"
9587
quarto_multilingual_website(
@@ -127,14 +119,11 @@ test_that("render_website() works", {
127119
)
128120
expect_identical(
129121
xml2::xml_attr(english_link, "href"),
130-
"https://example.com/index.html")
131-
expect_identical(xml2::xml_text(english_link), "Version in en"
122+
"https://example.com/index.html"
132123
)
133-
124+
expect_identical(xml2::xml_text(english_link), "Version in en")
134125
})
135126
test_that("render_book() works -- partial template", {
136-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
137-
138127
parent_dir <- withr::local_tempdir()
139128
project_dir <- "blop"
140129
quarto_multilingual_website(
@@ -191,12 +180,9 @@ test_that("render_book() works -- partial template", {
191180
'//div[@class="alert alert-info alert-dismissible"]'
192181
)
193182
expect_match(xml2::xml_text(div), "Salut")
194-
195183
})
196184

197185
test_that("render_book() works - appendices", {
198-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
199-
200186
parent_dir <- withr::local_tempdir()
201187
project_dir <- "blop"
202188
quarto_multilingual_book(
@@ -218,13 +204,9 @@ test_that("render_book() works - appendices", {
218204

219205
withr::with_dir(parent_dir, render_book(project_dir))
220206
expect_dir_exists(file.path(parent_dir, project_dir, "_book"))
221-
222-
223207
})
224208

225209
test_that("render_book() works - chapters", {
226-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
227-
228210
parent_dir <- withr::local_tempdir()
229211
project_dir <- "blop"
230212
quarto_multilingual_book(
@@ -247,13 +229,9 @@ test_that("render_book() works - chapters", {
247229

248230
withr::with_dir(parent_dir, render_book(project_dir))
249231
expect_dir_exists(file.path(parent_dir, project_dir, "_book"))
250-
251-
252232
})
253233

254234
test_that("render_book() works - parts and chapters", {
255-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
256-
257235
parent_dir <- withr::local_tempdir()
258236
project_dir <- "blop"
259237
quarto_multilingual_book(
@@ -290,12 +268,9 @@ test_that("render_book() works - parts and chapters", {
290268

291269
withr::with_dir(parent_dir, render_book(project_dir))
292270
expect_dir_exists(file.path(parent_dir, project_dir, "_book"))
293-
294271
})
295272

296273
test_that("render_website() works - listing", {
297-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
298-
299274
parent_dir <- withr::local_tempdir()
300275
project_dir <- "blop"
301276
quarto_multilingual_website(
@@ -344,8 +319,6 @@ test_that("render_website() works - listing", {
344319
})
345320

346321
test_that("render_website() works - clean render for each language", {
347-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
348-
349322
parent_dir <- withr::local_tempdir()
350323
project_dir <- "blop"
351324
quarto_multilingual_website(
@@ -381,8 +354,6 @@ test_that("render_website() works - clean render for each language", {
381354

382355
test_that("render_website() fails when missing sidebar
383356
and languagelinks is set to sidebar", {
384-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
385-
386357
parent_dir <- withr::local_tempdir()
387358
project_dir <- "blop"
388359
quarto_multilingual_website(
@@ -406,8 +377,6 @@ test_that("render_website() fails when missing sidebar
406377

407378
test_that("render_book() fails when missing navbar
408379
and languagelinks is set to navbar", {
409-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
410-
411380
parent_dir <- withr::local_tempdir()
412381
project_dir <- "blop"
413382

@@ -432,8 +401,6 @@ test_that("render_book() fails when missing navbar
432401
})
433402

434403
test_that("book with navbar placement has languagelinks in the navbar", {
435-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
436-
437404
parent_dir <- withr::local_tempdir()
438405
project_dir <- "blop"
439406

@@ -461,8 +428,6 @@ test_that("book with navbar placement has languagelinks in the navbar", {
461428
})
462429

463430
test_that("website with sidebar placement has languagelinks in the sidebar", {
464-
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")
465-
466431
parent_dir <- withr::local_tempdir()
467432
project_dir <- "blop"
468433

@@ -490,7 +455,6 @@ test_that("website with sidebar placement has languagelinks in the sidebar", {
490455
})
491456

492457
test_that("render_book() works - all language links are present in sidebar", {
493-
494458
parent_dir <- withr::local_tempdir()
495459
project_dir <- "blop"
496460

@@ -579,7 +543,6 @@ test_that("render_book() works - all language links are present in sidebar", {
579543
})
580544

581545
test_that("render_website() works - all language links are present in navbar", {
582-
583546
parent_dir <- withr::local_tempdir()
584547
project_dir <- "blop"
585548

@@ -656,7 +619,6 @@ test_that("render_website() works - all language links are present in navbar", {
656619
"href"
657620
)
658621
expect_identical(index_es_link_fr, "https://ropensci.org/fr/index.html")
659-
660622
})
661623

662624

@@ -683,7 +645,6 @@ test_that("render_website() works - all language links are present in navbar", {
683645
expect_file_exists(
684646
file.path(parent_dir, project_dir, "_site", "es", "practices.html")
685647
)
686-
687648
})
688649

689650

0 commit comments

Comments
 (0)