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 dba718b
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 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))
}
}

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))


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 dba718b

Please sign in to comment.