Skip to content

Commit f865336

Browse files
kungfuxcotes2020
andauthored
feat: make post description customizable (cotes2020#1602)
--------- Co-authored-by: Cotes Chung <[email protected]>
1 parent 0f8e782 commit f865336

10 files changed

+58
-29
lines changed

_data/origin/cors.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cdns:
1313

1414
# fonts
1515

16-
webfonts: https://fonts.googleapis.com/css2?family=Lato&family=Source+Sans+Pro:wght@400;600;700;900&display=swap
16+
webfonts: https://fonts.googleapis.com/css2?family=Lato:wght@300;400&family=Source+Sans+Pro:wght@400;600;700;900&display=swap
1717

1818
# Libraries
1919

_includes/post-description.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{%- comment -%}
2+
Get post description or generate it from the post content.
3+
{%- endcomment -%}
4+
5+
{%- assign max_length = include.max_length | default: 200 -%}
6+
7+
{%- capture description -%}
8+
{%- if post.description -%}
9+
{{- post.description -}}
10+
{%- else -%}
11+
{%- include no-linenos.html content=post.content -%}
12+
{{- content | markdownify | strip_html -}}
13+
{%- endif -%}
14+
{%- endcapture -%}
15+
16+
{{- description | strip | truncate: max_length | escape -}}

_includes/related-posts.html

+1-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ <h3 class="mb-4" id="related-label">
8181
{% include datetime.html date=post.date lang=include.lang %}
8282
<h4 class="pt-0 my-2">{{ post.title }}</h4>
8383
<div class="text-muted">
84-
<p>
85-
{% include no-linenos.html content=post.content %}
86-
{{ content | markdownify | strip_html | truncate: 200 | escape }}
87-
</p>
84+
<p>{% include post-description.html %}</p>
8885
</div>
8986
</div>
9087
</a>

_layouts/home.html

+1-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@
7272
<h1 class="card-title my-2 mt-md-0">{{ post.title }}</h1>
7373

7474
<div class="card-text content mt-0 mb-3">
75-
<p>
76-
{% include no-linenos.html content=post.content %}
77-
{{ content | markdownify | strip_html | truncate: 200 | escape }}
78-
</p>
75+
<p>{% include post-description.html %}</p>
7976
</div>
8077

8178
<div class="post-meta flex-grow-1 d-flex align-items-end">

_layouts/post.html

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<article class="px-1">
1515
<header>
1616
<h1 data-toc-skip>{{ page.title }}</h1>
17+
{% if page.description %}
18+
<p class="post-desc fw-light mb-4">{{ page.description }}</p>
19+
{% endif %}
1720

1821
<div class="post-meta text-muted">
1922
<!-- published date -->

_posts/2019-08-08-text-and-typography.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: Text and Typography
3+
description: Examples of text, typography, math equations, diagrams, flowcharts, pictures, videos, and more.
34
author: cotes
45
date: 2019-08-08 11:33:00 +0800
56
categories: [Blogging, Demo]
@@ -13,8 +14,6 @@ image:
1314
alt: Responsive rendering of Chirpy theme on multiple devices.
1415
---
1516

16-
This post is to show Markdown syntax rendering on [**Chirpy**](https://github.com/cotes2020/jekyll-theme-chirpy/fork), you can also use it as an example of writing. Now, let's start looking at text and typography.
17-
1817
## Headings
1918

2019
<!-- markdownlint-capture -->

_posts/2019-08-08-write-a-new-post.md

+12
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ Having said that, the key `author` can also identify multiple entries.
7373
> The benefit of reading the author information from the file `_data/authors.yml`{: .filepath } is that the page will have the meta tag `twitter:creator`, which enriches the [Twitter Cards](https://developer.twitter.com/en/docs/twitter-for-websites/cards/guides/getting-started#card-and-content-attribution) and is good for SEO.
7474
{: .prompt-info }
7575

76+
### Post Description
77+
78+
By default, the first words of the post are used to display on the home page for a list of posts, in the _Further Reading_ section, and in the XML of the RSS feed. If you don't want to display the auto-generated description for the post, you can customize it using the `description` field in the _Front Matter_ as follows:
79+
80+
```yaml
81+
---
82+
description: Short summary of the post.
83+
---
84+
```
85+
86+
Additionally, the `description` text will also be displayed under the post title on the post's page.
87+
7688
## Table of Contents
7789

7890
By default, the **T**able **o**f **C**ontents (TOC) is displayed on the right panel of the post. If you want to turn it off globally, go to `_config.yml`{: .filepath} and set the value of variable `toc` to `false`. If you want to turn off TOC for a specific post, add the following to the post's [Front Matter](https://jekyllrb.com/docs/front-matter/):

_posts/2019-08-09-getting-started.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
---
22
title: Getting Started
3+
description: >-
4+
Get started with Chirpy basics in this comprehensive overview.
5+
You will learn how to install, configure, and use your first Chirpy-based website, as well as deploy it to a web server.
36
author: cotes
47
date: 2019-08-09 20:55:00 +0800
58
categories: [Blogging, Tutorial]

_sass/layout/post.scss

+19-10
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,28 @@
1414
padding-right: $pr;
1515
}
1616

17-
h1 + .post-meta {
18-
span + span::before {
19-
@include dot;
20-
}
17+
header {
18+
.post-desc {
19+
@extend %heading;
2120

22-
em,
23-
time {
24-
@extend %text-highlight;
21+
font-size: 1.125rem;
22+
line-height: 1.6;
2523
}
2624

27-
em {
28-
a {
29-
color: inherit;
25+
.post-meta {
26+
span + span::before {
27+
@include dot;
28+
}
29+
30+
em,
31+
time {
32+
@extend %text-highlight;
33+
}
34+
35+
em {
36+
a {
37+
color: inherit;
38+
}
3039
}
3140
}
3241
}

assets/feed.xml

+1-8
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,7 @@ permalink: /feed.xml
4545
{% endfor %}
4646
{% endif %}
4747

48-
{% if post.summary %}
49-
<summary>{{ post.summary | strip }}</summary>
50-
{% else %}
51-
<summary>
52-
{% include no-linenos.html content=post.content %}
53-
{{ content | strip_html | truncate: 400 }}
54-
</summary>
55-
{% endif %}
48+
<summary>{% include post-description.html max_length=400 %}</summary>
5649

5750
</entry>
5851
{% endfor %}

0 commit comments

Comments
 (0)