Debian Codegraph @

scripts/emoji-convert.sh

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