Is there a way to replicate the behaviour of blogdown::serve_site()
where it caches files (i.e. it only rebuilds newly updated or "touched" files) but without actually causing a local preview?
The reason I ask is that I would like to automate this process with Github Actions and this seems to fail when using serve_site
.
For reference, I use Netlify to host and build the site. The general gist of my process is that I run a script to update a data file and then "touch" a file before using serve_site
to update just that file.
# touch the blog post that references this file
blogdown:::touch_file("path_to_file.Rmd")
# serve the site which re-renders just the touched post (not all posts)
blogdown::serve_site()
I can then commit this and Netlify will update the site. This works perfectly fine on my local machine and is what I've been doing for a while. But I'm trying to automate it with Github Actions so that it runs every day.
To do that I can setup the following. I copied this from this question
name: Get new data and rebuild site
on:
schedule:
- cron: "0 13 * * 1"
push:
branches:
- master
jobs:
scrape-and-commit:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@master
- uses: r-lib/actions/setup-pandoc@v1
- name: Install packages
run: Rscript -e 'install.packages(c("tidyverse", "here", "blogdown"))'
- name: Install Hugo
run: Rscript -e 'blogdown::install_hugo(extended = TRUE, version = "0.66.0")'
- name: Get data
run: Rscript -e 'source(here::here("scripts", "weekly_data_process.R"), echo = TRUE)'
- name: Build site
run: Rscript -e 'blogdown::serve_site()'
This runs fine until it gets to the 'build site' part, where it just hangs and I get the following error. I'm assuming this is because the process never actually finishes and so just times out.
Serving the directory /Users/runner/work/plussixoneblog/plussixoneblog at http://127.0.0.1:4321
##[error]The operation was canceled.
I've tried using blogdown::build_site()
and blogdown::build_hugo()
but build_site
re-renders every page which I don't want and build_hugo
doesn't re-render the touched file!
Basically what I need is to replicate the caching mechanism of serve_site
so that it just renders files where the RMD is newer than the HTML file without trying to preview it locally.
For reference - the failing Github Action run is here