2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JekyllのAtomの文字数を制限する

Last updated at Posted at 2019-06-22

フィードに本文全部を含めると長くなりすぎて困る時用。

JekyllのAtom feedはjekyll-feedというgemで生成されています。
基本的にはLiquidでの文字数制限を行います。

フィードのテンプレートファイルはgem本体の中にあるので探して編集します。

$ gem environment

で場所を教えてもらえます。
私の環境の場合は「GEM PATHS:」の一番上のディレクトリにありました。

feed.xmlを編集します。
文字数制限にはtruncateまたはtruncatewordsが使えます。
日本語の場合はtruncateの方が手っ取り早いでしょう。

{% raw %}{{ post.content | strip | xml_escape | truncate: 100, "..." }}{% endraw %}

100 の部分はお好みで。

編集には管理者権限が必要な場合があります。
また、アップデートの度にやり直しなので面倒ですが仕方ありません。

※こちらの記事はブログからの移転です。2017年6月6日初出。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?