【发布时间】:2018-06-22 00:11:08
【问题描述】:
我有一个repository,其中包含一系列使用Bookdown 构建的Rmd 文件。在这些 Rmd 文件中,调用了位于 folder 中的图像(也在存储库中)。如果我从主分支打开每个 Rmd 文件,则图像会正确呈现。但是,我尝试使用Travis 构建这本书并将内置书籍推送到gh-pages 分支(其中还包含图像文件夹)并使用Github 页面,但图像没有呈现。建好的书是here。
要调用 Rmd 文件中的图像,我使用如下行:

如果我在构建的书中检查损坏的图像,则路径包含我计算机的本地文件夹,鉴于 Rmd 文件中的所有路径都是相对的,我并不真正理解。我也尝试使用它(在 R 代码块中)调用图像,但它也不起作用:
knitr::include_graphics("/docs/non-plain/img/config_git.png")
我使用的是来自 Bookdown 手册的 .travis.yml,它调用了 _build.sh 和 _deploy.sh 脚本。
.travis.yml
language: r
cache: packages
pandoc_version: 1.19.2.1
before_script:
- chmod +x ./_build.sh
- chmod +x ./_deploy.sh
script:
- ./_build.sh
- ./_deploy.sh
_build.sh
#!/bin/sh
Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::gitbook')"
_deploy.sh
#!/bin/sh
set -e
[ -z "${GITHUB_PAT}" ] && exit 0
[ "${TRAVIS_BRANCH}" != "master" ] && exit 0
git config --global user.email "email.com"
git config --global user.name "username"
git clone -b gh-pages https://${GITHUB_PAT}@github.com/${TRAVIS_REPO_SLUG}.git book-output
cd book-output
cp -r ../_book/* ./
git add --all *
git commit -m"Update the book" || true
git push -q origin gh-pages
我无法理解我做错了什么以及为什么图像没有正确呈现。任何帮助表示赞赏。
【问题讨论】:
标签: r r-markdown travis-ci bookdown