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

kap*_*lan 24 markdown liquid jekyll

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

我在Jekyll文档中看到有一些东西叫做{{ page.excerpt | markdownify }}如何在页面或帖子上标记降价以便使用该过滤器?

编辑:或者markdownify是否采用整个.md文档?

Cho*_*Ren 77

Jekyll有一个excerpt_separator适合你的选择.事情是这样的:

_config.yml:

excerpt_separator: <!--more-->  # you can specify your own separator, of course.
Run Code Online (Sandbox Code Playgroud)

在你发布:

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

This appears in your `index.html`

This appears, too.

<!--more-->

This doesn't appear. It is separated.
Run Code Online (Sandbox Code Playgroud)

请注意,您必须准确输入<!--more-->,而不是<!--More--><!-- more -->.

在你的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 %}
Run Code Online (Sandbox Code Playgroud)

输出是这样的:

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

<article>

This appears in your `index.html`

This appears, too.

</article>
Run Code Online (Sandbox Code Playgroud)


jos*_*y10 14

在post markdown文件中,您需要先设置摘录,以下是我的一篇帖子中的示例

layout: post
title: A developers toolkit
date: Friday 14 December, 2012
excerpt: What text editor to use? Sass or plain old CSS? What on earth is Compass? Command    line? I'm not touching that. Sound like you? Welcome, I was once like you and this is the guide I wish someone had given me.
Run Code Online (Sandbox Code Playgroud)

然后在索引页面上调用标记

{{ post.excerpt }}
Run Code Online (Sandbox Code Playgroud)

然后应该输出你在markdown文件中写的内容.很好,很简单,为什么我喜欢Jekyll.