HTML jekyll索引以反向时间顺序列出链接

时间:2016-05-24 03:33:07

标签: html jekyll

我在Minimal Mistakes jekyll主题中修改了一些HTML来创建我自己的网站。最大的变化是我添加了另一个帖子标签,或者新的帖子索引。

我的问题是新标签按逆时间顺序列出我的帖子,而原始标签仍然正确列出帖子(最新的帖子)。但是当我查看html时,代码看起来完全相同。请参阅以下两页:

错误索引:

<!doctype html>
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if (IE 7)&!(IEMobile)]><html class="no-js lt-ie9 lt-ie8" lang="en"><![endif]-->
<!--[if (IE 8)&!(IEMobile)]><html class="no-js lt-ie9" lang="en"><![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"><!--<![endif]-->
<head>
{% include _head.html %}
</head>

<body class="post-index">

{% include _browser-upgrade.html %}

{% include _navigation.html %}

{% if page.image.feature %}
  <div class="image-wrap">
  <img src=
    {% if page.image.feature contains 'http' %}
      "{{ page.image.feature }}"
    {% else %}
      "{{ site.url }}/images/{{ page.image.feature }}"
    {% endif %}
  alt="{{ page.title }} feature image">
  {% if page.image.credit %}
    <span class="image-credit">Photo Credit: <a href="{{ page.image.creditlink }}">{{ page.image.credit }}</a></span>
  {% endif %}
  </div><!-- /.image-wrap -->
{% endif %}

<div id="main" role="main">
  <div class="article-author-side">
    {% include _author-bio.html %}
  </div>
  <div id="index">
    <h1>{{ page.title }}</h1>
    {% capture written_year %}'None'{% endcapture %}
    {% for post in site.work %}  
      {% capture year %}{{ post.date | date: '%Y' }}{% endcapture %}
      {% if year != written_year %}
        <h3>{{ year }}</h3>
        {% capture written_year %}{{ year }}{% endcapture %}
      {% endif %}
      <article>
        {% if post.link %}
          <h2 class="link-post"><a href="{{ site.url }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a> <a href="{{ post.link }}" target="_blank" title="{{ post.title }}"><i class="fa fa-link"></i></a></h2>
        {% else %}
          <h2><a href="{{ site.url }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a></h2>
          <p>{{ post.excerpt | strip_html | truncate: 160 }}</p>
        {% endif %}
      </article>
    {% endfor %}
  </div><!-- /#index -->
</div><!-- /#main -->

<div class="footer-wrap">
  <footer>
    {% include _footer.html %}
  </footer>
</div><!-- /.footer-wrap -->

{% include _scripts.html %}

</body>
</html>

正确的索引:

<!doctype html>
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if (IE 7)&!(IEMobile)]><html class="no-js lt-ie9 lt-ie8" lang="en"><![endif]-->
<!--[if (IE 8)&!(IEMobile)]><html class="no-js lt-ie9" lang="en"><![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"><!--<![endif]-->
<head>
{% include _head.html %}
</head>

<body class="post-index">

{% include _browser-upgrade.html %}

{% include _navigation.html %}

{% if page.image.feature %}
  <div class="image-wrap">
  <img src=
    {% if page.image.feature contains 'http' %}
      "{{ page.image.feature }}"
    {% else %}
      "{{ site.url }}/images/{{ page.image.feature }}"
    {% endif %}
  alt="{{ page.title }} feature image">
  {% if page.image.credit %}
    <span class="image-credit">Photo Credit: <a href="{{ page.image.creditlink }}">{{ page.image.credit }}</a></span>
  {% endif %}
  </div><!-- /.image-wrap -->
{% endif %}

<div id="main" role="main">
  <div class="article-author-side">
    {% include _author-bio.html %}
  </div>
  <div id="index">
    <h1>{{ page.title }}</h1>
    {% capture written_year %}'None'{% endcapture %}
    {% for post in site.posts %}  
      {% capture year %}{{ post.date | date: '%Y' }}{% endcapture %}
      {% if year != written_year %}
        <h3>{{ year }}</h3>
        {% capture written_year %}{{ year }}{% endcapture %}
      {% endif %}
      <article>
        {% if post.link %}
          <h2 class="link-post"><a href="{{ site.url }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a> <a href="{{ post.link }}" target="_blank" title="{{ post.title }}"><i class="fa fa-link"></i></a></h2>
        {% else %}
          <h2><a href="{{ site.url }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a></h2>
          <p>{{ post.excerpt | strip_html | truncate: 160 }}</p>
        {% endif %}
      </article>
    {% endfor %}
  </div><!-- /#index -->
</div><!-- /#main -->

<div class="footer-wrap">
  <footer>
    {% include _footer.html %}
  </footer>
</div><!-- /.footer-wrap -->

{% include _scripts.html %}

</body>
</html>

任何人都可以指导我如何使这两个页面首先列出链接。

此外,这里是与帖子相关的_config.yml部分:

collections:
  work:
    output: true
    permalink: /:collection/:path/

defaults:
  # _work
  - scope:
      path: ""
      type: work
    values:
      layout: single
      author_profile: false
      share: true

1 个答案:

答案 0 :(得分:3)

你的'错误'代码正在处理收集。收集项目按时间顺序排序。唯一的例外是site.posts以反向时间顺序排序。

要按逆时间顺序输出site.work集合,您可以执行以下操作:

{% for post in site.work reversed %}