これはおそらく簡単な質問ですが、既定のページで投稿のプレビューを表示するにはどうすればよいですか? Jekyll Bootstrap テーマ Tom を使用しています。
15720 次
4 に答える
48
ここで関数を調べると、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>
于 2012-06-15T03:43:58.880 に答える
14
WordPressのコメント アプローチが気に入った<!--more-->
ので、それに沿って何かを書きました。
_plugins/more.rb:
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)
投稿は次のようになります。
---
layout: post
title: "Your post title"
published: true
---
<p>This is the excerpt.</p>
<!--more-->
<p>This is the remainder of the post.</p>
その後、次のようにテンプレートで使用できます。
<!--more-->
抜粋を表示 (コメントの上のすべて):
<summary>{{ post.content | more: "excerpt" }}</summary>
残りを表示 (<!--more-->
コメントの後のすべて):
<article>{{ post.content | more: "remaining" }}</article>
excerpt
or以外の引数remaining
は、単に投稿全体を表示します。
于 2012-11-14T18:01:35.413 に答える
1
これは古い質問ですが、@ Talon876 の回答here で提起されているように、書式設定の問題の回避策を追加したいと考えています。
各投稿の最後に のような終了タグを追加するの</em>,</strong> or </b>
はあまり見栄えがよくないかもしれませんが、抜粋を表示しながらフォーマットを維持します。
例えば:
<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}}
</em></strong> <!-- This is what does the task-->
<br>
<a href="{{ post.url }}">Read more...</a><br><br>
{% endfor %}
</ul>
于 2015-02-22T20:12:01.120 に答える