rstudio / blogdown

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

FR: Share output options among posts with a single YAML file. #545

Closed atusy closed 3 years ago

atusy commented 3 years ago

With _output.yml, we can implicitly share output options among Rmd files in the same directory. However, when options(blogdown.new_bundle = TRUE), each posts exist in individual directories, and require explicitly share the option with output_yaml: ../_output.yml in the YAML front matter.

I want a feature that enables implicit sharing of the option even if options(blogdown.new_bundle = TRUE).

This feature request originally comes from a discussion in RStudio Community: https://community.rstudio.com/t/how-to-share-output-yml-among-blodwon-posts-when-blogdown-new-bundle-is-true/91557

Checklist

When filing a feature request, please check the boxes below to confirm that you have provided us with the information we need. Have you:

apreshill commented 3 years ago

I answered on community re: using Hugo archetypes for this purpose. They give you a lot of flexibility that (I think) better map onto your Hugo site's different kinds of content:

https://community.rstudio.com/t/how-to-share-output-yml-among-blodwon-posts-when-blogdown-new-bundle-is-true/91557/11

Have you considered this approach, or did you try it and it didn't suit your needs?

atusy commented 3 years ago

@apreshill

Thank you so much. This is a great solution. I also found new_post() by default refers to archetypes/default.md. However, I see no documentations about it. Maybe we should add descriptions at https://bookdown.org/yihui/blogdown/

atusy commented 3 years ago

Maybe we should add descriptions at bookdown.org/yihui/blogdown

Oops, it's there: https://bookdown.org/yihui/blogdown/templates.html#a-minimal-example So everything is fine now! Thank you all for your helps!

yihui commented 3 years ago

I don't recommend using the archetype in this case. Your goal is to set an option globally in the output format, and _output.yml is a better way to go. You can put this file in the root directory of your website project (search for _output.yml on this page: https://bookdown.org/yihui/blogdown/output-format.html).

Hard-coding the output field in each post will make it inconvenient to update the output format (e.g., any output format options) in the future. This time you may want to add the Pandoc extension +east_asian_line_breaks, and next time you may want to add or remove another extension, then you'd have to update each post if the extensions are specified in the output field of each post.

atusy commented 3 years ago

@yihui Thank you for suggestions. I agree _output.yml is the better choice.

I have read the link you shared, and tried it without success.

What does it mean by the root directory described below?

you can create a _output.yml file under the root directory of your website.

I have tried

yihui commented 3 years ago

@atusy I meant the project root. _output.yml should be copied to the directory of each post when rendering the post: https://github.com/rstudio/blogdown/blob/11fec4c7d59234596501c36ceece72c5f6d2a0a0/R/render.R#L142-L154 If it doesn't work, there might be a bug.

atusy commented 3 years ago

@yihui Thanks. I confirmed it works with new project and subsequently with my project. Maybe I did something wrong yesterday...

Thanks again!!