用jekyll,rmarkdown和github博客:如何显示图像 [英] Blogging with jekyll, rmarkdown and github: how to display images

查看:98
本文介绍了用jekyll,rmarkdown和github博客:如何显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用jekyll,rmarkdown和github三人创建一个博客(如下所示: http://yihui.name/knitr-jekyll/)

I try to do a blog using the trio jekyll, rmarkdown and github (as here: http://yihui.name/knitr-jekyll/)

我的所有.Rmd文件都保存在_source中,并且存在一个问题,有时这些图以基数为64的图像进行编织,有时会保存在一个图形文件夹中.

I have all my .Rmd in _source, and I have this issue that sometimes the plots are knit in base 64 images and sometimes saved in a figure folder.

第一个问题,为什么?

第二个问题:当我的情节另存为图像时,html中的路径似乎是Figure/source/.要知道目标文件夹是/blog/(我的_config.yml中的baseurl),要使其正常工作,它应该是blog/figure/source.

Second question: when my plot are saved as images, the path in the html appear to be figure/source/. Knowing that the destination folder is /blog/ (my baseurl in _config.yml), to make it work, it should be blog/figure/source.

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

Strangely, they are displayed locally and when I open the html with my browser. But when I deploy my website on github, the images aren't displayed, as the path is incorrect.

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

How to define the path to /blog/figure instead of /figure/ ?

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

the link to my blog, still in development: http://yvescr.github.io/

但是Rmd不会出现在github帐户中,因为我与github同步的文件夹是jekyll一代的目标文件.

But the Rmd don't appear in the github account, as the folder I synchronised with github is the destination file of the jekyll generation.

_config.yml:

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

makefile:

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

clean:
    rm -r ../blog/

推荐答案

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

I solve my issue, I post it here in case people have the same:

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

The jekyll() function in R compile the .rmd (in _source) in .md(in _post) with knitr(I think) then call the jekyll command.

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

Here, my issue was that when I changed the _config.yml file, with modification of the path, the .md are not re-created and so the path is not changed.

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

To make it work, I had to delete manually the .md in _source then re-run the jekyll() function.

关于图像,当我使用不带缓存的rmarkdown时,它们被编译为64个图像.

Concerning the images, they are compiled as 64 images when I use rmarkdown without cache.

借助缓存,knitr在文件夹中创建图像.

With the cache, knitr create images in a folder.

这篇关于用jekyll,rmarkdown和github博客:如何显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆