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 b6c8674205f..614139f8e37 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 00000000000..6c400360bf3 --- /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 1ba2f322008..ae39da41f17 100644 --- a/_includes/related-posts.html +++ b/_includes/related-posts.html @@ -81,10 +81,7 @@

{{ 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 4cf4c1d5d99..a9f5bd366a7 100644 --- a/_layouts/home.html +++ b/_layouts/home.html @@ -72,10 +72,7 @@

{{ 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 f666d71642c..f17ceea8641 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -14,6 +14,9 @@

{{ page.title }}

+ {% if page.description %} +

{{ page.description }}

+ {% endif %}