From f865336c896e0db34edf8482a53e0e5d8f07ff95 Mon Sep 17 00:00:00 2001 From: Alexander Fuks Date: Mon, 18 Mar 2024 14:50:05 +0400 Subject: [PATCH] feat: make post description customizable (#1602) --------- Co-authored-by: Cotes Chung <11371340+cotes2020@users.noreply.github.com> --- _data/origin/cors.yml | 2 +- _includes/post-description.html | 16 +++++++++++++ _includes/related-posts.html | 5 +--- _layouts/home.html | 5 +--- _layouts/post.html | 3 +++ _posts/2019-08-08-text-and-typography.md | 3 +-- _posts/2019-08-08-write-a-new-post.md | 12 ++++++++++ _posts/2019-08-09-getting-started.md | 3 +++ _sass/layout/post.scss | 29 ++++++++++++++++-------- assets/feed.xml | 9 +------- 10 files changed, 58 insertions(+), 29 deletions(-) create mode 100644 _includes/post-description.html diff --git a/_data/origin/cors.yml b/_data/origin/cors.yml index b6c8674..614139f 100644 --- a/_data/origin/cors.yml +++ b/_data/origin/cors.yml @@ -13,7 +13,7 @@ cdns: # fonts -webfonts: https://fonts.googleapis.com/css2?family=Lato&family=Source+Sans+Pro:wght@400;600;700;900&display=swap +webfonts: https://fonts.googleapis.com/css2?family=Lato:wght@300;400&family=Source+Sans+Pro:wght@400;600;700;900&display=swap # Libraries diff --git a/_includes/post-description.html b/_includes/post-description.html new file mode 100644 index 0000000..6c40036 --- /dev/null +++ b/_includes/post-description.html @@ -0,0 +1,16 @@ +{%- comment -%} + Get post description or generate it from the post content. +{%- endcomment -%} + +{%- assign max_length = include.max_length | default: 200 -%} + +{%- capture description -%} +{%- if post.description -%} + {{- post.description -}} +{%- else -%} + {%- include no-linenos.html content=post.content -%} + {{- content | markdownify | strip_html -}} +{%- endif -%} +{%- endcapture -%} + +{{- description | strip | truncate: max_length | escape -}} diff --git a/_includes/related-posts.html b/_includes/related-posts.html index 1ba2f32..ae39da4 100644 --- a/_includes/related-posts.html +++ b/_includes/related-posts.html @@ -81,10 +81,7 @@ {% include datetime.html date=post.date lang=include.lang %}

{{ post.title }}

-

- {% include no-linenos.html content=post.content %} - {{ content | markdownify | strip_html | truncate: 200 | escape }} -

+

{% include post-description.html %}

diff --git a/_layouts/home.html b/_layouts/home.html index 4cf4c1d..a9f5bd3 100644 --- a/_layouts/home.html +++ b/_layouts/home.html @@ -72,10 +72,7 @@ refactor: true

{{ post.title }}

-

- {% include no-linenos.html content=post.content %} - {{ content | markdownify | strip_html | truncate: 200 | escape }} -

+

{% include post-description.html %}

diff --git a/_layouts/post.html b/_layouts/post.html index f666d71..f17ceea 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -14,6 +14,9 @@ tail_includes:

{{ page.title }}

+ {% if page.description %} +

{{ page.description }}

+ {% endif %}