Jekyll on Github Pages:在另一个降价文件中包含markdown

And*_*Mao 10 markdown static-site jekyll github-pages kramdown

kramdown在Github Pages上使用Jekyll.我有一个降价我想要使用两次,并且不想维护它的两个版本.如何将其包含在其他降价文件中?

例如,我想键入类似的东西

{: include otherFile.md }
Run Code Online (Sandbox Code Playgroud)

otherFile.md在此命令所在的位置直接呈现内容.请注意,父文件也是markdown文件,而不是HTML模板.

额外的考虑:能够使用默认的GitHub页面工作流来完成这项工作会很棒,而不必使用GH页面禁用的插件,并且必须手动推送站点的编译版本.

Ben*_* W. 13

走的路似乎是include_relative.我在旧的Jekyll论坛上找到了用户geraldb的回答:

是的,有一个简单的方法.它在Jekyll(和GitHub Pages)中"开箱即用".刚试了一下.请参阅Vienna.html测试页面,例如:

---
layout: default
---

some text here

{% include_relative test_header.md %}

some more text here

{% include_relative test_footer.md %}
Run Code Online (Sandbox Code Playgroud)

查看源 - > test.md实时页面.

"招",如果你想叫它如此-是使用include_relative ,如果你想拥有的积木文本(例如intro.md, explanation.md,conclusion.md与你一起页等)(在同一文件夹).干杯.快乐的Jekylling.


自从我第一次写这个答案以来,原来的论坛帖子似乎完全没了,我还没有发现它存档在archive.org上.旧论坛上的答案链接是这样的,新论坛中geraldb的个人资料就在这里.

引用答案中的链接不再起作用,但这里是viennahtml.github.io repo 的链接.

  • `include_relative` 也对我有用。尽管 [Jekyll 教程页面上的示例代码](https://jekyllrb.com/docs/includes/#include-files-relative-to-another-file) 仅显示了嵌入 .html 文件的情况,它也适用于 .md 文件。 (2认同)

bio*_*uri 12

对我来说,问题无法通过导入include_relative和使用正常 include不呈现包含的 Markdown 文件来解决。

但是捕获包含然后通过管道传输它markdownify是一个很好的解决方法:

{% capture my_include %}{% include a_markdown_file.md %}{% endcapture %}
{{ my_include | markdownify }}
Run Code Online (Sandbox Code Playgroud)

我在GH:/jekyll/jekyll#1303 (comment) 中找到了这个。这是避免捕获的功能请求。不幸的是,它已关闭。