2022-12-10 12:14:48 +03:00
|
|
|
function emojifyText(text, emojis = []) {
|
2023-01-28 13:52:18 +03:00
|
|
|
if (!text) return '';
|
2022-12-10 12:14:48 +03:00
|
|
|
if (!emojis.length) return text;
|
2023-06-14 12:37:41 +03:00
|
|
|
if (text.indexOf(':') === -1) return text;
|
2022-12-10 12:14:48 +03:00
|
|
|
// Replace shortcodes in text with emoji
|
|
|
|
// emojis = [{ shortcode: 'smile', url: 'https://example.com/emoji.png' }]
|
|
|
|
emojis.forEach((emoji) => {
|
|
|
|
const { shortcode, staticUrl, url } = emoji;
|
|
|
|
text = text.replace(
|
|
|
|
new RegExp(`:${shortcode}:`, 'g'),
|
2023-06-14 12:37:41 +03:00
|
|
|
`<img class="shortcode-emoji emoji" src="${url}" alt=":${shortcode}:" width="12" height="12" loading="lazy" decoding="async" />`,
|
2022-12-10 12:14:48 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
// console.log(text, emojis);
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default emojifyText;
|