From 8d8cb6f4a84c0f01dd329bade5c0c1b6148f6881 Mon Sep 17 00:00:00 2001 From: Stefan Laut Date: Wed, 12 Nov 2025 14:20:47 +0100 Subject: [PATCH] Add support for optional [icon-filename].svg.tags file to include search tags --- README.md | 4 ++++ loxicon.py | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4f755a9..88161a7 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,10 @@ The index is used to generate the UUID for each icon, which the Miniserver uses To ensure that each custom icon has a static UUID, the index should be prefixed to each filename. An example is shown below, with the resulting `IconLibrary.zip` that is generated when Loxicon is run: +Besides the icon file, you can add an [filename.svg]__.tags__ file. This file contains search tags for the icon, with each tag on a separate line. It is combined with the tags provided via the CLI parameter `--tags`. + +* `1.bunny-rabbit.svg.tags` +

diff --git a/loxicon.py b/loxicon.py index 67430e1..fe12551 100644 --- a/loxicon.py +++ b/loxicon.py @@ -87,7 +87,13 @@ def add_icons_to_library(zf, iconList, tags=[], line=True, filled=True, force=Fa xmlroot = ET.parse(ilf) for icon in iconList: - if add_icon_xml(xmlroot, icon['name'], icon['index'], tags, line, filled, force): + # combine CLI tags with any per-file tags read from .svg.tags + combined_tags = list(tags) if tags else [] + if 'tags' in icon and icon['tags']: + # append per-file tags, avoiding modifying the original 'tags' arg + combined_tags.extend(icon['tags']) + + if add_icon_xml(xmlroot, icon['name'], icon['index'], combined_tags, line, filled, force): modified = True # write the new version of the XML file @@ -134,10 +140,29 @@ def compile_svgs(iconspec): i = m.group(1) if m.group(1) else len(files)+1 if m.group(1): - files.append(dict(index=int(i), - name=prefix + m.group(2), - path=file - )) + # prepare base entry + entry = dict(index=int(i), + name=prefix + m.group(2), + path=file) + + # look for a corresponding .tags file next to the svg + tags_path = file + '.tags' + tags_list = [] + if os.path.exists(tags_path): + try: + with open(tags_path, 'r', encoding='utf-8') as tf: + for line in tf: + t = line.strip() + if t: + tags_list.append(t) + except OSError: + # if reading fails, ignore tags for this file + tags_list = [] + + if tags_list: + entry['tags'] = tags_list + + files.append(entry) return files def upload_to_miniserver(miniserver, source, dest):