logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

emoji_merger.js (2017B)


  1. /*
  2. Emoji merger script, quick hack of a tool to:
  3. - update some missing emoji from an external source
  4. - sort the emoji
  5. - remove all multipart emoji (reactions don't allow them)
  6. Merges emoji from here: https://gist.github.com/oliveratgithub/0bf11a9aff0d6da7b46f1490f86a71eb
  7. to the simpler format we're using.
  8. */
  9. // Existing emojis we have
  10. const oldEmojiFilename = '../static/emoji.json'
  11. // The file downloaded from https://gist.github.com/oliveratgithub/0bf11a9aff0d6da7b46f1490f86a71eb
  12. const newEmojiFilename = 'emojis.json'
  13. // Output, replace the static/emoji.json with this file if it looks correct
  14. const outputFilename = 'output.json'
  15. const run = () => {
  16. const fs = require('fs')
  17. let newEmojisObject = {}
  18. let emojisObject = {}
  19. let data = fs.readFileSync(newEmojiFilename, 'utf8')
  20. // First filter out anything that's more than one codepoint
  21. const newEmojis = JSON.parse(data).emojis.filter(e => e.emoji.length <= 2)
  22. // Create a table with format { shortname: emoji }, remove the :
  23. newEmojis.forEach(e => {
  24. const name = e.shortname.slice(1, e.shortname.length - 1).toLowerCase()
  25. if (name.length > 0) {
  26. newEmojisObject[name] = e.emoji
  27. }
  28. })
  29. data = fs.readFileSync(oldEmojiFilename, 'utf8')
  30. emojisObject = JSON.parse(data)
  31. // Get rid of longer emojis that don't play nice with reactions
  32. Object.keys(emojisObject).forEach(e => {
  33. if (emojisObject[e].length > 2) emojisObject[e] = undefined
  34. })
  35. // Add new emojis from the new tables to the old table
  36. Object.keys(newEmojisObject).forEach(e => {
  37. if (!emojisObject[e] && newEmojisObject[e].length <= 2) {
  38. emojisObject[e] = newEmojisObject[e]
  39. }
  40. })
  41. // Sort by key
  42. const sorted = Object.keys(emojisObject).sort().reduce((acc, key) => {
  43. if (key.length === 0) return acc
  44. acc[key] = emojisObject[key]
  45. return acc
  46. }, {})
  47. fs.writeFile(outputFilename, JSON.stringify(sorted, null, 2), 'utf8', (err) => {
  48. if (err) console.log('Error writing file', err)
  49. })
  50. }
  51. run()