【发布时间】:2020-07-10 01:20:03
【问题描述】:
有没有办法复制 blogdown::serve_site() 缓存文件的行为(即它只重建新更新或“触及”的文件)但实际上不会导致本地预览?
我问的原因是我想用 Github Actions 自动化这个过程,而使用 serve_site 时这似乎失败了。
作为参考,我使用 Netlify 来托管和构建站点。我的过程的一般要点是我运行一个脚本来更新一个数据文件,然后在使用serve_site 更新该文件之前“触摸”一个文件。
# 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()
然后我可以提交此操作,Netlify 将更新该站点。这在我的本地机器上工作得很好,这也是我一段时间以来一直在做的事情。但我正在尝试使用 Github Actions 将其自动化,以便它每天运行。
为此,我可以设置以下内容。我从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()'
这运行良好,直到它到达“构建站点”部分,它只是挂起并且我收到以下错误。我假设这是因为该过程实际上从未完成,所以只是超时。
Serving the directory /Users/runner/work/plussixoneblog/plussixoneblog at http://127.0.0.1:4321
##[error]The operation was canceled.
我尝试过使用blogdown::build_site() 和blogdown::build_hugo(),但build_site 会重新呈现我不想要的每个页面,而build_hugo 不会重新呈现触摸过的文件!
基本上我需要的是复制serve_site 的缓存机制,以便它只呈现RMD 比HTML 文件更新的文件,而不尝试在本地预览它。
供参考 - 失败的 Github Action 运行是 here
【问题讨论】:
-
抱歉,这不是特别可重现的,需要设置一些东西才能获得reprex。如果有帮助,我可以这样做,但我想我会检查以前是否有其他人遇到过。
-
只是为了记录,这是在github.com/rstudio/blogdown/issues/468交叉发布的。
-
@YihuiXie 是的,对不起,我一直想更新这个 Stack Overflow 问题!我很快就会这样做。
-
完全不用担心!非常感谢您回帖!