TopShelfCraft / Wordsmith

A plugin for Craft CMS to help you manage and manipulate text.
Other
30 stars 20 forks source link

[FR] Truncate after first sentence #18

Open ademers opened 5 years ago

ademers commented 5 years ago

Add ability to truncate after a field content's first sentence.

For example: {{ entry.body|chop(limit=1, unit='s') }}

Originally discussed in Craft Discord: https://discordapp.com/channels/456442477667418113/456442867163070466/567769332717846548

jalendport commented 5 years ago

Thanks Andrea...

michaelrog commented 5 years ago

Sentence splitting is a bit tricky. What marks the end of a sentence? "Sentence-ending" punctuation isn't always:

"I want a No. 4 cheesyMcMeal w/ fries!" she exclaimed.

It's easier to compute 4! than 5!, but not by much...

Mr. and Mrs. Smith visited Dr. Jones on 5.4.2019.

To make it tight, we'd need to have an internal (extensible) list of common abbreviated words, some rules around numbers/dates/math, affordances for repeated punctuation !???!??, etc.

(As a punt, we could just wrap a component like php-sentence and just let it be known that the corner-case support is super weak... but I'm generally inclined against fragile functionality.)

ademers commented 5 years ago

@michaelrog Indeed. I hadn't considered those scenarios. I was solely thinking of my current scenario which is the first "." period. I can add an extra field instead where author can manually enter the copy, so ignore/close this FR. Thanks!

michaelrog commented 5 years ago

To be clear, I don't think it's necessarily a bad feature request. It's just not trivial to implement.

Gonna leave this open for now in case somebody wants to tackle it.

jalendport commented 5 years ago

Hmm yeah I forgot that we were using our own "library" for truncating text and hastily assumed that whatever we were using had a sentence truncation option that we just hadn't made available. But you did bring up some great and important points that I didn't initially take the time to think through when Andrea first mentioned the idea to me.