Skip to content

Commit

Permalink
feat: Add configurable excerpt length for home page articles #414
Browse files Browse the repository at this point in the history
- Introduce new `excerpt_length` option in `_config.yml`
- Implement dynamic excerpt truncation based on user-defined length
- Default to 200 characters if not specified
  • Loading branch information
EvanNotFound committed Aug 31, 2024
1 parent a041a3d commit 76a35c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion layout/_partials/home-content.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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}) %>
<% } %>
</div>
Expand Down

0 comments on commit 76a35c1

Please sign in to comment.