mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
emoji_codes: Replace JS module with JSON module.
webpack optimizes JSON modules using JSON.parse("{…}"), which is
faster than the normal JavaScript parser.
Update the backend to use emoji_codes.json too instead of the three
separate JSON files.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
committed by
Tim Abbott
parent
dce7118ec7
commit
e257253e64
@@ -24,27 +24,6 @@ EMOJI_CACHE_PATH = "/srv/zulip-emoji-cache"
|
||||
EMOJI_SCRIPT_DIR_PATH = os.path.join(ZULIP_PATH, 'tools', 'setup', 'emoji')
|
||||
NODE_MODULES_PATH = os.path.join(ZULIP_PATH, 'node_modules')
|
||||
|
||||
EMOJI_CODES_FILE_TEMPLATE = """\
|
||||
var emoji_codes = (function () {
|
||||
var exports = {};
|
||||
|
||||
exports.names = %(names)s;
|
||||
|
||||
exports.name_to_codepoint = %(name_to_codepoint)s;
|
||||
|
||||
exports.codepoint_to_name = %(codepoint_to_name)s;
|
||||
|
||||
exports.emoji_catalog = %(emoji_catalog)s;
|
||||
|
||||
exports.emoticon_conversions = %(emoticon_conversions)s;
|
||||
|
||||
return exports;
|
||||
}());
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = emoji_codes;
|
||||
}
|
||||
"""
|
||||
|
||||
SPRITE_CSS_FILE_TEMPLATE = """\
|
||||
div.emoji,
|
||||
span.emoji
|
||||
@@ -244,32 +223,20 @@ def setup_old_emoji_farm(cache_path: str,
|
||||
pass
|
||||
|
||||
def generate_map_files(cache_path: str, emoji_catalog: Dict[str, List[str]]) -> None:
|
||||
# This function generates the various data files consumed by webapp, mobile apps, bugdown etc.
|
||||
# This function generates the data file consumed by webapp, mobile apps, bugdown etc.
|
||||
names = emoji_names_for_picker(EMOJI_NAME_MAPS)
|
||||
codepoint_to_name = generate_codepoint_to_name_map(EMOJI_NAME_MAPS)
|
||||
name_to_codepoint = generate_name_to_codepoint_map(EMOJI_NAME_MAPS)
|
||||
|
||||
EMOJI_CODES_FILE_PATH = os.path.join(cache_path, 'emoji_codes.js')
|
||||
EMOJI_CODES_FILE_PATH = os.path.join(cache_path, 'emoji_codes.json')
|
||||
with open(EMOJI_CODES_FILE_PATH, 'w') as emoji_codes_file:
|
||||
emoji_codes_file.write(EMOJI_CODES_FILE_TEMPLATE % {
|
||||
ujson.dump({
|
||||
'names': names,
|
||||
'name_to_codepoint': name_to_codepoint,
|
||||
'codepoint_to_name': codepoint_to_name,
|
||||
'emoji_catalog': emoji_catalog,
|
||||
'emoticon_conversions': EMOTICON_CONVERSIONS,
|
||||
})
|
||||
|
||||
NAME_TO_CODEPOINT_PATH = os.path.join(cache_path, 'name_to_codepoint.json')
|
||||
with open(NAME_TO_CODEPOINT_PATH, 'w') as name_to_codepoint_file:
|
||||
name_to_codepoint_file.write(ujson.dumps(name_to_codepoint))
|
||||
|
||||
CODEPOINT_TO_NAME_PATH = os.path.join(cache_path, 'codepoint_to_name.json')
|
||||
with open(CODEPOINT_TO_NAME_PATH, 'w') as codepoint_to_name_file:
|
||||
codepoint_to_name_file.write(ujson.dumps(codepoint_to_name))
|
||||
|
||||
EMOTICON_CONVERSIONS_PATH = os.path.join(cache_path, 'emoticon_conversions.json')
|
||||
with open(EMOTICON_CONVERSIONS_PATH, 'w') as emoticon_conversions_file:
|
||||
emoticon_conversions_file.write(ujson.dumps(EMOTICON_CONVERSIONS))
|
||||
}, emoji_codes_file)
|
||||
|
||||
def dump_emojis(cache_path: str) -> None:
|
||||
with open('emoji_map.json') as emoji_map_file:
|
||||
|
||||
Reference in New Issue
Block a user