markdown - GitHub 页面上的 Jekyll : include markdown in another markdown file

标签 markdown jekyll github-pages static-site kramdown

我正在使用 kramdown在 GitHub 页面上使用 Jekyll。我有一 block markdown,我想使用两次,不想维护它的两个版本。如何将其包含在其他 Markdown 文件中?

例如,我想输入类似

{: include otherFile.md }

并具有 otherFile.md 的内容直接在这个命令所在的地方渲染。请注意,父文件也是 markdown 文件,而不是 HTML 模板。

额外的考虑:如果能够使用默认的 GitHub 页面工作流程做到这一点,并且不必使用 GH 页面禁用的插件并且必须手动推送站点的编译版本,那就太好了。

最佳答案

要走的路似乎是 include_relative .我在旧的 Jekyll forums 上找到了用户 geraldb 的答案:

Yes, there's a simple way. It works "out-of-the-box" in Jekyll (and GitHub Pages). Just tried it. See the Vienna.html test page e.g.:

---
layout: default
---

some text here

{% include_relative test_header.md %}

some more text here

{% include_relative test_footer.md %}

See the source -> test.md and the live page.

The "trick" if you want to call it so - is to use include_relative if you want to have the building block texts (e.g. intro.md, explanation.md, conclusion.md, etc.) along with your page (in the same folder). Cheers. Happy Jekylling.



自从我第一次写这个答案以来,原来的论坛帖子似乎已经完全消失了,我还没有在archive.org上找到它存档。旧版的回答链接是this (现在指向一个无关的帖子),新论坛中geraldb的个人资料是here .

引用的答案中的第一个链接已更新为指向当前存在的 repo 中的正确文件,1 并且第二个链接已失效但保持不变,因为我在这里引用了原作者。

1感谢 Ben Leggiero为了找到它!

关于markdown - GitHub 页面上的 Jekyll : include markdown in another markdown file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41966638/

相关文章:

在 GitHub 页面上部署 Angular

javascript - 如何在 JavaScript 中的字符串中添加反斜杠?

jquery - Rails 标记/标记或纺织

html - Markdown 中的 Rowspan 语法

python - 使用 R Markdown 样式文档 (.Rmd) 作为 Pweave 的输入

dns - CNAME 记录是否公开

ruby - 在 Windows 7 上运行 Jekyll

ruby -/usr/bin/jekyll : No such file or directory

javascript - 如何在 Javascript 中模拟按下按钮以触发 Simple-Jekyll-Search 中的搜索

markdown - Jekyll Markdown 处理器类似于 GitHub flavor 的 Markdown