Skip to content

icons

Class info

🛈 DocStrings

_get_collection_map cached

_get_collection_map(*prefixes: str) -> dict[str, list[str]]

Return a dictionary with a mapping from pyconify name to icon prefixes.

In order to provide compatibility with the materialx-icon-index, we also add the prefixes used by that index, which is different from the pyconify prefixes. (material vs mdi etc, see PYCONIFY_TO_PREFIXES)

Parameters:

Name Type Description Default
prefixes str

The collections to fetch

()
Source code in src/jinjarope/icons.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@functools.cache
def _get_collection_map(*prefixes: str) -> dict[str, list[str]]:
    """Return a dictionary with a mapping from pyconify name to icon prefixes.

    In order to provide compatibility with the materialx-icon-index,
    we also add the prefixes used by that index, which is different from
    the pyconify prefixes. (material vs mdi etc, see PYCONIFY_TO_PREFIXES)

    Args:
        prefixes: The collections to fetch
    """
    import pyconify

    mapping = {coll: [coll] for coll in pyconify.collections(*prefixes)}
    for k, v in PYCONIFY_TO_PREFIXES.items():
        if k in mapping:
            mapping[k].append(v)
    return mapping

_get_pyconify_icon_index cached

_get_pyconify_icon_index(*collections: str) -> dict[str, dict[str, str]]

Return a icon index for the pymdownx emoji extension containing pyconify icons.

The dictionaries contain three key-value pairs: - "name": the emoji identifier - "path": the pyconify key - "set": the collection name

Parameters:

Name Type Description Default
collections str

Collections to fetch. If none given, fetch all

()
Source code in src/jinjarope/icons.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
@functools.cache
def _get_pyconify_icon_index(*collections: str) -> dict[str, dict[str, str]]:
    """Return a icon index for the pymdownx emoji extension containing pyconify icons.

    The dictionaries contain three key-value pairs:
    - "name": the emoji identifier
    - "path": the pyconify key
    - "set": the collection name

    Args:
        collections: Collections to fetch. If none given, fetch all
    """
    import pyconify

    index = {}
    for coll, prefixes in _get_collection_map(*collections).items():
        collection = pyconify.collection(coll)
        for icon_name in collection.get("uncategorized", []):
            for prefix in prefixes:
                name = f":{prefix}-{icon_name}:"
                index[name] = {
                    "name": name,
                    "path": f"{coll}:{icon_name}",
                    "set": coll,
                }
        for cat in pyconify.collection(coll).get("categories", {}).values():
            for icon_name in cat:
                for prefix in prefixes:
                    name = f":{prefix}-{icon_name}:"
                    index[name] = {
                        "name": name,
                        "path": f"{coll}:{icon_name}",
                        "set": coll,
                    }
    return index

load_icon_index

load_icon_index() -> dict[str, dict[str, str]]

Load the complete icon index from disk.

Source code in src/jinjarope/icons.py
88
89
90
91
92
93
94
def load_icon_index() -> dict[str, dict[str, str]]:
    """Load the complete icon index from disk."""
    import gzip
    import json

    with gzip.open(ICON_FILE, "r") as file:
        return json.loads(file.read())

write_icon_index

write_icon_index()

Fetch the complete icon index and write it gzipped to disk.

Source code in src/jinjarope/icons.py
78
79
80
81
82
83
84
85
def write_icon_index():
    """Fetch the complete icon index and write it gzipped to disk."""
    import gzip
    import json

    mapping = _get_pyconify_icon_index()
    with gzip.open(ICON_FILE, "w") as file:
        file.write(json.dumps(mapping).encode())