从RMarkdown文档构建一个Jekyll站点的帖子,并遇到pandoc的“有用”链接URL编码问题。我点击了这个文件上的RStudio“Knit”按钮:
---
output: md_document
---
```{r setup, include=FALSE}
knitr::opts_knit$set(base.url = '{{ site.baseurl }}/')
knitr::opts_chunk$set(fig.path = 'assets/images/')
```
```{r sin_plot}
plot(1:100, sin(1:100))
```
我得到了这个降价文件:
plot(1:100, sin(1:100))
![](%7B%7B%20site.baseurl%20%7D%7D/assets/images/sin_plot-1.png)
我需要的是这个降价文件:
plot(1:100, sin(1:100))
![]({{ site.baseurl }}/assets/images/sin_plot-1.png)
液体标签将由Jekyll处理,但是pandoc正在阻碍。
问题由rmarkdown开启
由于您根本不需要Pandoc,因此您也不需要使用rmarkdown。你可以使用“vanilla”knitr(注意rmarkdown = knitr + Pandoc),即knitr::knit()
而不是rmarkdown::render()
。
对于Jekyll网站,blogdown可能会让你的生活变得更轻松,因为它也支持Jekyll:https://bookdown.org/yihui/blogdown/jekyll.html你不需要点击Knit
按钮而只需要blogdown::serve_site()
并享受LiveReload。如果您以前从未使用过blogdown,那么至少需要阅读博客书的第1章(但忽略那里的Hugo)。
如the other answer所述,“Knit”按钮调用rmarkdown::render
并且不可避免地是knitr + Pandoc。为了让RStudio用户为这个博客贡献推送按钮,我将所有内容都移到了简单的Makefile中。
RMD := $(shell find _posts/ -name '*.Rmd')
PORT = 4321
export GEM_HOME = ~/.gem
.PHONY: all
all: Gemfile.lock $(RMD:%.Rmd=%.md)
bundle exec jekyll build --drafts --baseurl=/p/$(PORT)
Gemfile.lock:
bundle install
%.md: %.Rmd
Rscript --vanilla -e "knitr::knit('$<', '$@')"
对于实时预览,RStudio用户可以在其控制台中运行servr::httw('_site')
进程并点击“Build”按钮进行更新。