Showing a snippet of the content in a topic
-
Is there a variable I could use to call {topic.content} but the first 140 char or so? That would look pretty neat if you do it right.
-
can you truncate?
var truncateStr = function (str, len) { if (typeof str != 'string') return str; len = isNumber(len) && len > 3 ? len : 140; return str.length <= len ? str : str.substr(0, len - 3) + '...'; }; var isNumber = function ( nb ) { return !isNaN( parseFloat ( nb ) ) && isFinite( nb ); };
-
The crappy part is you might accidentally truncate in the middle of HTML, or worst yet...:
140 chars:
this is my post with some styling included, because that's how I roll. Check it out, here is some <b>bolded text! See what happens when I k
... and then suddenly the rest of the posts are bolded
-
perhaps your snippet can disclude html tags. didn't we do something like this for the teaser text on the cat view? what exactly are you trying to do, maybe I can help
-
140 smells like twitter, I think @psychobunny is right, exclude html tags, or sanitize, then truncate.
Probably should truncate by words too, not chars. -
Okay 255. Let's be unique here...
Copyright © 2024 NodeBB | Contributors