2016-08-04 9 views
4

私はJekyll製の静的なウェブサイトでGitHubでホストされています。また、私はRmarkdownファイルを作成しJekyll投稿にRmarkdown/HTMLファイルを含める方法

Normal view of the site

thisのようなポストの一つが見え、私はポストへの結果のhtmlファイルを埋め込みたいです。あなただけ例えば、内部のHTMLファイルを作成し、その後、名前を _includes /プロジェクトのDocumentRootの中をフォルダを作成する必要が

「MyComponentの:私は、私はこれだけを行うために必要なことhereを読みます.htmlを」と、このようなもので、あなたの記事でそれを呼び出す:

{% include mycomponent.html %} 

私は_includes /フォルダ内の私のhtmlファイルを追加し、対応するポストのための値下げファイルの末尾にコードのように作品を追加しました。私はしかし、ウェブサイトのレイアウト変更を完全に

Undesired look of the site

、ということは、私はこれを避けることができ、私の方法はありますか?ウェブサイトのすべてのファイルはストアhereです。

EDIT:

私の意見では最良の解決策は次のとおりです:

のjQueryを使用した:

私はそれがthisを行うことが示唆された別の質問を見つけた

.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> 

私はそれを完全に理解していません。何らかの形でサイトのレイアウトが復元されましたが、今度は一部のイメージとhtmlウィジェットが失われます。また、ページのフッターが完全に台無しになっています。レポから

Another undesired look of the site

答えて

1

私は別のものの中にHTMLを埋め込む必要はないことを知った。 Rを使用すると、投稿付きのRmdファイルを作成し、必要なmdファイルに変換することができます。ジェイソンフィッシャーのwebsiteは、それをステップバイステップの手順でうまく説明しています。彼のGitHub siteにも有用な情報があります。

もう1つの有用なsiteは、Juuso Parkkinenによるものです。

# 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のアカウントが、同様に有用参照です:彼は彼が別のものにHTMLを埋め込むことはありませんだと言ってくれましたし、唯一のRは、直接、次のcodeを使用することによって、彼のジキルのウェブサイトを作成するために使用される人物です。

3

、私はあなたが別のファイルに_includes/Report.htmlを含めるようにしようとしたと仮定しています。

_includes/Report.htmlincludeがために設計されていること(doctypehtmlタグ付き)完全なHTMLページではなく、部分的です。液体は、無効なマークアップとレイアウトの問題の可能性が高いソースの作成、完全なHTMLとタグが含ま交換されます、(scriptタグを維持)、この問題を解決する_includes/Report.htmlから余分なマークアップを削除するには

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

をし、液体を使用して修正部分を含める:

{% include Report.html %} 
+0

ロスありがとう、私はそれを見てみましょう。 – jroberayalas

関連する問題