【问题标题】:Why does removing yaml front matter stop Jekyll from converting md file to html为什么删除 yaml 前端会阻止 Jekyll 将 md 文件转换为 html
【发布时间】:2019-05-14 12:13:37
【问题描述】:

我继承了一个使用 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

但如果没有前面的问题,日志中没有与 testing-file-2.md 相关的消息

此 testing-file-2.md 是具有元数据的其他文件集合的一部分。删除元数据后,它们会呈现到 html 网站,但不会呈现到 testing-file-2.md。

jekyll 有没有一种方法可以在没有前端的情况下构建和渲染文件?

【问题讨论】:

    标签: jekyll


    【解决方案1】:

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

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

    Markdown 文件 (.md) 由 kramdownLiquid 处理 如果 它们以 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,尤其是要包含的文件不能高于文件系统中包含文件的事实。

    【讨论】:

    • 如果您希望您的文件被处理/转换为 html,请将 --- 放在开头,不要换行。谢谢亚瑟
    【解决方案2】:

    我已经 read 要求至少有一个空的前端,否则 jekyll 将忽略该文件

    ---
    ---
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      • 2018-01-19
      相关资源
      最近更新 更多