5

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/
YCR
  • 3,794
  • 3
  • 25
  • 29
  • 3
    A link to your github repo would be appreciated. – Brian Willis Dec 24 '15 at 00:30
  • 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 Dec 25 '15 at 17:16
  • I have put the build.r, makefile and _config.yml. Thanks – YCR Dec 25 '15 at 20:38
  • 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 Dec 26 '15 at 14:11
  • If your website is associated with your github user name, then the `baseurl` in `_config.yml` should be: `""`. But, if it is associated with your project repo, it should be `"/projectname"` – Metrics Dec 30 '15 at 22:52
  • @Metrics: you're right, my issue is more with knitr, I think. the figures are not knit with the good url, event with baseurl = "/blog". I may have an option to knit the figure in a particular place, like knitr::opts_chunk$set( fig.path = sprintf('blog/figure/%s/', d)) but even tht way, it change nothing. Still looking for ideas, but thanks :) – YCR Dec 31 '15 at 12:10
  • @MirosławZalewski, thanks, I'll try to create a reproducible exemple in an alternative repo. – YCR Dec 31 '15 at 12:11
  • In `_config.yml`, this is what I did: `baseurl: ""` and `baseurlknitr: /" `. It should work. – Metrics Dec 31 '15 at 15:28
  • 1
    you may be interested in my setup based on `jekyll-now` repo: https://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 Feb 03 '16 at 12:07

1 Answers1

2

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.

YCR
  • 3,794
  • 3
  • 25
  • 29