12

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   
> 
d.b
  • 29,772
  • 5
  • 24
  • 63
Sebastian Sauer
  • 1,247
  • 10
  • 20

2 Answers2

16

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.

Yihui Xie
  • 22,808
  • 20
  • 167
  • 387
  • Hi Yihui. What is your workflow recommendation for manually publishing the site onto a shared server? Since I'm not running hugo command on the server side or using Netlify, the only way I know how to create the website is `build_site()` which re-renders all rmd files. – Atakan Jun 22 '20 at 06:34
  • I would appreciate if you can comment on [my recent question](https://stackoverflow.com/questions/62508839/prevent-re-knitting-of-old-rmd-files-when-publishing-blogdown-website-on-shared) about this – Atakan Jun 22 '20 at 06:50
  • Did you read Section 1.7 of the blogdown book or the third bullet in my answer? – Yihui Xie Jun 22 '20 at 14:35
  • Yes I read them both. Build site rehexecutes rmds (but desired for updating iteratively), but your answer to my other question outlines a clear workflow. thanks – Atakan Jun 22 '20 at 17:33
  • Okay. Good to know that I managed to clarify the expected workflow! – Yihui Xie Jun 22 '20 at 19:37
0

blogdown::serve_site() tries to rerender some of my old blog posts after I reset my computer and re-downloaded the code from github.

By using blogdown:::build_rmds("content/post/{file_name}.Rmd") I was able to render single Rmd files to html. To check the results I run hugo server in the terminal window.

datistics
  • 211
  • 2
  • 6