如何获取 Github 页面以生成我的博客文章列表?
How do I get Github Pages to generate a list of my blog posts?
我想在我的网站主页上包含指向我的博客文章的链接列表。
我知道执行此操作的代码是
{% 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,但我收到了一封 "Page Build Fails" 电子邮件
将代码放在一个部分中似乎是我的错误。
将其放在 header 作品下方
<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 %}
这取决于您是希望帖子列表出现在网站的任何地方还是只出现在主页上。对于主页,您应该将其添加到 index.html
文件中。在无处不在的情况下,将其添加到 default.html
会是一个更好的主意。
它在您的 index.html
文件中的样子如下:
---
layout: default
---
{% for post in site.posts %}
...
{% endfor %}
在这种情况下,除了 YAML 前端内容之外的所有内容都将成为 _layouts/default.html
中的 {{ content }}
。
如果您确实使用了类似 _layouts/default.html
的内容,则将其包含在 HTML 的 body
内的任何位置。
我想在我的网站主页上包含指向我的博客文章的链接列表。
我知道执行此操作的代码是
{% 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,但我收到了一封 "Page Build Fails" 电子邮件
将代码放在一个部分中似乎是我的错误。
将其放在 header 作品下方
<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 %}
这取决于您是希望帖子列表出现在网站的任何地方还是只出现在主页上。对于主页,您应该将其添加到 index.html
文件中。在无处不在的情况下,将其添加到 default.html
会是一个更好的主意。
它在您的 index.html
文件中的样子如下:
---
layout: default
---
{% for post in site.posts %}
...
{% endfor %}
在这种情况下,除了 YAML 前端内容之外的所有内容都将成为 _layouts/default.html
中的 {{ content }}
。
如果您确实使用了类似 _layouts/default.html
的内容,则将其包含在 HTML 的 body
内的任何位置。