如何在Jekyll中定义自定义集合?

 我所信仰的感觉 发布于 2023-01-08 21:20

在Jekyll Collections文档之后,我在_config.yml中编写了以下代码

_config.yml

collections: 
- popular_posts

因此,当我打印{{site.collections}}时,输出为"popular_posts".

我还在"_posts"的同一级别创建了一个名为"_popular_posts"的文件夹._popular_posts包含两个.md文件,其中包含一些YAML前端内容,与帖子相同.

但是,如果我打印{{site.popular_posts}}或{{site.collections.popular_posts}},则没有输出.

如何让Jekyll识别该目录中的.md文件,以便以下代码可以正常工作?

{% for popular_post in site.popular_posts %}
  
    

{{ popular_post.title }}

{{ popular_post.number }}/5 {% endfor %}

小智.. 5

这很容易!你走在正确的轨道上.在你的_config.yml:

collections:
- popular_posts

这将告诉Jekyll读入所有文件_popular_posts.

如果您希望这两个文件中的每一个都有相应的输出文件(如_posts现在的工作方式),您需要将您的更改_config.yml为:

collections:
  popular_posts:
    output: true

这将在生产文件/popular_posts/filename1.html/popular_posts/filename2.html对每个岗位的一页.

收藏只是最近在GitHub页面上,所以如果你在那里尝试,它将失败.

如果您需要,请查看jekyll-help以获得更多帮助!

1 个回答
  • 这很容易!你走在正确的轨道上.在你的_config.yml:

    collections:
    - popular_posts
    

    这将告诉Jekyll读入所有文件_popular_posts.

    如果您希望这两个文件中的每一个都有相应的输出文件(如_posts现在的工作方式),您需要将您的更改_config.yml为:

    collections:
      popular_posts:
        output: true
    

    这将在生产文件/popular_posts/filename1.html/popular_posts/filename2.html对每个岗位的一页.

    收藏只是最近在GitHub页面上,所以如果你在那里尝试,它将失败.

    如果您需要,请查看jekyll-help以获得更多帮助!

    2023-01-08 21:29 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有