Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add icon keywords file #274

Merged
merged 17 commits into from
Sep 20, 2023
58 changes: 58 additions & 0 deletions .github/figma-descriptions-transformer/figma-transformer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Clone the mistica-icons repo to your computer and make sure you are on the production branch with the latest updates

# Ensure that icons-keywords.json is up-to-date and contains the line with the icon's name

# Open the Figma Bulk Meta plugin where the icons are located
# Export the JSON and name it telefonica-original.json, save it in the repo under resources/figma-descriptions-transformer/originals
# Choose brand to export changing the brand name on line 13 in this file
# Run the script in the terminal "python3 figma-transformer.py"

# Open the Figma Bulk Meta plugin
# Go to the "Import" tab and select the telefonica.json file generated by the script

# ————— CHANGE BRAND TO THE BRAND NAME ————— #
# "vivo" or "telefonica" or "o2"
brand = "telefonica"

import json

# Build the file path using the variable
original_path = f'./.github/figma-descriptions-transformer/originals/{brand}-original.json'
generated_path = f'./.github/figma-descriptions-transformer/generated/{brand}.json'

# Read the original JSON from the file
with open(original_path, 'r') as original_file:
json_original = json.load(original_file)

# Read the keyword mapping from the file
# DO NOT TOUCH #
with open('./icons/icons-keywords.json', 'r') as keywords_file:
keywords = json.load(keywords_file)

# Function to replace the description
def replace_description(json, keywords):
new_json = {}

for key, item in json.items():
# Remove "light", "regular", and "filled" from the key
key_without_variants = key.replace('-light', '').replace('-regular', '').replace('-filled', '')

if key_without_variants in keywords:
words = keywords[key_without_variants]
new_description = ', '.join(words)
else:
new_description = item["description"]

# Copy the original object and update the description
new_item = item.copy()
new_item['description'] = new_description
new_json[key] = new_item

return new_json

# Call the function to get the updated JSON
updated_json = replace_description(json_original, keywords)

# Write the updated JSON to a new file
with open(generated_path, 'w') as new_file:
json.dump(updated_json, new_file, indent=2)
Loading