如何在 Jekyll 中使用 markdownify 显示索引摘录

2023-12-24

我希望在索引页上显示较长帖子或页面的简短文本摘录。我本来打算在 Front Matter 中使用自定义变量并抓住它,但后来我看到了过滤器.excerpt

我看到在Jekyll 文档 http://jekyllrb.com/docs/templates/有一种东西叫做{{ page.excerpt | markdownify }}我如何在页面或帖子上标记降价才能使用该过滤器?

编辑: 或者 markdownify 是否获取整个 .md 文档?


杰基尔有一个选择excerpt_separator http://jekyllrb.com/docs/posts/#post-excerpts,适合您。 事情是这样的:

In _config.yml:

excerpt_separator: <!--more-->  # you can specify your own separator, of course.

在您的帖子中:

---
layout: post
title: Foo
---

This appears in your `index.html`

This appears, too.

<!--more-->

This doesn't appear. It is separated.

请注意,您必须准确输入<!--more-->, not <!--More--> or <!-- more -->.

In your index.html:

<!-- Loop in you posts -->
{% for post in site.posts %}
  <!-- Here's the header -->
  <header>
    <h2 class="title"><a href="{{ post.url }}">{{ post.title }}</a></h2>
  </header>

  <!-- Your post's summary goes here -->
  <article>{{ post.excerpt }}</article> 
{% endfor %}

输出是这样的:

<header>
  <h2 class="title"><a href="Your post URL">Foo</a></h2>
</header>

<article>

This appears in your `index.html`

This appears, too.

</article>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Jekyll 中使用 markdownify 显示索引摘录 的相关文章

随机推荐