首页 > 解决方案 > Jekyll 包含转义结束标签?

问题描述

所以我有一个具有以下基本结构的站点:

<body>
  <section>
    <p>Text of Section 1</p>
  </section>
  <section>
    <p>Text of Section 2</p>
  </section>
...
</body>

我想使用 jekyll 从 markdown 文件生成整个网站,但由于 markdown 不知道任何类似部分的内容,我的想法是使用 markdown 作为普通文本,然后从另一个文件中包含缺少的 html,如下所示:

---
layout: default.html
---

Text of Section 1.

{% include sectionbreak.html %}

Text of Section 2.

为此,sectionbreak.html必须包含类似

</section>
<section>

但是,jekyll似乎会在包含文件的开头自动转义任何关闭的 html 标记,结果是一个更像这样的网站,彼此堆叠越来越多的部分:

<body>
  <section>
    <p>Text of Section 1</p>
  <p>&lt;/section&gt;</p>
  <section>
    <p>Text of Section 2</p>
 ...
</body>

有没有人知道如何禁用这种行为,或者做什么来生成网站?

标签: htmlincludeescapingjekyll

解决方案


这是每一页的事情吗?或者只是一个专业的头版?我不明白你为什么要创建这样的常规日常帖子,但我已经为我的首页做了这个,我有这样的东西:

|-...
|- _landing
 |- intro.md
 |- blog.md
 |- projects.md
|- index.html

在我index.hml的主页中,我拉入按 ._landing排序的所有集合frontmatter.index。它可以让您重新排序并将部分添加到您的主页,其中landing/blog.md仅包含最新的 5-10 个条目和一个链接,pages/archive.html其中包含完整的分页帖子列表。

同样,我不会对您网站上的每个页面都建议这样做,但它适用于我数量有限的专业页面。像:

  • 具有多个链接到整页的摘要部分的索引/登录页面
  • 具有多个联系部分的联系页面

编辑

对于冰雹玛丽来说,这个怎么样,如果不通过 jekyll 源,我不知道它是否会起作用,但是:

{% assign sections = page.content | split:"<!-- SPLIT -->" %}
{% for section in sections %}
<section>
  {{ section }}
</section>
<banner>
</banner>
{% endfor %}

快速谷歌表明这可能不像我想象的那么疯狂:https ://gist.github.com/Phlow/04f635e4d1fc928b1157


推荐阅读