How to get excerpts?

2 views
Skip to first unread message

Hartmut Goebel

unread,
Jun 13, 2024, 8:37:39 AMJun 13
to nikola-discuss

Hi,

for the post list of my most recent blog posts, I want to get the "excerpt" of the post.

post_helper.tmpl already contains this code:

%if post.description():
    <meta property="og:description" content="${post.description()[:200]|h}">
%else:
    <meta property="og:description" content="${post.text(strip_html=True)[:200]|h}">
%endif

Anyhow, I want a more sophisticated version:

  • inline-markup within the text shall be rendered to html
  • the text should contain terminate if there is a paragraph ending within
  • the text should not be cut within words but only between words
  • if within the last about 50 characters there is a period, comma, colon, semi-colon. this should be used to terminate the excerpt.

Anyone already implemented this? Or any other hints how to implement this?

-- 
Regards
Hartmut Goebel

| Hartmut Goebel          | h.go...@crazy-compilers.com               |
| www.crazy-compilers.com | compilers which you thought are impossible |

Chris Warrick

unread,
Jun 13, 2024, 3:50:14 PMJun 13
to nikola-...@googlegroups.com
Hi,

Nikola supports user-defined teasers:
https://getnikola.com/handbook.html#teasers . You can render them in
templates using ${post.text(teaser_only=True)}.
If you want things to look good (and you seem to have a lot of rules),
manually picking the best place to break the text is the best way.

--
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16
Reply all
Reply to author
Forward
0 new messages