Skip to content

Commit

Permalink
conditional autolink
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Apr 8, 2024
1 parent abf7a18 commit a103c85
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions R/autolink.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
.autolink <- function(path = ".") {
# everything wrapped in tryCatch() because especially error prone with weird pandoc memory errors

html_files <- c(
fs::dir_ls(fs::path_join(c(path, "docs/vignettes")), regexp = "\\.html$", fail = FALSE),
fs::dir_ls(fs::path_join(c(path, "docs/man")), regexp = "\\.html$", fail = FALSE))
for (h in html_files) {
tmp <- try(downlit::downlit_html_path(h, h), silent = TRUE)
if (inherits(tmp, "try-error")) {
cli::cli_alert_danger(sprintf("Failed to auto-link: %s", h))
}
}
fs::dir_ls(fs::path_join(c(path, "docs/vignettes")), regexp = "\\.html$", fail = FALSE),
fs::dir_ls(fs::path_join(c(path, "docs/man")), regexp = "\\.html$", fail = FALSE))

md_files <- c(
fs::dir_ls(fs::path_join(c(path, "docs/vignettes")), regexp = "\\.md$", fail = FALSE),
fs::dir_ls(fs::path_join(c(path, "docs/man")), regexp = "\\.md$", fail = FALSE))
for (m in md_files) {
tmp <- try(downlit::downlit_md_path(m, m), silent = TRUE)
if (inherits(tmp, "try-error")) {
cli::cli_alert_danger(sprintf("Failed to auto-link: %s", h))
fs::dir_ls(fs::path_join(c(path, "docs/vignettes")), regexp = "\\.md$", fail = FALSE),
fs::dir_ls(fs::path_join(c(path, "docs/man")), regexp = "\\.md$", fail = FALSE))


if (isTRUE(.doc_type(path) %in% "quarto_website")) {
for (h in html_files) {
tmp <- try(downlit::downlit_html_path(h, h), silent = TRUE)
if (inherits(tmp, "try-error")) {
cli::cli_alert_danger(sprintf("Failed to auto-link: %s", h))
}
}

} else {
for (m in md_files) {
tmp <- try(downlit::downlit_md_path(m, m), silent = TRUE)
if (inherits(tmp, "try-error")) {
cli::cli_alert_danger(sprintf("Failed to auto-link: %s", h))
}
}
}
}

0 comments on commit a103c85

Please sign in to comment.