mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	build_emoji: Add emoji_catalog to emoji_code.js
				
					
				
			Use `emoji.json` to create a emoji catalog and add it to `emoji_code.js` file. This catalog contains the unicode codepoints of all the emojis grouped according to their category. Emojis are sorted according to the `sort_order` defined in the iamcal's dataset.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							4470a3947b
						
					
				
				
					commit
					660d96038a
				
			@@ -13,7 +13,7 @@ from itertools import permutations, chain
 | 
			
		||||
import ujson
 | 
			
		||||
 | 
			
		||||
from six.moves import range, zip
 | 
			
		||||
from typing import Dict, List, Text
 | 
			
		||||
from typing import Any, Dict, List, Text
 | 
			
		||||
 | 
			
		||||
# the corresponding code point will be set to exactly these names as a
 | 
			
		||||
# final pass, overriding any other rules.  This is useful for cases
 | 
			
		||||
@@ -223,3 +223,22 @@ def emoji_names_for_picker(emoji_map):
 | 
			
		||||
        codepoint_to_names[codepoint] = names
 | 
			
		||||
 | 
			
		||||
    return sorted(list(chain.from_iterable(codepoint_to_names.values())))
 | 
			
		||||
 | 
			
		||||
# Returns a dict from categories to list of codepoints. The list of
 | 
			
		||||
# codepoints are sorted according to the `sort_order` as defined in
 | 
			
		||||
# `emoji_data`.
 | 
			
		||||
def generate_emoji_catalog(emoji_data):
 | 
			
		||||
    # type: (List[Dict[Text, Any]]) -> Dict[str, List[str]]
 | 
			
		||||
    sort_order = {} # type: Dict[str, int]
 | 
			
		||||
    emoji_catalog = {} # type: Dict[str, List[str]]
 | 
			
		||||
    for emoji in emoji_data:
 | 
			
		||||
        category = str(emoji["category"])
 | 
			
		||||
        codepoint = str(emoji["unified"])
 | 
			
		||||
        sort_order[codepoint] = emoji["sort_order"]
 | 
			
		||||
        if category in emoji_catalog:
 | 
			
		||||
            emoji_catalog[category].append(codepoint)
 | 
			
		||||
        else:
 | 
			
		||||
            emoji_catalog[category] = [codepoint, ]
 | 
			
		||||
    for category in emoji_catalog:
 | 
			
		||||
        emoji_catalog[category].sort(key=lambda codepoint: sort_order[codepoint])
 | 
			
		||||
    return emoji_catalog
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user