fix rendering of emojis with camelCase names

This commit is contained in:
mst 2024-11-26 15:16:14 +03:00
parent ad4f34c7db
commit 283f2e5784

View file

@ -277,11 +277,18 @@ EMOJI_BASE_PATH = Path.cwd() / 'static' / 'emojis'
emoji_cache = {} emoji_cache = {}
def to_snake_case(name):
name = re.sub(r'(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub(r'([a-z0-9])([A-Z])', r'\1_\2', name).lower()
def find_emoji_path(emoji_name): def find_emoji_path(emoji_name):
if '_' in emoji_name:
head, sep, tail = emoji_name.partition('_') head, sep, tail = emoji_name.partition('_')
else:
head = to_snake_case(emoji_name).split('_')[0]
if any(Path(EMOJI_BASE_PATH).glob(f'{head}.json')): if any(Path(EMOJI_BASE_PATH).glob(f'{head}.json')):
for json_file in Path(EMOJI_BASE_PATH).glob('*.json'): for json_file in Path(EMOJI_BASE_PATH).glob('*.json'):
print("\n[CatAsk/functions/find_emoji_path] Using JSON meta file\n") app.logger.debug("\n[CatAsk/functions/find_emoji_path] Using JSON meta file\n")
pack_data = loadJSON(json_file) pack_data = loadJSON(json_file)
emojis = pack_data.get('emojis', []) emojis = pack_data.get('emojis', [])