Truncate Posts on Multiple Post Landing Page?

Hi Adam, thanks so much for the new features and your video about it. It helps so much. Of course new features lead to even more feature requests :innocent: Have you considered implementing some sort of truncate feature, so that with a given post length it gets truncated and only a ā€œteaserā€ is shown on the landing pages?

2 Likes

I will add that over the weekend, no problem!

2 Likes

I’m just chiming in to mention that I added something like this with custom metadata using a ā€œsummaryā€ and outputting it in the config for post-list. I don’t know what your naming convention will be and am curious if there could be: a) an automated one with a name like ā€œteaserā€, and/or b) a custom one like ā€œsummaryā€, or some way to differentiate (with fallback if the custom one isn’t provided). Also want to make sure my current implementation doesn’t collide with any new naming convention. You can check out what I did here on my archive (this uses post-list with the added summary var): Apple Annie’s Weblog Ā· Archive

Edit: adding that maybe a marker like ā€œ===ā€œ in the post could be where a teaser ends and gets stripped in the Markdown and everything after is the body. Just an idea.

1 Like

Love your setup! I don’t think there will be any risk of conflict because I’ll set this up as a configuration item—something similar to the existing Titleless title length item (introduced here), which can accept a value of n words or n characters. Then there’s Truncation appendix which is what will appear at the end of a truncated chunk of text (if it was in fact truncated).

But I really like the idea of managing this within each post—the marker idea is interesting! Might also try something like an HTML comment for that, e.g. <!-- summary -->. Not sure; open to input!

1 Like

I’m wondering too about interplay with existing solutions. I’ve something similar with a custom Excerpt front matter that I call with $excerpt in post listings.

Thinking out loud with no idea of what would be involved I’m wondering how complicated it would be to suss out a way for people with custom solves for this to use a built-in as a fallback.

Maybe not for soon but for later, a way to say in our format snippets some equivalent of the logic (in my case) a configuration settings like

Teaser override: excerpt (or whatever someone’s used as a custom front matter)

and then in my templates I’d change anywhere I have {excerpt} to {teaser} which because of the above would output the new teaser if I hadn’t added any Excerpt: front matter, but still output any manual excerpt for posts where I’d added that custom front matter.

1 Like

Truncation has been added — keeping it pretty simple for now. There is now a Landing page post length configuration item, which can be set to values like 80 characters or 45 words. It will apply to landing page posts only when Landing page post count is set to a value greater than 1. It’ll also append the Truncation appendix value to any truncated post bodies.

1 Like

This is and works perfectly fine. Thanks again @adam !

1 Like

BTW not sure what other people might think about it but maybe it would be a nice touch if the # title of an truncated post on the multiple post landing page would convert into a link to the full post as the date stamp does right now? And there is a small glitch with truncation that kicks in in the middle of a md link. Not sure if the truncation should kick in before or after or as it is right not just as defined …

1 Like

The title link is a neat idea — let me see what I can do about that. As for the glitch you caught, that’s a super tricky problem… the kind that leaves me with a knot in my stomach. It’s easy for me to truncate a string after a certain number of words or characters, but it’s not easy to do it in a way that avoids things like HTML, Markdown, or other scenarios where you don’t want the text to be truncated in that particular spot. :confused:

So, I’ll need to think about what I can do to mitigate that. This may be a simple case where automated truncation is just not the right solution to the problem. Might be that creating teasers or predefined excerpts is the way to go for maximum control.

However, one idea that just came to mind would be to convert the source Markdown text to HTML first, then strip all HTML tags, and then truncate that stripped string. That should eliminate the conflict with both Markdown and HTML, but it comes at the cost of losing all formatting on your truncated post bodies. Do you think that’s an acceptable tradeoff? (Personally, I’m not sure…)

1 Like

Personally, I think losing all formatting on every truncated post would be much worse than displaying a broken md or html formatting occasionally. As I am no programmer at all, I can not estimate how hard it would be just to check the last ā€œsentenceā€ after truncation was performed for not closed md and html tags and just strip them? In the long run I think it would be fine, to have this dump cut off after xxx words and in addition, as discussed above, some sort of placeholder / tag that allows to set the position manually. That way everyone could easily fix this by inserting the tag where it is needed or wanted.

1 Like