rstudio / htmltools

Tools for HTML generation and output
https://rstudio.github.io/htmltools/
215 stars 68 forks source link

add overwrite argument in `copyDependencyToDir` for Rmd `self_contained: false` #294

Open zac-garland opened 2 years ago

zac-garland commented 2 years ago

Hi all,

I recently posted an issue in https://github.com/rstudio/rmarkdown/issues/2226#issue-1012707759 related to rmarkdown's self_contained: false yaml option. This option uses htmltools::copyDependencyToDir for HTML dependencies and it works great!

However, the current behavior of copyDependencyToDir is to overwrite HTML dependencies, even if they already exist, which can be time-consuming if you are iteratively rendering many Rmd files, and/or editing Rmd files using this option.

I'm happy to submit a PR, but wanted to post here to see if there were any concerns with adding in something like:
overwrite_dir = TRUE

copyDependencyToDir(
  dependency,
  outputDir,
  mustWork = TRUE,
  overwrite_dir = TRUE
)
zac-garland commented 2 years ago

*thought, rHtmlDeps cdn link

struckma commented 1 year ago

Thank you for bringing this up.

I would also like to see some option to avoid repetitively copying the same dependency for a "site" for each single rendered document. Not only, it takes time; having more control on the libraries shared by a set of files could also allow for some parallelization.

However, how would one control that option from save_html? A concept could be to have an alternative save-function saving a list of several html objects at once (I'll name it save_site, for now). Maybe, this save_site could also first extract all shared dependencies from all the objects, or there would be some extra function to do so. Then, save_site would iterate over the html objects and just generate the files as usually but omitting all file.copy steps for the dependencies.

I could contribute, if you like.