fix og error ( truncated unicode character ) - closes #6839

This commit is contained in:
Baltazar Gomez 2021-08-10 12:04:58 -05:00 committed by Thomas Zarebczan
parent 7312badc18
commit 017ec11737

View file

@ -41,8 +41,13 @@ function insertToHead(fullHtml, htmlToInsert) {
}
}
function truncateDescription(description) {
return description.length > 200 ? description.substr(0, 200) + '...' : description;
function truncateDescription(description, maxChars=200) {
// Get list of single-codepoint strings
const chars = [...description];
// Use slice array instead of substring to prevent breaking emojis
let truncated = chars.slice(0, maxChars).join('');
// Format truncated string
return (chars.length <= maxChars) ? truncated : truncated + "..." ;
}
function normalizeClaimUrl(url) {