Skip to content

Commit

Permalink
feat: make post description customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
kungfux committed Mar 15, 2024
1 parent 0f8e782 commit b0f142a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 13 deletions.
11 changes: 11 additions & 0 deletions _includes/post-description.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% comment %}
Get post description or generate it from the post content.
{% endcomment %}

{% assign max_length = include.max_length | default: 200 %}
{% if post.description %}
{{ post.description | strip | truncate: max_length | escape }}
{% else %}
{% include no-linenos.html content=post.content %}
{{ content | markdownify | strip_html | truncate: max_length | escape }}
{% endif %}
3 changes: 1 addition & 2 deletions _includes/related-posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ <h3 class="mb-4" id="related-label">
<h4 class="pt-0 my-2">{{ post.title }}</h4>
<div class="text-muted">
<p>
{% include no-linenos.html content=post.content %}
{{ content | markdownify | strip_html | truncate: 200 | escape }}
{% include post-description.html max_length=200 %}
</p>
</div>
</div>
Expand Down
4 changes: 1 addition & 3 deletions _layouts/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
layout: default
refactor: true
---

{% include lang.html %}

{% assign pinned = site.posts | where: 'pin', 'true' %}
Expand Down Expand Up @@ -73,8 +72,7 @@ <h1 class="card-title my-2 mt-md-0">{{ post.title }}</h1>

<div class="card-text content mt-0 mb-3">
<p>
{% include no-linenos.html content=post.content %}
{{ content | markdownify | strip_html | truncate: 200 | escape }}
{% include post-description.html max_length=300 %}
</p>
</div>

Expand Down
1 change: 1 addition & 0 deletions _posts/2019-08-08-text-and-typography.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Text and Typography
description: See markdown syntax rendering on Chirpy, so you can use it as an example of writing.
author: cotes
date: 2019-08-08 11:33:00 +0800
categories: [Blogging, Demo]
Expand Down
12 changes: 12 additions & 0 deletions _posts/2019-08-08-write-a-new-post.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Writing a New Post
description: This tutorial will guide you how to write a post in the Chirpy template.
author: cotes
date: 2019-08-08 14:10:00 +0800
categories: [Blogging, Tutorial]
Expand Down Expand Up @@ -73,6 +74,17 @@ Having said that, the key `author` can also identify multiple entries.
> 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.
{: .prompt-info }

### Post description

The `description` field is optional. If it isn't defined, 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:

```yaml
---
title: Post title
description: Short summary of the post
---
```

## Table of Contents

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/):
Expand Down
1 change: 1 addition & 0 deletions _posts/2019-08-09-getting-started.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Getting Started
description: A quick start guide to help you get started with Chirpy.
author: cotes
date: 2019-08-09 20:55:00 +0800
categories: [Blogging, Tutorial]
Expand Down
1 change: 1 addition & 0 deletions _posts/2019-08-11-customize-the-favicon.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Customize the Favicon
description: How to customize the favicon of Chirpy.
author: cotes
date: 2019-08-11 00:34:00 +0800
categories: [Blogging, Tutorial]
Expand Down
15 changes: 7 additions & 8 deletions assets/feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ permalink: /feed.xml
{% endfor %}
{% endif %}

{% if post.summary %}
<summary>{{ post.summary | strip }}</summary>
{% else %}
<summary>
{% include no-linenos.html content=post.content %}
{{ content | strip_html | truncate: 400 }}
</summary>
{% endif %}
<summary>
{% if post.summary %}
{{ post.summary | strip | truncate: 1000 }}
{% else %}
{% include post-description.html max_length=1000 %}
{% endif %}
</summary>

</entry>
{% endfor %}
Expand Down

0 comments on commit b0f142a

Please sign in to comment.