Jekyll 开始 * 和 * 结束摘录分隔符

Jekyll begin *and* end excerpt separators

我正在用 Jekyll 写博客。我知道 jekyll 有 excerpt_separator 可以用来指定摘录的结尾,比如

This is a blog post, click to see more than this
<!-- more -->
This is not in excerpt

但是,我想在我的每篇博文中引用一段话,但不要在摘录中包含那段话。像

>   “There are two ways of constructing a software design: One way is to make it
>   so simple that there are obviously no deficiencies and the other way is to
>   make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare

<!-- begin_excerpt -->
This is the excerpt
<!-- end_excerpt -->

Not part of the excerpt.

到目前为止,我一直无法找到支持这一点的证据。
我该如何着手完成这项工作?

遗憾的是,默认情况下,Jekyll 不支持指定摘录开头的方法。

解决此问题的一种可能方法是在 Jekyll 的前言中使用 excerpt 变量,直接将所需文本写入其中,然后显示 page.excerpt 变量的值在页面内容中。

它有点乱,而且会破坏页面内容,但它会起作用。

---
excerpt: 'This is the excerpt'
---

>   “There are two ways of constructing a software design: One way is to make it
>   so simple that there are obviously no deficiencies and the other way is to
>   make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare

{{ page.excerpt }} // This is the excerpt

Not part of the excerpt.

我找到了一种可行的替代方法,并且不会破坏预期的行为。我发现如果您将引用移至首页并更改布局,则可以让摘录忽略引用。

样本post:

---
title: Test of Quote Post
layout: quotepost
categories: Random
comments: false
quote: |
    Hack the Planet!  
    Hack the Planet!
---
A sample post preceded by a quote.

布局部分:

{% if page.quote %}
  <p class="lead">{{ page.quote | markdownify }}</p> 
{% endif %}     
<p class="lead">{{ content }}</p>

之所以有效,是因为引用不再是 post 内容的一部分。然而,posts 布局会将引用添加到 posts 内容之前的页面布局中。您甚至可以通过这种方式为引号提供自己的样式属性。这也是您向页面添加不属于内容(如评论)的功能的方式。

注意:如果您希望引文位于不同的行,则必须在每行引文后添加双 space。此外,如果您希望在另一页上显示完整的 posts 内容,则必须根据需要手动添加引号。