mastodon icon indicating copy to clipboard operation
mastodon copied to clipboard

Customisable "too long" post truncation length, based on number of lines AND number of characters

Open naught101 opened this issue 3 years ago • 7 comments

Pitch

Currently some long posts truncate, due to https://github.com/mastodon/mastodon/pull/8205

The example posted at that MR (https://share.elouworld.org/@Exagone313/195324 - 1042 chars, one per line) is truncated to 12 lines. However, there are some long-ish posts (e.g. https://mstdn.social/@Mirella_PhD/109310858624901226, which has a 21 lines and then a long image), which do not get truncated, I guess because they are under 500 characters total.

It would be good to have a user-customisable truncation length, for example:

  • Truncate any post longer than 8 new lines.
  • Truncate any post longer than 300 characters
  • Don't show media on truncated posts

Motivation

These options would help prevent user's timelines from getting clogged up with large posts.

naught101 avatar Nov 09 '22 01:11 naught101

Truncation should ideally be based on max height, not character count

trwnh avatar Nov 09 '22 01:11 trwnh

Yes, but I think that's not possible unless you assume a text width. Although I guess it would be reasonable to assume a fairly narrow text width, like 300px.

naught101 avatar Nov 09 '22 01:11 naught101

Not really, you can do it based on ex units or aspect ratio

trwnh avatar Nov 09 '22 01:11 trwnh

For reference, I this post: image

is 659 characters, 116 words, and 23 lines at about 650px. So about 28 characters per line (it's ~50 characters for the full width lines)

I think my ideal truncation strategy for something like this would be

  • Estimate number of lines, maybe something like nchars / 35? This doesn't need to be too precise
  • If num lines is more than 10 (customisable), truncate to 6 lines (customisable), with a "read more" link.

naught101 avatar Nov 09 '22 01:11 naught101

It shouldn't be based on character count at all, because you can do things

l
i
k
e

t
h
i
s

The optimal strategy is to limit the max-height based on ex or aspect ratio

trwnh avatar Nov 09 '22 01:11 trwnh

OK, but it needs to be both, because of line wrapping. In your example, you get 9 lines with 9 characters, but I can also get 9 lines just by writing 400ish characters, and some instances allow 1000+ characters, which can easily get you up to 30+ lines with only a few line breaks.

naught101 avatar Nov 09 '22 05:11 naught101

Yes, so you apply a max-height using ex units or otherwise calculating an aspect ratio using Javascript. What matters is line height -- that's why I'm suggesting ex.

trwnh avatar Nov 09 '22 05:11 trwnh

Giving the user the control on line-clamp could be also a solution to manage the content height:

display: -webkit-box;
overflow: hidden;
-webkit-line-clamp: 4;
-webkit-box-orient: vertical;

idotj avatar Jan 10 '23 21:01 idotj

Also compare with #20188 "Option to disable external link previews". Perhaps the collapsed version of he post could show the link without the preview.

nielsle avatar Feb 03 '24 17:02 nielsle