如何使用 jekyll 按时间顺序在 _posts 的子目录中列出我的帖子

how to list my posts in a sub directory of _posts order by time with jekyll

我正在使用 mmistakes/minimal-mistakes 构建我的 github 页面。

我想在 _pages/android.html 中列出我在 _posts/android 下的所有帖子。意思是,我想把 2016-09-01-aaa.md2016-09-02-bbb.md2016-08-26-ccc.md 但不是 2016-09-03-ddd.md 放在 _pages/android.html.

这是我项目的目录结构:

.
├── _config.yml
├── _pages
│    └── android.html
├── _posts
│    ├── android
│    │    ├── third-party
│    │    │    ├── 2016-09-01-aaa.md
│    │    │    └── 2016-09-02-bbb.md
│    │    └── handler
│    │         └── 2016-08-26-ccc.md
│    └── java
│         └── effective-java
│              └── 2016-09-03-ddd.md
└── _site
     ├── index.html (my github home page)
     ├── android
     │    ├── index.html (generated from "_pages/android.html")
     │    ├── third-party
     │    │    ├── aaa
     │    │    │    └── index.html
     │    │    └── bbb
     │    │         └── index.html
     │    └── handler
     │         └── ccc
     │              └── index.html
     └── java
          └── effective-java
               └── ddd
                    └── index.html

这里是_pages/android.html:

(但它会列出 _posts 下的所有帖子, 我怎样才能让它只列出 _posts/android 下的帖子?)

---
layout: archive
permalink: /android/
excerpt: "android"
author_profile: false
sidebar:
  nav: "android"
---
{% include base_path %}

<h3 class="archive__subtitle">{{ site.data.ui-text[site.locale].recent_posts | default: "Recent Posts" }}</h3>

{% for post in site.posts %}
  {% include archive-single.html %}
{% endfor %}

这里是_include/base_path:

{% if site.url %}
  {% assign base_path = site.url | append: site.baseurl %}
{% else %}
  {% assign base_path = site.github.url %}
{% endif %}

这里是2016-09-01-aaa.md: (其他帖子与此类似。)

---
title: aaa
categories: /android/third-party/
---
write some contents.

这是 _config.yml 的片段:

# Site Settings
locale                   : "zh-CN"
title                    : "IT Tech"
title_separator          : "-"
name                     : "TesTName"
description              : "Android Java HTML CSS JavaScript Ubuntu"
url                      : "http://localhost:4000"  # the base hostname & protocol for your site e.g. "https://mmistakes.github.io"
baseurl                  : # the subpath of your site, e.g. "/blog"

# Defaults
defaults:
  # _posts
  - scope:
      path: ""
      type: posts
    values:
      layout: single
      author_profile: true
      read_time: false
      comments: true
      share: true
      related: false
  # _pages
  - scope:
      path: ""
      type: pages
    values:
      layout: single
      author_profile: true
      related: true

那么,我该怎么做呢?我真的不擅长 html 和 jekyll 的东西。

here 所述,以下应该有效:

{% for post in site.categories.android %}
  {% include archive-single.html %}
{% endfor %}

类别声明如下:

categories: android third-party

post.path 将列出您在子文件夹 _posts/android

中的所有帖子
{% for post in site.posts %}
  {% if post.path contains 'android' %}
     {% include archive-single.html %}
  {% endif %}
{% endfor %}