首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用jekyll在_posts order by time子目录中列出我的帖子

如何使用jekyll在_posts order by time子目录中列出我的帖子
EN

Stack Overflow用户
提问于 2016-09-06 17:58:54
回答 2查看 1.2K关注 0票数 3

我使用jekyll构建的mmistakes/minimal-mistakes来构建我的github页面。

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

下面是我的项目的目录结构:

代码语言:javascript
复制
.
├── _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下的帖子呢?)

代码语言:javascript
复制
---
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

代码语言:javascript
复制
{% if site.url %}
  {% assign base_path = site.url | append: site.baseurl %}
{% else %}
  {% assign base_path = site.github.url %}
{% endif %}

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

代码语言:javascript
复制
---
title: aaa
categories: /android/third-party/
---
write some contents.

下面是_config.yml的代码片段

代码语言:javascript
复制
# 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之类的东西。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-06 19:01:56

正如here所说的,下面的代码应该可以工作:

代码语言:javascript
复制
{% for post in site.categories.android %}
  {% include archive-single.html %}
{% endfor %}

使用如下声明的类别:

代码语言:javascript
复制
categories: android third-party
票数 1
EN

Stack Overflow用户

发布于 2018-05-20 22:25:31

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

代码语言:javascript
复制
{% for post in site.posts %}
  {% if post.path contains 'android' %}
     {% include archive-single.html %}
  {% endif %}
{% endfor %}   
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39346102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档