You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Jekyll集合指定子目录并配置permalink及排除文件?

Jekyll集合路径与Permalink配置解决方案

一、核心集合配置

要实现将_stuff/data/下的文件作为集合,同时生成stuff/{文件名}/格式的Permalink,在_config.yml中添加如下配置:

collections:
  stuff:
    output: true
    permalink: /stuff/:title/
    path: "_stuff/data"
  • path: "_stuff/data":指定集合仅读取_stuff/data目录下的文件,自动排除_stuff下的其他直接文件或子文件夹
  • permalink: /stuff/:title/:定义生成的URL格式

二、:title占位符行为解释

你遇到的:title解析为不带.md的文件名而非frontmatter中title字段的问题,是Jekyll的默认规则:

  • Jekyll的:title占位符默认优先使用文件的basename(即去除扩展名的文件名),而非frontmatter里的title值
  • 若想让Permalink使用frontmatter中的title字段,需改用:slug占位符(Jekyll会自动将frontmatter的title转换为URL友好的slug格式),修改后的Permalink配置为:
    permalink: /stuff/:slug/
    

三、额外排除规则(可选)

如果_stuff目录下存在其他需要完全排除出Jekyll构建流程的文件/子目录(比如非集合的页面、资源文件),可在_config.yml中添加exclude配置:

exclude:
  - "_stuff/*.md"
  - "_stuff/other-folder/"

内容的提问来源于stack exchange,提问作者Giszmo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 02:18:15