diff --git a/_includes/post-description.html b/_includes/post-description.html deleted file mode 100644 index 48bb03b76eb..00000000000 --- a/_includes/post-description.html +++ /dev/null @@ -1,30 +0,0 @@ -{%- comment -%} - Get post description or generate it from the post content. -{%- endcomment -%} - -{%- capture description -%} - {%- if post.description -%} - {{- post.description -}} - {%- else -%} - {% comment %} - Remove the line number of the code snippet. - {% endcomment %} - {%- assign content = post.content -%} - - {%- if content contains '
' -%}
- {%- assign content = content | replace: '', '' -%}
- {%- endif -%}
-
- {{- content | strip_html | newline_to_br | replace: '
', ' ' | strip_newlines -}}
- {%- endif -%}
-{%- endcapture -%}
-
-{%- if include.json -%}
- {%- assign description = description | jsonify -%}
-{%- else -%}
- {%- assign max_length = include.max_length | default: 200 -%}
- {%- assign description = description | strip | truncate: max_length -%}
-{%- endif -%}
-
-{{- description -}}
diff --git a/_includes/post-summary.html b/_includes/post-summary.html
new file mode 100644
index 00000000000..c9314fc812a
--- /dev/null
+++ b/_includes/post-summary.html
@@ -0,0 +1,39 @@
+{%- comment -%}
+ Get the post's description or body content.
+
+ Arguments:
+ full_text: If true, return the full content. Default is false.
+ max_length: The maximum length of the returned content. Default is 200.
+{%- endcomment -%}
+
+{%- if post.description and include.full_text != true -%}
+ {{- post.description -}}
+{%- else -%}
+ {%- comment -%} Remove the line numbers from the code snippet. {%- endcomment -%}
+
+ {%- assign content = post.content -%}
+
+ {%- if content contains ' ' -%}
+ {%- assign content = content
+ | replace: '',
+ '' -%}
+ {%- endif -%}
+
+ {%- assign content = content
+ | markdownify
+ | strip_html
+ | newline_to_br
+ | replace: '
', ' '
+ | strip_newlines
+ | strip
+ -%}
+
+ {%- unless include.full_text -%}
+ {%- assign max_length = include.max_length | default: 200 -%}
+ {%- assign content = content | truncate: max_length -%}
+ {%- endunless -%}
+
+ {{- content -}}
+{%- endif -%}
diff --git a/_includes/related-posts.html b/_includes/related-posts.html
index 37a295bdc29..4b4f8088a0c 100644
--- a/_includes/related-posts.html
+++ b/_includes/related-posts.html
@@ -82,7 +82,7 @@
{% include datetime.html date=post.date lang=include.lang %}
{{ post.title }}
- {% include post-description.html %}
+ {% include post-summary.html %}
diff --git a/_layouts/home.html b/_layouts/home.html
index 66a12012f49..cb9ab244d48 100644
--- a/_layouts/home.html
+++ b/_layouts/home.html
@@ -78,7 +78,7 @@
{{ post.title }}
- {% include post-description.html %}
+ {% include post-summary.html %}