使用 jekyll、rmarkdown 和 github 写博客:如何显示图像
Blogging with jekyll, rmarkdown and github: how to display images
我尝试使用三重奏 jekyll、rmarkdown 和 github(如此处:http://yihui.name/knitr-jekyll/)
创建博客
我所有的 .Rmd 都在 _source 中,但我有这个问题,有时绘图是在 base 64 图像中编织的,有时保存在图形文件夹中。
第一个问题,为什么?
第二个问题:当我的图保存为图片时,html中的路径似乎是figure/source/。知道目标文件夹是 /blog/(我在 _config.yml 中的 baseurl),要让它工作,它应该是 blog/figure/source.
奇怪的是,当我用浏览器打开 html 时,它们会在本地显示。
但是当我在 github 上部署我的网站时,由于路径不正确,图像没有显示。
如何定义 /blog/figure 而不是 /figure/ 的路径?
编辑:link 到我的博客,仍在开发中:
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/
我解决了我的问题,我 post 在这里以防其他人遇到同样的问题:
R 中的 jekyll() 函数用 knitr(我认为)编译 .rmd(在 _source 中)在 .md(在 _post)中,然后调用 jekyll 命令。
这里,我的问题是,当我更改 _config.yml 文件时,修改路径后,.md 不是 re-created,因此路径没有更改。
为了让它工作,我必须手动删除 _source 中的 .md,然后 re-run jekyll() 函数。
关于图片,当我使用没有缓存的rmarkdown时,它们被编译为64张图片。
使用缓存,knitr 在文件夹中创建图像。
我尝试使用三重奏 jekyll、rmarkdown 和 github(如此处:http://yihui.name/knitr-jekyll/)
创建博客我所有的 .Rmd 都在 _source 中,但我有这个问题,有时绘图是在 base 64 图像中编织的,有时保存在图形文件夹中。
第一个问题,为什么?
第二个问题:当我的图保存为图片时,html中的路径似乎是figure/source/。知道目标文件夹是 /blog/(我在 _config.yml 中的 baseurl),要让它工作,它应该是 blog/figure/source.
奇怪的是,当我用浏览器打开 html 时,它们会在本地显示。 但是当我在 github 上部署我的网站时,由于路径不正确,图像没有显示。
如何定义 /blog/figure 而不是 /figure/ 的路径?
编辑:link 到我的博客,仍在开发中: 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/
我解决了我的问题,我 post 在这里以防其他人遇到同样的问题:
R 中的 jekyll() 函数用 knitr(我认为)编译 .rmd(在 _source 中)在 .md(在 _post)中,然后调用 jekyll 命令。
这里,我的问题是,当我更改 _config.yml 文件时,修改路径后,.md 不是 re-created,因此路径没有更改。
为了让它工作,我必须手动删除 _source 中的 .md,然后 re-run jekyll() 函数。
关于图片,当我使用没有缓存的rmarkdown时,它们被编译为64张图片。
使用缓存,knitr 在文件夹中创建图像。