这可能是一个简单的问题,但如何在默认页面上显示我的帖子的预览?我正在使用Jekyll Bootstrap主题Tom.
Tal*_*876 47
通过这里的函数,我找到了strip_html和truncatewords.
这是一个包含75个预览文字的"帖子列表"示例.
<ul >
{% for post in site.posts limit 4 %}
<li><span>{{ post.date | date_to_string }}</span> » <a href="{{ BASE_PATH }}{{ post.url }}">{{ post.title }}</a></li>
{{ post.content | strip_html | truncatewords:75}}<br>
<a href="{{ post.url }}">Read more...</a><br><br>
{% endfor %}
</ul>
Run Code Online (Sandbox Code Playgroud)
kmi*_*ael 45
这也至少可以用于1.0.0,内置并且易于使用.
<ul>
{% for post in site.posts %}
<li>
<a href="{{ post.url }}">{{ post.title }}</a>
<p>{{ post.excerpt }}</p>
</li>
{% endfor %}
</ul>
Run Code Online (Sandbox Code Playgroud)
看到这里.
mat*_*b33 14
我喜欢<!--more-->WordPress 的评论方法,所以我写了一些东西:
module More
def more(input, type)
if input.include? "<!--more-->"
if type == "excerpt"
input.split("<!--more-->").first
elsif type == "remaining"
input.split("<!--more-->").last
else
input
end
else
input
end
end
end
Liquid::Template.register_filter(More)
Run Code Online (Sandbox Code Playgroud)
你的帖子看起来像这样:
---
layout: post
title: "Your post title"
published: true
---
<p>This is the excerpt.</p>
<!--more-->
<p>This is the remainder of the post.</p>
Run Code Online (Sandbox Code Playgroud)
然后,您可以在模板中使用它,如下所示:
<!--more-->评论上方的所有内容):<summary>{{ post.content | more: "excerpt" }}</summary>
Run Code Online (Sandbox Code Playgroud)
<!--more-->评论后的所有内容):<article>{{ post.content | more: "remaining" }}</article>
Run Code Online (Sandbox Code Playgroud)
除了excerpt或remaining将只显示整个帖子的任何论点.
| 归档时间: |
|
| 查看次数: |
14720 次 |
| 最近记录: |