1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-09 05:14:15 +01:00
ntfy/scripts/emoji-convert.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
2.2 KiB
Bash
Raw Normal View History

2021-11-29 16:57:18 +01:00
#!/bin/bash
# This script reduces the size and converts the emoji.json file from https://github.com/github/gemoji/blob/master/db/emoji.json
# to be used in the Android app (app/src/main/resources/emoji.json) and the Web UI (server/static/js/emoji.js).
SCRIPTDIR="$(cd "$(dirname "$0")" && pwd)"
ROOTDIR="$(cd "$(dirname "$0")/.." && pwd)"
if [ -z "$1" ]; then
2021-12-02 18:04:22 +01:00
echo "Syntax: $0 FILE.(js|json|md)"
2021-11-29 16:57:18 +01:00
echo "Example:"
echo " $0 emoji-converted.json"
2022-04-04 16:04:01 +02:00
echo " $0 $ROOTDIR/web/src/app/emojis.js"
2021-12-02 18:04:22 +01:00
echo " $0 $ROOTDIR/docs/emojis.md"
2021-11-29 16:57:18 +01:00
exit 1
fi
if [[ "$1" == *.js ]]; then
echo -n "// This file is generated by scripts/emoji-convert.sh to reduce the size
// Original data source: https://github.com/github/gemoji/blob/master/db/emoji.json
2022-02-24 18:26:07 +01:00
export const rawEmojis = " > "$1"
cat "$SCRIPTDIR/emoji.json" | jq -rc 'map({emoji: .emoji, aliases: .aliases, tags: .tags, category: .category, description: .description, unicode_version: .unicode_version})' >> "$1"
2021-12-02 18:04:22 +01:00
elif [[ "$1" == *.md ]]; then
echo "# Emoji reference
<!-- This file was generated by scripts/emoji-convert.sh -->
2023-10-29 17:32:08 +01:00
You can [tag messages](publish.md#tags-emojis) with emojis 🥳 🎉 and other relevant strings. Matching tags are automatically
2021-12-02 18:04:22 +01:00
converted to emojis. This is a reference of all supported emojis. To learn more about the feature, please refer to the
2023-10-29 17:32:08 +01:00
[tagging and emojis page](publish.md#tags-emojis).
2021-12-02 18:04:22 +01:00
2023-04-07 03:51:25 +02:00
<table class=\"remove-md-box emoji-table\"><tr>
2021-12-02 18:04:22 +01:00
" > "$1"
count="$(cat "$SCRIPTDIR/emoji.json" | jq -r '.[] | .emoji' | wc -l)"
percolumn=$(($count / 3)) # This will misbehave if the count is not divisible by 3
for col in 0 1 2; do
from="$(($col * $percolumn + 1))"
to="$(($col * $percolumn + 1 + $percolumn))"
2023-04-07 03:51:25 +02:00
echo "<td><table><thead><tr><th>Tag</th><th style='text-align: center'>Emoji</th></tr></thead><tbody>" >> "$1"
2021-12-02 18:04:22 +01:00
cat "$SCRIPTDIR/emoji.json" \
2023-04-07 03:51:25 +02:00
| jq -r '.[] | "<tr><td class=c><code>" + .aliases[0] + "</code></td><td class=e>" + .emoji + "</td></tr>"' \
2021-12-02 18:04:22 +01:00
| sed -n "${from},${to}p" >> "$1"
echo "</tbody></table></td>" >> "$1"
done
echo "</tr></table>" >> "$1"
2021-11-29 16:57:18 +01:00
else
cat "$SCRIPTDIR/emoji.json" | jq -rc 'map({emoji: .emoji,aliases: .aliases})' > "$1"
fi