Jekyll是否包含转义结束标签?

时间:2020-01-23 14:27:55

标签: html include escaping 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>

有人对如何禁用此行为有什么想法,或者怎么做才能生成网站?

2 个答案:

答案 0 :(得分:0)

这是每一页的事情吗?还是只有专业首页?我不明白为什么您要创建像这样的常规日常帖子,但是我已经在我的首页上做到了,

|-...
|- _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 %}

快速的google显示,这可能没有我想象的那么疯狂:https://gist.github.com/Phlow/04f635e4d1fc928b1157

答案 1 :(得分:0)

我认为问题不在于 Jekyll,而在于 Markdown。据我所知,没有办法让 Jekyll-flavored Markdown 正确解释悬空/孤立 </closing tag>。它将被解释为纯文本并包含在 <p> 段落中。

起初我想出了类似其他答案所显示的内容:

/_layouts/default.html

{%- assign content = content | replace: "<!-- section break -->", "</section><section>" -%}

<section>
  {{ content }}
</section>

但最终我还需要将参数附加到该部分。这是我实现这一目标的非常糟糕的方式。

/_includes/section.html

<!-- $uncomment </section> $uncomment -->
<!-- $uncomment <section style="background-color: {{ include.background }}"> $uncomment -->

/_layouts/default.html

{% assign content = content | replace:"<!-- $uncomment ","" %}
{% assign content = content | replace:" $uncomment -->","" %}

index.md


blah blah blah plain section

{% include section.html %}

blah blah blah plain section

{% include section.html background="#ff0000" %}

blah blah blah section with red background color