Skip to content

Instantly share code, notes, and snippets.

@beryllium
Created November 11, 2022 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beryllium/ac008d5a26c074912842f3dbb61f80e9 to your computer and use it in GitHub Desktop.
Save beryllium/ac008d5a26c074912842f3dbb61f80e9 to your computer and use it in GitHub Desktop.
Sculpin article excerpts

Sculpin Article Excerpts

The Breakaway

This method uses a special string, <!-- break -->, to denote a breakpoint in index.html:

{# Split the post into an array using explode().
   Because we provide a length of 2, the "rest"
   of the post will be stored in the second array
   element, even if there are multiple breakpoints. #}
{% set break_array =
    post.blocks.content|split('<!-- break -->', 2) %}

{# Output the first element of the array in raw mode #}
{{ break_array[0]|raw }}

{# Detect if there is more to the post. If the post
   was only one array element with no breakpoints,
   it would all have shown up. This Read More link should
   only show up if there is overflow to the post. #}
{% if break_array|length > 1 %}
    <div class="my-6"><a href="{{ site.url }}{{ post.url }}" class="p-2 rounded-md hover:bg-gray-500 hover:text-white">
        Read more of this post &raquo;
    </a></div>
{% endif %}

The Excerpt

In the YAML front-matter, specify a custom parameter with an excerpt of text to display instead of the post content blocks.

---
layout: post
title: Who Watches the Watchmen?
date: 2018-02-22 22:59:59
image: img/sculpin-banner.png
tags: [sculpin]
categories: [coding, howto]
summary: "Presenting ideas on how to properly test the --watch parameter to site generation using the Symfony Process Component"
---

Then, in index.html, instead of showing the post content blocks, you would output the summary:

{{ post.summary }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment