Skip to content

Commit

Permalink
fix: simplify URL selection
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Dec 10, 2024
1 parent f3f4ce6 commit a485fea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 52 deletions.
22 changes: 11 additions & 11 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,7 @@ render <- function(path = ".",
config <- file.path(path, "_quarto.yml")
config_contents <- read_yaml(config)

if (is.null(site_url)) {
if (nzchar(Sys.getenv("BABELQUARTO_TESTS_URL")) || !on_ci()) {
site_url <- site_url %||% config_contents[[type]][["site-url"]] %||% ""
} else {
# no end slash
# for deploy previews
# either root website (Netlify deploys)
# or something else
site_url <- Sys.getenv("BABELQUARTO_CI_URL", "")
}
}
site_url <- site_url %||% site_url(config_contents, type)
site_url <- sub("/$", "", site_url)

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

}

site_url <- function(config_contents, type) {

if (nzchar(Sys.getenv("BABELQUARTO_CI_URL"))) {
return(Sys.getenv("BABELQUARTO_CI_URL"))
}

config_contents[[type]][["site-url"]] %||% ""

}

render_quarto_lang <- function(language_code, path, output_dir, type) {

temporary_directory <- withr::local_tempdir()
Expand Down
43 changes: 2 additions & 41 deletions tests/testthat/test-render.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
test_that("render_book() works", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"
quarto_multilingual_book(
Expand All @@ -23,8 +21,6 @@ test_that("render_book() works", {
})

test_that("render_book() works - change link", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"
quarto_multilingual_book(
Expand All @@ -48,8 +44,6 @@ test_that("render_book() works - change link", {
})

test_that("render_book() works -- chapters in folders", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"
quarto_multilingual_book(
Expand Down Expand Up @@ -88,8 +82,6 @@ test_that("render_book() works -- chapters in folders", {
})

test_that("render_website() works", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"
quarto_multilingual_website(
Expand Down Expand Up @@ -127,14 +119,11 @@ test_that("render_website() works", {
)
expect_identical(
xml2::xml_attr(english_link, "href"),
"https://example.com/index.html")
expect_identical(xml2::xml_text(english_link), "Version in en"
"https://example.com/index.html"
)

expect_identical(xml2::xml_text(english_link), "Version in en")
})
test_that("render_book() works -- partial template", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"
quarto_multilingual_website(
Expand Down Expand Up @@ -191,12 +180,9 @@ test_that("render_book() works -- partial template", {
'//div[@class="alert alert-info alert-dismissible"]'
)
expect_match(xml2::xml_text(div), "Salut")

})

test_that("render_book() works - appendices", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"
quarto_multilingual_book(
Expand All @@ -218,13 +204,9 @@ test_that("render_book() works - appendices", {

withr::with_dir(parent_dir, render_book(project_dir))
expect_dir_exists(file.path(parent_dir, project_dir, "_book"))


})

test_that("render_book() works - chapters", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"
quarto_multilingual_book(
Expand All @@ -247,13 +229,9 @@ test_that("render_book() works - chapters", {

withr::with_dir(parent_dir, render_book(project_dir))
expect_dir_exists(file.path(parent_dir, project_dir, "_book"))


})

test_that("render_book() works - parts and chapters", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"
quarto_multilingual_book(
Expand Down Expand Up @@ -290,12 +268,9 @@ test_that("render_book() works - parts and chapters", {

withr::with_dir(parent_dir, render_book(project_dir))
expect_dir_exists(file.path(parent_dir, project_dir, "_book"))

})

test_that("render_website() works - listing", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"
quarto_multilingual_website(
Expand Down Expand Up @@ -344,8 +319,6 @@ test_that("render_website() works - listing", {
})

test_that("render_website() works - clean render for each language", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"
quarto_multilingual_website(
Expand Down Expand Up @@ -381,8 +354,6 @@ test_that("render_website() works - clean render for each language", {

test_that("render_website() fails when missing sidebar
and languagelinks is set to sidebar", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"
quarto_multilingual_website(
Expand All @@ -406,8 +377,6 @@ test_that("render_website() fails when missing sidebar

test_that("render_book() fails when missing navbar
and languagelinks is set to navbar", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"

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

test_that("book with navbar placement has languagelinks in the navbar", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"

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

test_that("website with sidebar placement has languagelinks in the sidebar", {
withr::local_envvar(BABELQUARTO_TESTS_URL = "true")

parent_dir <- withr::local_tempdir()
project_dir <- "blop"

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

test_that("render_book() works - all language links are present in sidebar", {

parent_dir <- withr::local_tempdir()
project_dir <- "blop"

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

test_that("render_website() works - all language links are present in navbar", {

parent_dir <- withr::local_tempdir()
project_dir <- "blop"

Expand Down Expand Up @@ -656,7 +619,6 @@ test_that("render_website() works - all language links are present in navbar", {
"href"
)
expect_identical(index_es_link_fr, "https://ropensci.org/fr/index.html")

})


Expand All @@ -683,7 +645,6 @@ test_that("render_website() works - all language links are present in navbar", {
expect_file_exists(
file.path(parent_dir, project_dir, "_site", "es", "practices.html")
)

})


Expand Down

0 comments on commit a485fea

Please sign in to comment.