Skip to content

Commit

Permalink
render_docs(autolink = TRUE) uses downlit
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Apr 7, 2024
1 parent c292c66 commit 18d6c8b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: altdoc
Title: Package Documentation Websites with 'Quarto', 'Docsify', 'Docute', or 'MkDocs'
Version: 0.3.0.9002
Version: 0.3.0.9003
Authors@R:
c(person(given = "Etienne",
family = "Bacher",
Expand All @@ -24,6 +24,7 @@ Imports:
cli,
desc,
evaluate,
downlit,
fs,
quarto,
tools,
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
execute:
freeze: auto
```
* `render_docs(autolink = TRUE)` uses the `downlit` package to automatically link function calls to their documentation on the web.

### Other changes

Expand Down
27 changes: 26 additions & 1 deletion R/render_docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @param verbose Logical. Print Rmarkdown or Quarto rendering output.
#' @param parallel Logical. Render man pages and vignettes in parallel using the `future` framework. In addition to setting this argument to TRUE, users must define the parallelism plan in `future`. See the examples section below.
#' @param freeze Logical. If TRUE and a man page or vignette has not changed since the last call to `render_docs()`, that file is skipped. File hashes are stored in `altdoc/freeze.rds`. If that file is deleted, all man pages and vignettes will be rendered anew.
#' @param autolink Logical. If TRUE use the `downlit` package to link function names and help calls from vignettes and man pages to documentation page on the web.
#' @inheritParams setup_docs
#' @export
#'
Expand Down Expand Up @@ -44,7 +45,7 @@
#' render_docs(parallel = TRUE)
#'
#' }
render_docs <- function(path = ".", verbose = FALSE, parallel = FALSE, freeze = FALSE) {
render_docs <- function(path = ".", verbose = FALSE, parallel = FALSE, freeze = FALSE, autolink = TRUE) {

path <- .convert_path(path)
tool <- .doc_type(path)
Expand Down Expand Up @@ -92,6 +93,7 @@ render_docs <- function(path = ".", verbose = FALSE, parallel = FALSE, freeze =
cli::cli_h1("Vignettes")
fail_vignettes <- .import_vignettes(src_dir = path, tar_dir = docs_dir, tool = tool, verbose = verbose, parallel = parallel, freeze = freeze)


# Error so that CI fails
if (length(fail_vignettes) > 0 & length(fail_man) > 0) {
cli::cli_abort("There were some failures when rendering vignettes and man pages.")
Expand All @@ -104,6 +106,29 @@ render_docs <- function(path = ".", verbose = FALSE, parallel = FALSE, freeze =
cli::cli_h1("Update HTML")
.import_settings(path = path, tool = tool, verbose = verbose, freeze = freeze)

if (isTRUE(autolink)) {
cli::cli_h1("Auto-Link")
html_files <- c(fs::dir_ls(fs::path_join(c(path, "docs/vignettes")), regexp = "\\.html$"),
fs::dir_ls(fs::path_join(c(path, "docs/man")), regexp = "\\.html$"))
for (h in html_files) {
downlit::downlit_html_path(h, h)
}
h <- fs::path_join(c(path, "docs/index.html"))
if (fs::file_exists(h)) {
downlit::downlit_html_path(h, h)
}

md_files <- c(fs::dir_ls(fs::path_join(c(path, "docs/vignettes")), regexp = "\\.html$"),
fs::dir_ls(fs::path_join(c(path, "docs/man")), regexp = "\\.html$"))
for (m in md_files) {
downlit::downlit_html_path(m, m)
}
m <- fs::path_join(c(path, "docs/README.md"))
if (fs::file_exists(m)) {
downlit::downlit_html_path(m, m)
}
}

cli::cli_h1("Complete")
cli::cli_alert_success("Documentation updated.")
}
Expand Down
2 changes: 1 addition & 1 deletion man-roxygen/altdoc_freeze.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @section Freeze
#' @section Freeze:
#'
#' When working on a package, running `render_docs()` to preview changes can be a time-consuming road block. The argument `freeze = TRUE` tries to improve the experience by preventing rerendering of files that have not changed since the last time `render_docs()` was ran. Note that changes to package internals will not cause a rerender, so rerendering the entire docs can still be necessary.
#'
Expand Down
10 changes: 9 additions & 1 deletion man/render_docs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 18d6c8b

Please sign in to comment.