Using Truncated Output in Jekyll

2013-04-11 12:00Edit this page

Since I had been using WordPress1 before, after switching to Jekyll I naturally wanted to find a way to recognize <!-- more --> for truncating output.

Plugins

After a quick Google search, I found relevant plugins:

However, if your Jekyll is also hosted on GitHub, you can’t use plugins. For security reasons, GitHub runs Jekyll with the --safe parameter, rendering all third-party plugins ineffective.

Liquid

Just when I was feeling a bit disappointed, I found this article: Post excerpts in Jekyll2

You can achieve this using a filter in the Liquid template language:

{{ post.content | split: "<!-- more -->" | first }}

Then add a Read More link after the truncated article:

<a href="#more>Read More →</a>

This way, even Jekyll hosted on GitHub can have truncated output.3

Notes added on 2018-10-10


  1. I vaguely remember setting up a WordPress blog on free PHP hosting during college ↩︎

  2. Unfortunately, this link is no longer working, and I don’t know what exactly I saw through this link back in 2013 ↩︎

  3. Truncating article output on the homepage is not strictly necessary ↩︎

Unless otherwise stated, articles on this blog are licensed under the Creative Commons Attribution 4.0 International License. Please credit the original author and source when sharing.


Tags: archive

No comments yet

Leave a comment

Creative Commons © 2013 — 2026 xiaocang | Theme based on fzheng.me & NexT | Hosted by Netlify