R 使用blogdown和github操作-服务于站点的替代方案

R 使用blogdown和github操作-服务于站点的替代方案,r,blogdown,R,Blogdown,有没有一种方法可以复制blogdown::service_site()缓存文件的行为(即,它只重建新更新的或“接触过的”文件),但实际上不会导致本地预览 我问这个问题的原因是,我想用Github操作自动化这个过程,但在使用service\u site时,这似乎失败了 作为参考,我使用Netlify来托管和构建站点。我的过程的一般要点是,我运行一个脚本来更新数据文件,然后在使用service\u site仅更新该文件之前“触摸”一个文件 # touch the blog post that ref

有没有一种方法可以复制
blogdown::service_site()
缓存文件的行为(即,它只重建新更新的或“接触过的”文件),但实际上不会导致本地预览

我问这个问题的原因是,我想用Github操作自动化这个过程,但在使用
service\u site
时,这似乎失败了

作为参考,我使用Netlify来托管和构建站点。我的过程的一般要点是,我运行一个脚本来更新数据文件,然后在使用
service\u 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操作自动化它,使它每天运行

为此,我可以设置以下内容。这是我从

在到达“构建站点”部分之前,它运行良好,在那里它只是挂起,我得到以下错误。我假设这是因为这个过程从未真正结束,所以只是超时

Serving the directory /Users/runner/work/plussixoneblog/plussixoneblog at http://127.0.0.1:4321
##[error]The operation was canceled.
我尝试过使用
blogdown::build\u site()
blogdown::build\u hugo()
但是
build\u site
重新呈现我不想要的每个页面,并且
build\u hugo
不会重新呈现被触摸的文件

基本上,我需要的是复制
service\u site
的缓存机制,以便它只呈现RMD比HTML文件更新的文件,而不尝试在本地预览它


仅供参考-失败的Github操作运行是

我设法解决了这个问题,因此分享了答案。我做的两件事似乎对这里有所帮助

首先-使用
blogdown::构建站点(local=TRUE)
。当地的部分是我之前错过的

我还需要将操作的touch_文件部分添加到run命令中。我不确定这是否真的很重要,但这是最终让整个过程对我起作用的一步,所以我要说是的

摘录如下。在“安装软件包”部分,您还需要添加您所接触的文件中使用的软件包

jobs:
  touch-and-rebuild:
    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("here", "blogdown"))'
      - name: Install Hugo
        run: Rscript -e 'blogdown::install_hugo(extended = TRUE, version = "0.66.0")'
      - name: Build site
        run: |
          blogdown:::touch_file(here::here("path", "to", "file.Rmd"))
          blogdown:::build_site(TRUE)
        shell: Rscript {0} 


在此之后,您将需要一些代码来提交

很抱歉,这不是特别可复制的,需要设置一些内容才能获得reprex。如果有帮助的话,我可以这样做,但我想我会检查一下以前是否有人遇到过这个问题。为了记录在案,这是交叉发布的。@YihuiXie是的,很抱歉我一直想更新这个堆栈溢出问题!我马上就去,不用担心!非常感谢您发回!
jobs:
  touch-and-rebuild:
    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("here", "blogdown"))'
      - name: Install Hugo
        run: Rscript -e 'blogdown::install_hugo(extended = TRUE, version = "0.66.0")'
      - name: Build site
        run: |
          blogdown:::touch_file(here::here("path", "to", "file.Rmd"))
          blogdown:::build_site(TRUE)
        shell: Rscript {0}