emoji-convert.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. # This script reduces the size and converts the emoji.json file from https://github.com/github/gemoji/blob/master/db/emoji.json
  3. # to be used in the Android app (app/src/main/resources/emoji.json) and the Web UI (server/static/js/emoji.js).
  4. SCRIPTDIR="$(cd "$(dirname "$0")" && pwd)"
  5. ROOTDIR="$(cd "$(dirname "$0")/.." && pwd)"
  6. if [ -z "$1" ]; then
  7. echo "Syntax: $0 FILE.(js|json|md)"
  8. echo "Example:"
  9. echo " $0 emoji-converted.json"
  10. echo " $0 $ROOTDIR/web/src/app/emojis.js"
  11. echo " $0 $ROOTDIR/docs/emojis.md"
  12. exit 1
  13. fi
  14. if [[ "$1" == *.js ]]; then
  15. echo -n "// This file is generated by scripts/emoji-convert.sh to reduce the size
  16. // Original data source: https://github.com/github/gemoji/blob/master/db/emoji.json
  17. export const rawEmojis = " > "$1"
  18. cat "$SCRIPTDIR/emoji.json" | jq -rc 'map({emoji: .emoji, aliases: .aliases, tags: .tags, category: .category, description: .description, unicode_version: .unicode_version})' >> "$1"
  19. elif [[ "$1" == *.md ]]; then
  20. echo "# Emoji reference
  21. <!-- This file was generated by scripts/emoji-convert.sh -->
  22. You can [tag messages](../publish/#tags-emojis) with emojis 🥳 🎉 and other relevant strings. Matching tags are automatically
  23. converted to emojis. This is a reference of all supported emojis. To learn more about the feature, please refer to the
  24. [tagging and emojis page](../publish/#tags-emojis).
  25. <table class="remove-md-box"><tr>
  26. " > "$1"
  27. count="$(cat "$SCRIPTDIR/emoji.json" | jq -r '.[] | .emoji' | wc -l)"
  28. percolumn=$(($count / 3)) # This will misbehave if the count is not divisible by 3
  29. for col in 0 1 2; do
  30. from="$(($col * $percolumn + 1))"
  31. to="$(($col * $percolumn + 1 + $percolumn))"
  32. echo "<td><table><thead><tr><th>Tag</th><th>Emoji</th></tr></thead><tbody>" >> "$1"
  33. cat "$SCRIPTDIR/emoji.json" \
  34. | jq -r '.[] | "<tr><td><code>" + .aliases[0] + "</code></td><td>" + .emoji + "</td></tr>"' \
  35. | sed -n "${from},${to}p" >> "$1"
  36. echo "</tbody></table></td>" >> "$1"
  37. done
  38. echo "</tr></table>" >> "$1"
  39. else
  40. cat "$SCRIPTDIR/emoji.json" | jq -rc 'map({emoji: .emoji,aliases: .aliases})' > "$1"
  41. fi