Skip to content

Commit 48f81aa

Browse files
committed
feat(posts): add prioritized post summaries for home page
✨ Add concise, prioritized summaries for posts on the home page to avoid leaking large code blocks or overly long content in the index. 📁 Modified: index.html, README.md 📝 Document recommended front-matter usage and added a README section with examples and a nav entry for the new feature 💡 Behavior: prefer front-matter summary/description, then the first rendered paragraph (skipping headings/code), then Jekyll excerpt or stripped content as a fallback
1 parent 7b99f6c commit 48f81aa

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,39 @@ bundle exec jekyll serve --host=localhost --livereload
9292
```
9393

9494

95+
## Post summaries (home page excerpts)
96+
97+
The home page now shows a concise summary for each post without leaking large code blocks.
98+
99+
Summary priority (no changes needed to old posts):
100+
101+
1. If a post defines `summary:` (or `description:`) in front matter, that is used.
102+
2. Otherwise the first real paragraph from the post body is extracted and truncated.
103+
3. If no paragraph is found, it falls back to Jekyll's excerpt or stripped content.
104+
105+
Recommended usage for new posts:
106+
107+
```yaml
108+
---
109+
layout: post
110+
title: My Post
111+
date: 2025-08-27
112+
summary: A one‑sentence teaser for the home page list.
113+
---
114+
115+
Intro paragraph here…
116+
117+
<!--more-->
118+
119+
Rest of the content…
120+
```
121+
122+
Notes:
123+
- `summary:` gives you full control over the home-page blurb.
124+
- `<!--more-->` is optional; use it when you want the per‑post page to show a short intro before the rest.
125+
- Old posts don’t need to be edited. They’ll automatically use their first paragraph.
126+
127+
95128

96129
## SEO Improvements
97130

@@ -170,6 +203,7 @@ It is a brazen two-column theme that pairs a prominent sidebar with uncomplicat
170203
- [Live reload](#live-reload)
171204
- [Testing imgur hosted images](#testing-imgur-hosted-images)
172205
- [Current full site testing example:](#current-full-site-testing-example)
206+
- [Post summaries (home page excerpts)](#post-summaries-home-page-excerpts)
173207
- [SEO Improvements](#seo-improvements)
174208
- [Canonical URL](#canonical-url)
175209
- [Robots Tag](#robots-tag)

index.html

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,34 @@ <h1 class="post-title">
1414

1515
<span class="post-date">{{ post.date | date_to_string }}</span>
1616

17-
<p>{{ post.content | strip_html | truncatewords:75}}</p>
17+
{%- comment -%}
18+
Summary priority:
19+
1) front matter: summary/description
20+
2) first actual paragraph from rendered content (skips headings/code)
21+
3) fallback to excerpt or stripped content
22+
{%- endcomment -%}
23+
24+
{% if post.summary %}
25+
<p>{{ post.summary }}</p>
26+
{% elsif post.description %}
27+
<p>{{ post.description }}</p>
28+
{% else %}
29+
{% assign paragraphs = post.content | split: '</p>' %}
30+
{% assign found_para = false %}
31+
{% for p in paragraphs %}
32+
{% if found_para == false and p contains '<p' %}
33+
{% assign found_para = true %}
34+
<p>{{ p | append: '</p>' | strip_html | truncatewords: 75 }}</p>
35+
{% endif %}
36+
{% endfor %}
37+
{% unless found_para %}
38+
{% if post.excerpt %}
39+
<p>{{ post.excerpt | strip_html | truncatewords: 75 }}</p>
40+
{% else %}
41+
<p>{{ post.content | strip_html | truncatewords: 75 }}</p>
42+
{% endif %}
43+
{% endunless %}
44+
{% endif %}
1845
<p><a href="{{ site.baseurl }}{{ post.url }}">Continue Reading</a></p>
1946

2047

0 commit comments

Comments
 (0)