jro*_*las 7 html jekyll r-markdown
我正在使用Jekyll制作的静态网站,并在GitHub上托管.其中一个帖子看起来像这样
此外,我创建了一个Rmarkdown文件,我想将生成的html文件嵌入到帖子中.我在这里读到我只需要这样做:
您只需在项目的DocumentRoot中创建一个名为_includes /的文件夹,然后在其中创建一个HTML文件,例如"mycomponent.html"并在帖子中调用它,如下所示:
Run Code Online (Sandbox Code Playgroud){% include mycomponent.html %}
我在_includes /文件夹中添加了我的html文件,并在相应帖子的markdown文件末尾添加了这段代码.但是,当我这样做时,网站布局会完全改变
我有办法避免这种情况吗?该网站的所有文件都存储在这里.
编辑:
我发现它被建议做另外一个问题这个:
在我看来,最好的解决方案是:
使用jQuery:
a.html:
Run Code Online (Sandbox Code Playgroud)<html> <head> <script src="jquery.js"></script> <script> $(function(){ $("#includedContent").load("b.html"); }); </script> </head> <body> <div id="includedContent"></div> </body> </html>
b.html:
Run Code Online (Sandbox Code Playgroud)<p> This is my include file </p>
我完全不明白.不知何故,网站的布局已恢复,但现在一些图像和htmlwidget丢失了.此外,页面的页脚完全搞砸了.
我发现没有必要将一个html嵌入到另一个html中。使用 R,可以创建包含帖子的 Rmd 文件,然后将其转换为所需的 md 文件。Jason Fisher 的网站通过分步说明对其进行了很好的解释。他的 GitHub网站也有有用的信息。
另一个有用的网站是 Juuso Parkkinen 的网站。他告诉我,他从来没有将 html 嵌入到另一个 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)
}
}
Run Code Online (Sandbox Code Playgroud)
他的 GitHub 帐户也是一个有用的参考。
归档时间: |
|
查看次数: |
817 次 |
最近记录: |