Skip to content

Commit

Permalink
fix: does not require README.qmd for Quarto website (#295)
Browse files Browse the repository at this point in the history
* fix: does not require README.qmd for Quarto website

* fix: README.qmd is not mandatory

* fix: fix index file name

* fix: should not remove

* fix: fix on quarto

* chore: replace `brio::write_lines` -> `base::writeLines`
  • Loading branch information
eitsupi authored Oct 5, 2024
1 parent 806d2b1 commit 011cea5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 39 deletions.
34 changes: 9 additions & 25 deletions R/import_readme.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
"md"
}

if (readme_type != "qmd" && tool == "quarto_website") {
cli::cli_abort(
"Quarto websites require a README.qmd file in the root of the package directory.",
call = NULL
)
}

src_file <- fs::path_join(
c(src_dir, grep(paste0("\\.", readme_type, "$"), readme_files, ignore.case = TRUE, value = TRUE))
)
Expand Down Expand Up @@ -67,36 +60,27 @@
"qmd" = {
pre <- fs::path_join(c(src_dir, "altdoc/preamble_vignettes_qmd.yml"))
pre <- tryCatch(.readlines(pre), warning = function(w) NULL, error = function(e) NULL)
# copy to quarto file
if (tool == "quarto_website") {
fs::file_copy(
src_file,
fs::path_join(c(tar_dir, "index.qmd")),
overwrite = TRUE
)
}
# process in-place for use on Github
# TODO: preambles inserted in the README often break Quarto websites. It's
# not a big problem to omit the preamble, but it would be good to
# investigate this, because I am not sure what is going on -VAB
.qmd2md(src_file, src_dir)
# .qmd2md(fn, src_dir, preamble = pre)
.update_freeze(src_dir, basename(src_file), successes = 1, fails = NULL, type = "README")
cli::cli_alert_success("{.file README} imported.")
return(invisible())
}
)

if (tool == "quarto_website") {
tar_file <- fs::path_join(c(tar_dir, "index.md"))
} else {
tar_file <- fs::path_join(c(tar_dir, "README.md"))
}

tar_file <- fs::path_join(c(tar_dir, "README.md"))
src_file <- fs::path_join(c(src_dir, "README.md"))
fs::file_copy(src_file, tar_file, overwrite = TRUE)
.check_md_structure(tar_file)

# Add the index page which includes README.md
if (tool == "quarto_website") {
writeLines(
enc2utf8("{{< include README.md >}}"),
fs::path_join(c(tar_dir, "index.md"))
)
}

tmp <- fs::path_join(c(src_dir, "README.markdown_strict_files"))
if (fs::dir_exists(tmp)) {
cli::cli_alert("We recommend using a `knitr` option to set the path of your images to `man/figures/README-`. This would ensure that images are properly stored and displayed on multiple platforms like CRAN, Github, and on your `altdoc` website.")
Expand Down
6 changes: 0 additions & 6 deletions R/settings_quarto_website.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
settings <- strsplit(settings, "\\n")[[1]]
writeLines(settings, fs::path_join(c(path, "_quarto", "_quarto.yml")))

# index.md breaks rendering
fn <- fs::path_join(c(path, "_quarto", "index.md"))
if (fs::file_exists(fn)) {
fs::file_delete(fn)
}

# NEWS.qmd breaks rendering, so we delete it if NEWS.md is available.
# This happens when converting from NEWS.Rd
a <- fs::path_join(c(path, "_quarto", "NEWS.md"))
Expand Down
6 changes: 1 addition & 5 deletions R/setup_docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ setup_docs <- function(tool, path = ".", overwrite = FALSE) {
}

# README.md is mandatory
if (tool == "quarto_website") {
fn <- "README.qmd"
} else {
fn <- "README.md"
}
fn <- "README.md"
msg <- sprintf("%s is mandatory. `altdoc` created a dummy README file in the package directory.", fn)
fn <- fs::path_join(c(path, fn))
if (!fs::file_exists(fn)) {
Expand Down
2 changes: 1 addition & 1 deletion inst/quarto_website/quarto_website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ website:
collapse-level: 1
contents:
- text: Home
file: index.qmd
file: index.md
- section: $ALTDOC_VIGNETTE_BLOCK
- section: $ALTDOC_MAN_BLOCK
- text: News
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-setup_docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,5 @@ test_that("quarto: README.qmd", {
create_local_package()
expect_false(file.exists("README.qmd"))
setup_docs("quarto_website", overwrite = TRUE)
expect_true(file.exists("README.qmd"))
expect_false(file.exists("README.qmd"))
})

0 comments on commit 011cea5

Please sign in to comment.