使用 Jekyll 包含另一个页面而不显示 Front Matter

发布于 2025-01-14 03:13:43 字数 722 浏览 2 评论 0原文

我正在尝试将 index.html 的输出克隆到另一个页面 thanks.html 中。它正在工作,但无论我尝试什么,我最终都会得到 ---layout: default title: example --- 渲染(来自 index.html 的 Front Matter)文件开始的地方。

我尝试过:

---
layout: default
thanks: true
---
{% capture main %}{% include_relative /index.html %}{% endcapture %}
{{ main }}

并且:

---
layout: default
thanks: true
---
{% include_relative /index.html %} <!-- Same problem with just 'include' -->

但我得到了相同的结果。

如果我删除行 layout: default 它可以工作,但正如预期的那样,我不再有页眉或页脚。我也可以使用包含来使其工作,但这会导致具有不同行的页面出现大量重复。

如果相关的话,我正在通过 docker 运行 Jekyll 版本 4.2.2,并且我的 _config.yml 中没有设置插件。

I'm trying to clone the output of index.html in another page, thanks.html. It's working, but no matter what I try I end up with --- layout: default title: example --- rendered (from index.html's Front Matter) where the file starts.

I've tried:

---
layout: default
thanks: true
---
{% capture main %}{% include_relative /index.html %}{% endcapture %}
{{ main }}

And:

---
layout: default
thanks: true
---
{% include_relative /index.html %} <!-- Same problem with just 'include' -->

But I get the same result.

If I drop the line layout: default it works, but as expected I don't have a header or footer anymore. I can also get it to work using includes but this makes for a lot of duplication for a page with a single line that's different.

In case it's relevant, I'm running Jekyll version 4.2.2 via docker, and there are no plugins set in my _config.yml.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜唯美灬不弃 2025-01-21 03:13:43

一个脆弱的黑客:

{% capture source %}{% include_relative included.html %}{% endcapture %}
{{ source | split: "---" | last }}

只是不要在包含的文档中的任何地方使用 --- 。 :)

A fragile hack:

{% capture source %}{% include_relative included.html %}{% endcapture %}
{{ source | split: "---" | last }}

Just don’t use --- anywhere in the included document. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文