mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-12-24 03:08:13 +03:00
16 lines
552 B
JavaScript
16 lines
552 B
JavaScript
function emojifyText(text, emojis = []) {
|
|
if (!emojis.length) return text;
|
|
// 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'),
|
|
`<img class="shortcode-emoji emoji" src="${url}" alt=":${shortcode}:" width="12" height="12" loading="lazy" />`,
|
|
);
|
|
});
|
|
// console.log(text, emojis);
|
|
return text;
|
|
}
|
|
|
|
export default emojifyText;
|