【问题标题】:How to combine multiple Markdown sources in a Nunjkucks template in Eleventy如何在 Eleventy 的 Nunjkucks 模板中组合多个 Markdown 源
【发布时间】:2020-10-27 20:07:04
【问题描述】:

我在 Eleventy 中使用 Nunjucks 模板。页面布局由一个主要的content 区域和一个aside 组成。我可以将 Markdown 用于内容,但找不到使用 Markdown 的方法。 Markdown 似乎只有一个来源;模板中包含的任何其他来源都必须是 Nunjucks 模板。

index.njk:

  <article>
    {{ content | safe }} 
  </article>
  <aside>
    {% include "aside.md" %}
  </aside>

aside.md:

# Aside.

结果:

<article>
<p>This is the content from the upstream Markdown.</p>
</article>
<aside>
# Aside.
</aside>

除此之外仍然是原始的 Markdown。如何包含已处理的 Markdown?

我是所有这些技术的新手,感觉我缺少一些基本的东西。

【问题讨论】:

标签: markdown nunjucks eleventy


【解决方案1】:

使用包含

包含必须放在特定文件夹(_includes - 您可以覆盖此文件夹名称,甚至有子文件夹) :

    {% include 'partials/google-analytics.html' %}
    {% include 'partials/cookie-consent.html' %}
    {% include 'partials/post-sharing.html' %}

或者你可以定义一个(它们必须被导入,或者在你使用它们的地方定义)。宏的优点是您可以在调用它们时传入参数它们作为函数工作...

{% macro paginationLink(active, disabled, href, title) %}    
    <li class="page-item {% if active %} active {% elseif disabled %} disabled {% endif %}">
        {% if disabled %} 
            <span class="page-link">{{ title | safe }}</span>
        {% else %}
            <a class="page-link" href="{{ href | url }}">{{ title | safe }}</a>
        {% endif %}        
    </li>
{% endmacro %}

然后可以轻松调用宏 ^:

{{ paginationLink(false, isFirst, firstPageHref, '<i class="fas fa-angle-double-left"></i>') }}

【讨论】:

    猜你喜欢
    • 2020-12-03
    • 2022-11-01
    • 2012-03-28
    • 1970-01-01
    • 2021-12-14
    • 2020-02-26
    • 2010-09-29
    • 1970-01-01
    • 2020-08-16
    相关资源
    最近更新 更多