2017-03-05 55 views
1

我想在我的網站的主頁上添加一篇到我的博客文章的鏈接列表。如何獲取Github頁面以生成我的博客文章列表?

我理解的代碼做,這是

{% for post in site.posts %} 
    <h3><a href="{{ post.url }}">{{ post.title }}</a></h3> 
    <p><small><strong>{{ post.date | date: "%B %e, %Y" }}</strong> . {{ post.category }} . <a href="http://mypage.github.com{{ post.url }}#disqus_thread"></a></small></p>   
{% endfor %} 

但我不知道在哪裏可以把這個代碼?

我試着將它添加到一個新的章節裏面default.html中,但是我收到一個「頁面構建失敗」的電子郵件

+0

學習https://jekyllrb.com/docs/posts/ –

回答

0

把課裏面似乎是我的錯誤代碼。

把它的標題下工作

<header> 
     <h1>{{ site.title | default: site.github.repository_name }}</h1> 
     <h2>{{ site.description | default: site.github.project_tagline }}</h2> 
    </header> 
{% for post in site.posts %} 
    <h3><a href="{{ post.url }}">{{ post.title }}</a></h3> 
    <p><small><strong>{{ post.date | date: "%B %e, %Y" }}</strong> . {{ post.category }} . <a href="http://myname.github.com{{ post.url }}#disqus_thread"></a></small></p>    
{% endfor %} 
+0

謝謝,我沒有意識到我可以在markdown內執行代碼。我會放棄它。 –

1

這取決於你是否要職位的名單中的網站或只是主頁到處出現。對於主頁,您應該將其添加到您的index.html文件中。在任何情況下,將其添加到default.html將是一個更好的主意。

下面是它會是什麼樣子在index.html文件:

--- 
layout: default 
--- 

{% for post in site.posts %} 
... 
{% endfor %} 

在這種情況下,除了前面YAML有關的其他一切都將成爲{{ content }}_layouts/default.html

如果您確實使用了類似於您的_layouts/default.html的內容,請將其包含在HTML的body內的任意位置。

+0

謝謝,但是我使用index.md –

+0

這也可以工作,'index.html'或'index.md'。 – jpvillaisaza