2016-08-04 2 views
4

지킬로 만든 정적 웹 사이트에서 작업 중이며 GitHub에서 호스팅됩니다. 또한, 내가 Rmarkdown 파일을 만든 지킬 게시물에 Rmarkdown/HTML 파일을 포함하는 방법

Normal view of the site

this처럼 포스트 중 하나는보고, 나는 포스트에 결과 HTML 파일을 포함하고 싶습니다.

그냥 예를 들어, 다음, 프로젝트의 DocumentRoot에의 이름으로 _includes/을 폴더를 만들고 내부에 HTML 파일을 만들어야합니다 "를 MyComponent : 나는에만이 작업을 수행하는 데 필요한 그 here 읽기 .html 중에서 "와 같은 뭔가 게시물에 전화 :

{% include mycomponent.html %} 

을 나는 _includes/폴더에 내 HTML 파일을 추가하고 해당 게시물에 대한 가격 인하 파일의 끝에 코드의 같은 부분을 추가 . 내가 그렇게 할 때, 웹 사이트 레이아웃 변경 사항은 전부

Undesired look of the site

내가이 문제를 방지 할 수 있습니다 나는 방법이 있습니까? 웹 사이트의 모든 파일은 here입니다.

편집 :

내 생각에 가장 좋은 방법은 다음과 같습니다 :

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 위젯은 손실됩니다. 또한 페이지의 꼬리말이 완전히 엉망입니다.

REPO에서

Another undesired look of the site

답변

1

다른 것으로 html을 내장 할 필요가 없음을 알게되었습니다. R을 사용하여 게시물이있는 Rmd 파일을 작성한 다음 필요한 md 파일로 변환 할 수 있습니다. 제이슨 피셔의 website은 단계별 지침을 잘 설명합니다. 그의 GitHub site에도 유용한 정보가 있습니다.

또 다른 유용한 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.html 오히려 include 위해 설계되는 부분 이외의 (a doctypehtml 태그) 완전한 HTML 페이지입니다.액체는 유효하지 않은 마크 업 및 레이아웃 문제의 큰 원인 창조하는 전체 HTML과 태그를 포함 교체됩니다

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

는이 문제를 해결합니다 (script 태그를 유지) _includes/Report.html에서 추가 마크 업을 제거하려면, 그리고 액체를 사용하여 수정 된 부분을 포함 시키십시오.

{% include Report.html %} 
+0

로스에게 감사드립니다. – jroberayalas

관련 문제