我正在使用Jekyll创建一个新的博客。
在主页面上,将列出我最近的10篇文章。
这个列表中的条目将包括标题、发布日期和摘要,很可能是第一段。
我只熟悉基本模板的Jekyll用法,所以页面中只能放一个变量或者整篇文章。
有没有一种方法可以避免在分页器中使用post.content
,仅包含我定义的某一点之前的内容 (例如“{% endexcerpt %}”)?
类似于{{ post.content | strip_html | truncatewords: 50 }}
这样的内容会产生更加一致的节选。它获取前50个单词并去除任何格式。
当然,您可以使用{{ post.excerpt }}
替代{{ post.content }}
。
如果您不喜欢自动生成的节选内容,您还可以手动覆盖它们。
有关如何执行此操作的完整文档,请参见: http://jekyllrb.com/docs/posts/#post-excerpts
<!--more-->
来告诉 Jekyll 在摘要内容中应该“截断”文章,或者在 _config.yml
中全局设置插入分隔符。 - eQ19使用
{{ post.content | markdownify | strip_html | truncatewords: 50 }}
使用{{ post.excerpt }}
或{{ post.content }}
的替代方法。
这将提供一致长度的未格式化文本块,其中不包含原始的markdown内容。整洁。
感谢@karolis-ramanauskas的这条评论,我已将其制作成正式答案以便更好地展示。
excerpt_separator
变量。如果将此变量设置为<!--end_excerpt-->
,那么post.excerpt
将包括<!--end_excerpt-->
之前的所有内容,不包括<!--end_excerpt-->
标签本身。---
excerpt_separator: <!--end_excerpt-->
---
This is included in excerpts.
This is also included in excerpts.
<!--end_excerpt-->
But this is not.
excerpt_separator
而浪费精力,你可以直接在_config.yml
文件中设置它。excerpt_separator: "<!--more-->" # 每篇博客文章的全局摘要分隔符
,然后记得重新启动jekyll本地服务器。所有对config.yml的更改都需要重启才能生效。