Blogs with jekyll, rmarkdown and github: how to display images

I am trying to make a blog using the trio of jekyll, rmarkdown and github (like here: http://yihui.name/knitr-jekyll/ )

I have all my .Rmd in _source, and I have this problem that sometimes the graphics are knitted in the base 64 images and sometimes saved in the pictures folder.

The first question is why?

Second question: when my plot is saved as images, the html path looks like figure / source /. Knowing that the destination folder is / blog / (my baseurl in _config.yml), to make it work, it must be a blog / figure / source.

Strange, they are displayed locally and when I open html with my browser. But when I deploy my site on github, the images do not appear, since the path is wrong.

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

Edit: A link to my blog is still under construction: http://yvescr.imtqy.com/

But Rmd does not appear on the github account, since the folder synchronized with github is the jekyll generation target file.

_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/ 
+5
source share
1 answer

I solve my problem, I post it here if people have the same thing:

The jekyll () function in R compiles .rmd (in _source) to .md (in _post) with knitr (I think), then calls the jekyll command.

My problem here was that when I changed the _config.yml file with the path change, .md is not recreated and therefore the path does not change.

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

As for the images, they are compiled as 64 images when I use rmarkdown without a cache.

With a cache, knitr creates images in a folder.

+1
source

Source: https://habr.com/ru/post/1239096/


All Articles