5
votes

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

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.

First question, why?

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.

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.

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

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

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:

# Build settings
markdown: kramdown
baseurl: "/blog"

In 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/
1
A link to your github repo would be appreciated.Brian Willis
Can you add link to your _config.yml file? It's not in your GitHub repo and I don't think issue can be solved without it. Also, the exact command that you use to generate your website would be appreciated.Mirek Długosz
I have put the build.r, makefile and _config.yml. ThanksYCR
I have tried reproducing your problem, but so far I have failed. Is there a chance for you to upload entire source directory (parent of whenever Makefile is) somewhere? Maybe as new branch of git project? You can delete it once this problem is solved. At the moment the only tip I have is to check _posts directory for file that will become 2015/07/Voronoi_station.html. If image path is wrong in this file, then servr/knitr is at fault. If image path is correct there, then problem is related to how jekyll processes files.Mirek Długosz
you may be interested in my setup based on jekyll-now repo: jangorecki.github.io/blog/2014-11-05/Hello-World.html it won't be supported starting from May 2016 as github is dropping redcarpet support, but will still work locally and on other git pages which supports custom jekyll setup.jangorecki

1 Answers

2
votes

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

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

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.

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

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

With the cache, knitr create images in a folder.