title: Blogging with jekyll, rmarkdown and github: how to display images
body: <p>I try to do a blog using the trio jekyll, rmarkdown and github (as here: <a href="http://yihui.name/knitr-jekyll/" rel="nofollow noreferrer">http://yihui.name/knitr-jekyll/</a>)</p>
  
  <p>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.</p>
  
  <p>First question, why?</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>How to define the path to /blog/figure instead of /figure/ ?</p>
  
  <p>Edit: the link to my blog, still in development:
  <a href="http://yvescr.github.io/" rel="nofollow noreferrer">http://yvescr.github.io/</a></p>
  
  <p>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. </p>
  
  <p>_config.yml:</p>
  
  <pre><code># Build settings
  markdown: kramdown
  baseurl: "/blog"
  </code></pre>
  
  <p>In R:</p>
  
  <pre><code>jekyll(dir = ".", input = "_source", output = "_posts", script = c("Makefile", "build.R")
  , command = "jekyll build --destination ../blog")
  </code></pre>
  
  <p>build.r:</p>
  
  <pre><code>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)
  })
  </code></pre>
  
  <p>makefile:</p>
  
  <pre><code>all:
      Rscript -e "servr::jekyll('..')"
  
  clean:
      rm -r ../blog/
  </code></pre>