How to include rmarkdown / html file in Jekyll post

I am working on a static website created with Jekyll and hosted on GitHub. One of the posts looks like this

Normal view of the site

In addition, I created a Rmarkdown file, and I want to insert the resulting html file into the message. I read here that I only needed to do this:

You just need to create a folder called _includes / in the DocumentRoot of your project, and then create an HTML file inside, for example, "mycomponent.html", and name it in your message with something like this:

{% include mycomponent.html %}

I added my html file to the _includes / folder and added such a piece of code at the end of the markdown file for the corresponding message. However, when I do this, the layout of the website changes completely

Unwanted site appearance

? - .

EDIT:

, this:

, :

jQuery:

a.html:

<html> 
  <head> 
    <script src="jquery.js"></script> 
    <script> 
    $(function(){
      $("#includedContent").load("b.html"); 
    });
    </script> 
  </head>
  <body> 
     <div id="includedContent"></div>
  </body> 
</html>

b.html:

<p> This is my include file </p>

. - , htmlwidgets . , .

Another undesirable kind of site

+4
2

, html . R, Rmd , md. . GitHub .

, Juuso Parkkinen. , , html R , - Jekyll, :

# compiles all .Rmd files in _R directory into .md files in _posts directory,
# if the input file is older than the output file.

# run ./knitpages.R to update all knitr files that need to be updated.

KnitPost <- function(input, outfile, base.url="/") {
  # this function is a modified version of an example here:
  # http://jfisher-usgs.github.com/r/2012/07/03/knitr-jekyll/
  require(knitr);
  opts_knit$set(base.url = base.url)
  fig.path <- paste0("blog/figs/", sub(".Rmd$", "", basename(input)), "/")
  opts_chunk$set(fig.path = fig.path)
  opts_chunk$set(fig.cap = "testing")
  render_jekyll()
  knit(input, outfile, envir = parent.frame())
}

for (infile in list.files("blog/_R", pattern="*.Rmd", full.names=TRUE)) {
  outfile = paste0("blog/_posts/", sub(".Rmd$", ".md", basename(infile)))

  # knit only if the input file is the last one modified
  if (!file.exists(outfile) | file.info(infile)$mtime > file.info(outfile)$mtime) {
    KnitPost(infile, outfile)
  }
}

GitHub .

+1

, _includes/Report.html .

_includes/Report.html - HTML- ( doctype html), , include. Liquid include HTML, :

<!doctype html>
<html>
  <head>...</head>
  <body>
    ...
    <!doctype html>
    <html>
      ...
    </html>
  </body>
</html>

, _includes/Report.html ( script) Liquid :

{% include Report.html %}
+3

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


All Articles