From 7ba31a6b928f3c9c9e88d79f39ea9846ce0f49ae Mon Sep 17 00:00:00 2001 From: OFF0 Date: Fri, 9 Dec 2022 11:51:08 +0100 Subject: [PATCH] feed: reduce and censor content that has many newlines Render newlines as linebreaks is nice, but it can be abused by adding too many newlines. This change reduces 3 newlines to 2 globally to keep the output somewhat sane. --- src/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index 46e5c08..0103140 100644 --- a/src/main.js +++ b/src/main.js @@ -156,7 +156,7 @@ setInterval(() => { function createTextNote(evt, relay) { const {host, img, isReply, name, replies, time, userName} = getMetadata(evt, relay); const isLongContent = evt.content.trimRight().length > 280; - const content = isLongContent ? evt.content.slice(0, 280) : evt.content; + const content = (isLongContent ? evt.content.slice(0, 280) : evt.content).replaceAll(/\n{3,}/g, '\n\n'); const hasReactions = reactionMap[evt.id]?.length > 0; const didReact = hasReactions && !!reactionMap[evt.id].find(reaction => reaction.pubkey === pubkey); const replyFeed = replies[0] ? replies.map(e => replyDomMap[e.id] = createTextNote(e, relay)) : [];