From 76a35c1a4d09b78e11ba6c4d5542ce999f325662 Mon Sep 17 00:00:00 2001 From: Evan Luo Date: Sat, 31 Aug 2024 15:46:18 -0400 Subject: [PATCH] feat: Add configurable excerpt length for home page articles #414 - Introduce new `excerpt_length` option in `_config.yml` - Implement dynamic excerpt truncation based on user-defined length - Default to 200 characters if not specified --- _config.yml | 2 ++ layout/_partials/home-content.ejs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index 32e88eaf..6b50479e 100755 --- a/_config.yml +++ b/_config.yml @@ -249,6 +249,8 @@ home: # ...... # you can add more # Article date format article_date_format: auto # auto, relative, YYYY-MM-DD, YYYY-MM-DD HH:mm:ss etc. + # Article excerpt length + excerpt_length: 200 # Max length of article excerpt # Article categories visibility categories: enable: true # Whether to enable diff --git a/layout/_partials/home-content.ejs b/layout/_partials/home-content.ejs index 89591760..a349008e 100755 --- a/layout/_partials/home-content.ejs +++ b/layout/_partials/home-content.ejs @@ -43,7 +43,10 @@ <% } else if (post.excerpt && post.excerpt !== "false") { %> <%- render(post.excerpt, "markdown") %> <% } else { %> - <%- truncate(strip_html(post.content), {length: 300}) %> + <% + const excerptLength = theme.home.excerpt_length || 200; + %> + <%- truncate(strip_html(post.content), {length: excerptLength}) %> <% } %>