我正在使用由Jekyll制作并托管在GitHub上的静态网站。其中一篇帖子看起来像这样
另外,我创建了一个Rmarkdown文件,并且想要将生成的html文件嵌入到帖子中。我在这里读到,我只需要这样做:
您只需在项目的DocumentRoot中创建一个名为_includes /的文件夹,然后在其中创建一个HTML文件,例如“ mycomponent.html”,并在您的帖子中使用类似以下内容的名称即可:
{% include mycomponent.html %}
我在_includes /文件夹中添加了html文件,并在相应帖子的markdown文件末尾添加了此类代码。但是,当我这样做时,网站布局会完全改变
我有办法避免这种情况吗?该网站的所有文件都存储在这里。
编辑:
我发现了另一个建议这样做的问题:
我认为最好的解决方案是:
使用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。同样,页面的页脚也被完全弄乱了。
我发现没有必要将html嵌入另一个。使用R,可以创建带有帖子的Rmd文件,然后将其转换为所需的md文件。杰森·费舍尔(Jason Fisher)的网站通过分步说明很好地说明了这一点。他的GitHub网站还提供了有用的信息。
另一个有用的站点是Juuso Parkkinen的站点。他是告诉我他从未将html嵌入另一个的人,而只是使用R通过使用以下代码直接使用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帐户也是一个有用的参考。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句