【问题标题】:how to list my posts in a sub directory of _posts order by time with jekyll如何使用 jekyll 按时间顺序在 _posts 的子目录中列出我的帖子
【发布时间】:2017-01-13 17:45:28
【问题描述】:

我正在使用mmistakes/minimal-mistakes,它是用 jekyll 构建的来构建我的 github 页面。

我想在_pages/android.html 中列出我在_posts/android 下的所有帖子。意思是,我想把 2016-09-01-aaa.md,2016-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的sn-p:

# 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 的东西。

【问题讨论】:

    标签: html yaml jekyll liquid github-pages


    【解决方案1】:

    post.path 将列出您在子文件夹_posts/android 中的所有帖子

    {% for post in site.posts %}
      {% if post.path contains 'android' %}
         {% include archive-single.html %}
      {% endif %}
    {% endfor %}   
    

    【讨论】:

      【解决方案2】:

      here 所述,以下应该可以工作:

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

      使用这样声明的类别:

      categories: android third-party
      

      【讨论】:

      • 我试过了,{% for post in site.categories.android %} 不起作用,{% for post in site.posts.android %} 都不起作用。那些代码什么也没显示。
      • @gncavalry 我认为问题在于您的类别声明。而不是categories: /android/third-party/,试试categories: android third-party
      • 你是对的,将类别更改为android third-party 并使用代码{% for post in site.categories.android %} {% include archive-single.html %} {% endfor %} .我第一次验证时一定有问题。谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-16
      • 1970-01-01
      • 2016-12-22
      • 2013-05-14
      • 1970-01-01
      • 2015-01-15
      相关资源
      最近更新 更多