"""Bring in the icons the site uses: Gitea's sets. python3 -I scripts/icons.py <@primer/octicons package dir> File icons are a subset of material-icon-theme (MIT, the set Gitea uses for files; npm material-icon-theme 5.40.0). The chosen SVGs go to web/static/icons/material/, and the name, extension and folder maps to internal/render/icons_gen.go. Every mapping that points at a chosen icon is kept, so coverage is wide while the icon count stays small. UI icons (tabs, stats, clone, copy, CI, activity) are Octicons (MIT, Gitea's UI set; npm @primer/octicons 19.15.0), 16px variants. Only the ones in UI are copied, to web/static/icons/octicons/.svg. """ import json, os, re, shutil, sys FILES = """file go go-mod go-workspace markdown readme license changelog contributing authors css sass less html javascript typescript react react_ts vue svelte astro json yaml toml xml console python rust swift c cpp h hpp java kotlin ruby php lua nix docker makefile just git nodejs npm yarn pnpm lock image svg font pdf zip database settings document log certificate key tune editorconfig prettier eslint todo templ terraform graphql proto csharp dart elixir erlang haskell zig r julia powershell apple android gradle vim http table jupyter tex renovate caddy nginx hcl robots favicon webassembly assembly vite tailwindcss deno bun biome """.split() FOLDERS = """folder folder-open folder-src folder-docs folder-command folder-public folder-test folder-github folder-gitea folder-scripts folder-resource folder-images folder-config folder-lib folder-dist folder-node folder-git folder-vscode folder-docker folder-template folder-components folder-utils folder-api folder-server folder-client folder-android folder-app folder-css folder-font folder-javascript folder-include folder-tools folder-temp folder-content folder-database folder-ios folder-mock folder-log folder-routes folder-views folder-hook folder-theme folder-core folder-plugin folder-target folder-private folder-secure folder-claude folder-nix folder-ci folder-environment folder-examples folder-benchmark folder-markdown folder-svg folder-video folder-audio folder-desktop folder-mobile """.split() # site UI icon name -> Octicon name. Add only what a template or docKinds uses. UI = { "book": "book", "branch": "git-branch", "check": "check", "chevron": "triangle-down", "code": "code", "comment": "comment", "commit": "git-commit", "conduct": "code-of-conduct", "copy": "copy", "dot": "dot-fill", "download": "download", "fire": "flame", "heart": "heart", "history": "history", "info": "info", "issue": "issue-opened", "issue-closed": "issue-closed", "law": "law", "link": "link", "lock": "lock", "merge": "git-merge", "organization": "organization", "package": "package", "pull": "git-pull-request", "pulse": "pulse", "quote": "quote", "repo-new": "repo", "shield": "shield", "support": "comment-discussion", "tag": "tag", "unlock": "unlock", "user": "person", "users": "people", "x": "x", } material, octicons = sys.argv[1], sys.argv[2] out = "web/static/icons" m = json.load(open(os.path.join(material, "dist/material-icons.json"))) have = set(m["iconDefinitions"]) icons = [n for n in FILES + FOLDERS if n in have] missing = sorted(set(FILES + FOLDERS) - have) if missing: print("not in this version:", " ".join(missing)) shutil.rmtree(out, ignore_errors=True) # also drops icon sets no longer used os.makedirs(os.path.join(out, "material")) os.makedirs(os.path.join(out, "octicons")) for n in icons: src = os.path.normpath(os.path.join(material, "dist", m["iconDefinitions"][n]["iconPath"])) shutil.copy(src, os.path.join(out, "material", n + ".svg")) shutil.copy(os.path.join(material, "LICENSE"), os.path.join(out, "material", "LICENSE")) for name, src in UI.items(): svg = open(os.path.join(octicons, "build/svg", src + "-16.svg")).read() if 'viewBox="0 0 16 16"' not in svg or re.search(r"style=|