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

时间:2015-12-23 22:43:38

标签: r jekyll knitr r-markdown

我尝试使用trio jekyll,rmarkdown和github做博客(如:http://yihui.name/knitr-jekyll/

我在_source中拥有我的所有.Rmd,我有这个问题,有时这些图是基础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"

在R:

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

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)
})

生成文件:

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

clean:
    rm -r ../blog/

1 个答案:

答案 0 :(得分:2)

我解决了我的问题,我将其发布在此处以防人们拥有相同的内容:

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

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

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

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

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

相关问题