【发布时间】:2013-05-01 15:16:06
【问题描述】:
我希望在索引页面上显示来自较长帖子或页面的简短文本摘录。我打算在 Front Matter 中使用一个自定义变量并抓住它,但后来我看到了 .excerpt 的过滤器
我在Jekyll docs 中看到了一个叫做{{ page.excerpt | markdownify }} 的东西我如何在页面或帖子上标记降价以使用该过滤器?
edit:还是 markdownify 会占用整个 .md 文档?
【问题讨论】:
我希望在索引页面上显示来自较长帖子或页面的简短文本摘录。我打算在 Front Matter 中使用一个自定义变量并抓住它,但后来我看到了 .excerpt 的过滤器
我在Jekyll docs 中看到了一个叫做{{ page.excerpt | markdownify }} 的东西我如何在页面或帖子上标记降价以使用该过滤器?
edit:还是 markdownify 会占用整个 .md 文档?
【问题讨论】:
在帖子降价文件中,您需要先设置摘录,这是我的一篇帖子中的示例
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.
然后在索引页面调用标签
{{ post.excerpt }}
这应该会输出你在降价文件中写的内容。很好很简单,为什么我喜欢 Jekyll。
【讨论】:
Jekyll 有一个选项excerpt_separator,适合你。
事情是这样的:
在_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-->,而不是<!--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 %}
输出是这样的:
<header>
<h2 class="title"><a href="Your post URL">Foo</a></h2>
</header>
<article>
This appears in your `index.html`
This appears, too.
</article>
【讨论】:
截至参考84cfc1cef,jekyll 的 github 版本支持每个帖子 excerpt_separator,因此您必须添加对 Gemfile 的引用:
gem 'jekyll', github: 'jekyll/jekyll', ref: '84cfc1ceff0474fd3eb3beb193ae59ae43694863'
并使用以下YAML 创建帖子:
---
title: Post Excerpt Separator
excerpt_separator: "\n---\n"
---
【讨论】:
不适用于 mu 或集合,jekyll 在遇到除了解析液体时会出现恐慌。我不知道这是为什么,它应该按照你的建议工作。
还有一个选择:
post.content 或我的情况是:blogX.content 并通过一些限制内容大小的文本过滤器粉碎它。
即: {{ 博客内容 | strip_html |截断字数:100 }}
【讨论】: