Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent blogdown from rerendering all posts?

Background:

I am featuring a blog built on @YihuiXie's R package blogdown.

Problem:

When I render_site(), all source files (*.Rmd) are rendered - even the unchanged source files are re-reendered.

This complete re-rendering is time consuming and unnecessary (I think).

Question/ Desired Solution:

How can I prevent blogdown from re-rendering the unchanged source files? I want blogdown to render only new or changed source files.

What I have already tried:

  • I've read the blogdown book; Yihui seems to propose the "rebuild-all" approach.

  • I've read the help files for render_site() and hugo_build(). The first one states that it will render all rmd files. In contrast hugo_build() does not knit rmd files (ie., rmd files are not compiled to md files).

  • I've checked SO and Google, but this question seems not to have been asked before.

SessionInfo():

R version 3.4.4 (2018-03-15)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.4

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_1.1.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.17    rstudioapi_0.7  knitr_1.20      magrittr_1.5    RcppTOML_0.1.3  xtable_1.8-2    R6_2.2.2        rlang_0.2.0     stringr_1.3.1   tools_3.4.4     xfun_0.1       
[12] miniUI_0.1.1.1  htmltools_0.3.6 yaml_2.1.19     rprojroot_1.3-2 digest_0.6.15   bookdown_0.7    later_0.7.2     promises_1.0.1  evaluate_0.10.1 mime_0.5        rmarkdown_1.9.4
[23] blogdown_0.6    stringi_1.2.2   compiler_3.4.4  backports_1.1.2 jsonlite_1.5    httpuv_1.4.3   
> 
like image 588
Sebastian Sauer Avatar asked May 28 '18 11:05

Sebastian Sauer


1 Answers

I think the answer is on the page you referenced -- Section 1.7 of the blogdown book ("A recommended workflow"). It seems it is not clear enough to you, so let me rephrase it:

  1. You should rarely need bookdown::render_site(). You can see that I didn't even mention this function in Section 1.7.

  2. Use blogdown::serve_site(), and it is the only function you need to call if your website is published on Netlify, or any servers that can run the hugo command to build your website on the server side.

  3. If you do not use Netlify, or do not call hugo on the server side, but want to build the site locally and publish the public/ folder manually, call blogdown::hugo_build() before you publish your website.

Since you are using Netlify, the answer is basically blogdown::serve_site(). That is all you need. It does not re-render Rmd files that have not been changed. See the Appendix D.3.

like image 54
Yihui Xie Avatar answered Sep 28 '22 10:09

Yihui Xie