使用jekyll,rmarkdown和github进行博客:如何显示图像

YCR*_*YCR 5 r jekyll knitr r-markdown

我尝试使用三人化身,rmarkdown和github上做一个博客(这里:http://yihui.name/knitr-jekyll/)

我有我所有的.Rmd在_source,我有这个问题,有时地块在基底编织64幅图像,有时保存在一个文件夹身影.

第一个问题,为什么?

第二个问题:当我的情节被保存为图像时,html中的路径似乎是数字/来源/.知道目标文件夹是/ blog /(我在_config.yml中的baseurl),为了使它工作,它应该是blog/figure/source.

奇怪的是,当我用浏览器打开html时,它们会在本地显示.但是当我在github上部署我的网站时,图像不会显示,因为路径不正确.

如何定义/ blog/figure的路径而不是/ figure /?

编辑:我的博客的链接,仍在开发中:http: //yvescr.github.io/

但是Rmd没有出现在github帐户中,因为我与github同步的文件夹是jekyll生成的目标文件.

_config.yml:

# Build settings
markdown: kramdown
baseurl: "/blog"
Run Code Online (Sandbox Code Playgroud)

在R:

jekyll(dir = ".", input = "_source", output = "_posts", script = c("Makefile", "build.R")
, command = "jekyll build --destination ../blog")
Run Code Online (Sandbox Code Playgroud)

build.r:

local({
  # fall back on '/' if baseurl is not specified
  baseurl = servr:::jekyll_config('.', 'baseurl', '/')
  knitr::opts_knit$set(base.url = baseurl)
  # fall back on 'kramdown' if markdown engine is not specified
  markdown = servr:::jekyll_config('.', 'markdown', 'kramdown')
  # see if we need to use the Jekyll render in knitr
  if (markdown == 'kramdown') {
    knitr::render_jekyll()
  } else knitr::render_markdown()

  # input/output filenames are passed as two additional arguments to Rscript
  a = commandArgs(TRUE)
  d = gsub('^_|[.][a-zA-Z]+$', '', a[1])
  knitr::opts_chunk$set(
    fig.path   = sprintf('blog/figure/%s/', d),
    cache.path = sprintf('cache/%s/', d)
  )

  knitr::opts_knit$set(width = 70)
  knitr::knit(a[1], a[2], quiet = TRUE, encoding = 'UTF-8', envir = .GlobalEnv)
})
Run Code Online (Sandbox Code Playgroud)

生成文件:

all:
    Rscript -e "servr::jekyll('..')"

clean:
    rm -r ../blog/
Run Code Online (Sandbox Code Playgroud)

YCR*_*YCR 2

我解决了我的问题,我将其发布在这里,以防人们有相同的情况:

R中的jekyll()函数用knitr(我认为)编译.md(在_post中)中的.rmd(在_source中),然后调用jekyll命令。

在这里,我的问题是,当我更改 _config.yml 文件并修改路径时,不会重新创建 .md,因此路径不会更改。

为了使其工作,我必须手动删除 _source 中的 .md,然后重新运行 jekyll() 函数。

关于图像,当我使用没有缓存的 rmarkdown 时,它们被编译为 64 个图像。

使用缓存,knitr 在文件夹中创建图像。