Search code examples
jekyllliquidjekyll-theme

How can I limit the number of lines shown on the homepage of a Jekyll blog?


In my Jekyll theme, some of my blog posts are shown as it is on the home page. But I want to limit them up to certain lines. That is, I want to show only 5-6 lines of the blog on the home page. For example, enter image description here In,
1. 5 lines of the blog post are visible
2. Only two lines of the blog post are visible
3. In the last post of the page the entire blog post is visible on the homepage.

I am new to Jekyll and I don't know how can I do that. The theme I am using is the earlier version of White Paper


Solution

  • The preview text from each blog posts are from {{ post.excerpt }} in index.html[1]. It looks like the White Paper jekyll theme is using the default behavior of Post excerpts[2].

    By default this is the first paragraph of content in the post, however it can be customized by setting a excerpt_separator variable in front matter or _config.yml.

    If you want to control how much text is previewed for each blog post, you can stop using {{ post.excerpt }} and do something like {{ post.content | truncatewords: 60 }} instead.

    These {{ ... }} code snippets are from the Liquid templating language [3][4]

    [1] https://github.com/vinitkumar/white-paper/blob/3995398d74b42ee70ad2e4c82a0ab8955ad49955/index.html#L10

    [2] https://jekyllrb.com/docs/posts/#post-excerpts

    [3] https://jekyllrb.com/docs/liquid/

    [4] https://shopify.github.io/liquid/