rstudio / blogdown

Create Blogs and Websites with R Markdown
https://pkgs.rstudio.com/blogdown/
1.74k stars 331 forks source link

[FR] config option for multiple custom rendering functions #683

Closed mivalek closed 2 years ago

mivalek commented 2 years ago

Hi all,

(This is an edited repost from #289 which hasn't received a response in 6 months. If it's on people's radar, please feel free to close this issue)

A tiny bit of background: I am a uni teacher so hosting both slides and lecture handouts/worksheets in an integrated easy-to-use, easy-to-maintain way is important when creating a course website. I think that enabling users to define custom formats while keeping blogdown::html_page as the default should be fairly simple.

Here is my suggestion (implemented in this commit): config.yaml should have an optional renders: parameter, such as:

renders:
  default: "blogdown::html_page"
  slides: "my_pkg::my_format"

blogdown::build_site() then reads renders from config.yaml and passes it down to blogdown:::build_one() which looks for the type: parameter in a .Rmd file's YAML front matter. If there isn't one, the file gets rendered by the default method. In this scenario, files with type: slides in YAML get rendered with my_pkg::my_format. Using the type: param is handy because it allows custom HUGO templates for files of a given type.

If there is no renders: in config.yaml, everything gets rendered by blogdown::html_page so it would not be a breaking change.

The implementation linked above doesn't deal with TOML but I don't imagine it would take a lot of work to expand. I've been working on a blogdown/HUGO theme for course websites I would like to release and this feature is crucial for it.

Many thanks!

yihui commented 2 years ago

Sorry about the delay in response. I think we can just continue the discussion in https://github.com/rstudio/blogdown/issues/289. Thank you!