为什么删除 yaml front matter 会阻止 Jekyll 将 md 文件转换为 html

Why does removing yaml front matter stop Jekyll from converting md file to html

我继承了一个使用 jekyll 将 markdown 内容转换为 html 的过程。

如果我删除 --- 之间的 yaml 前端内容,应客户要求简化编辑过程,

---
product: Product Name
capability: testing
infotype: Overview
audience:

---

# Testing file 2

This is another testing file.

jekyll 构建不转换文件。

# Testing file 2

This is another testing file.

当我在测试 2 文件中有前面的内容时,我在 运行 build --verbose

时在日志中看到以下内容
Rendering: user-administration/testing-file-2.md
Pre-Render Hooks: user-administration/testing-file-2.md
Rendering Markup: user-administration/testing-file-2.md
Rendering Layout: user-administration/testing-file-2.md

但是如果没有前面的内容,日志中就没有与测试文件相关的消息-2.md

此测试文件-2.md 是具有元数据的其他文件集合的一部分。当删除元数据时,它们会呈现在 html 网站中,但不会呈现在测试文件 -2.md 中。

有没有一种方法可以让 Jekyll 构建和渲染没有前端内容的文件?

我已经 read 要求至少有空的前面内容,否则 jekyll 会忽略该文件

---
---

Jekyll 不会忽略任何文件。相反,对于每个文件,它决定文件是否是:

  • 静态文件,可以按原样复制到输出文件夹 (_site),或
  • 先处理一个文件。

Markdown 文件 (.md) 由 kramdown and Liquid 处理 if 它们以 YAML frontmatter 开头:

---
---

否则它们将被视为静态文件,并复制到 _site 而不进行任何处理。

使用 include_relative 有一个可能对您有用的解决方法;但这可能会给您客户的编辑带来更多的麻烦,这取决于他们的工作方式。

您可以在要处理的文件中包含一个静态文件。您的静态文件可能是 plain-text.md:

# Static text file

This is a file with no YAML frontmatter.

然后,您单独创建一个带有 frontmatter 的 markdown 文件,其中将包含纯文本文件。比如说,processed-text.md:

---
---
{% include_relative plaintext.md %}

然后您的纯文本将被处理并在您的网站上显示为 /processed-text。将文件 processed-text.md 视为一种用于保存 plain-text.md.

的模板

你会想看到the docs on include_relative,尤其是要包含的文件不能在文件系统中的包含文件之上。