code.gitea.io/gitea@v1.21.7/web_src/js/features/emoji.js (about) 1 import emojis from '../../../assets/emoji.json'; 2 3 const {assetUrlPrefix, customEmojis} = window.config; 4 5 const tempMap = {...customEmojis}; 6 for (const {emoji, aliases} of emojis) { 7 for (const alias of aliases || []) { 8 tempMap[alias] = emoji; 9 } 10 } 11 12 export const emojiKeys = Object.keys(tempMap).sort((a, b) => { 13 if (a === '+1' || a === '-1') return -1; 14 if (b === '+1' || b === '-1') return 1; 15 return a.localeCompare(b); 16 }); 17 18 const emojiMap = {}; 19 for (const key of emojiKeys) { 20 emojiMap[key] = tempMap[key]; 21 } 22 23 // retrieve HTML for given emoji name 24 export function emojiHTML(name) { 25 let inner; 26 if (Object.hasOwn(customEmojis, name)) { 27 inner = `<img alt=":${name}:" src="${assetUrlPrefix}/img/emoji/${name}.png">`; 28 } else { 29 inner = emojiString(name); 30 } 31 32 return `<span class="emoji" title=":${name}:">${inner}</span>`; 33 } 34 35 // retrieve string for given emoji name 36 export function emojiString(name) { 37 return emojiMap[name] || `:${name}:`; 38 }