【问题标题】:Jekyll includes escapes closing tags?Jekyll 包含转义结束标签?
【发布时间】:2020-01-23 14:27:55
【问题描述】:

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

<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>

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

【问题讨论】:

    标签: html include escaping jekyll


    【解决方案1】:

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

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

    在我的主页index.hml 中,我拉入了按frontmatter.index 排序的所有_landing 集合。它可以让您重新排序并将部分添加到您的主页,其中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

    【讨论】:

    • 这是一种每页的东西——想法是在部分之间放置带有引号的横幅,这些横幅会贯穿整个页面,并且当它们在一个部分内时不起作用。我已经有类似您描述的多个文件的内容,但想将它们合并为一个,否则它开始对所有较小的文件造成麻烦(也可能需要注意:我不是在写博客,只是链接到的多个站点彼此)。
    【解决方案2】:

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

    起初,我想出了与其他答案类似的东西:

    /_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
    

    【讨论】:

      猜你喜欢
      • 2016-05-13
      • 1970-01-01
      • 1970-01-01
      • 2012-12-22
      • 1970-01-01
      • 2012-01-14
      • 2019-07-19
      • 1970-01-01
      • 2011-01-23
      相关资源
      最近更新 更多