Kanji
・Cloud Engineer / Freelance ・Geboren 1993 ・Aus Ehime / Wohnhaft in Shibuya, Tokio ・5 Jahre AWS-Erfahrung Profildetails
Inhaltsverzeichnis
Bei der Verwendung von Bildern in Mermaid gibt es zwei Hauptmethoden: „① Geben Sie die Bild-URL mit dem „img“-Tag an“ und „② Verwenden Sie ein Symbolpaket“.Im Folgenden wird beschrieben, wie Sie die alten AWS-Architektursymbole verwenden.
Referenz: So ändern Sie Knotenformen und geben Bilder/Symbole im Mermaid-Flussdiagramm an #Anfänger --Qiita
Verwenden Sie das „img“-Tag von Mermaid, um die URL eines AWS-Symbols direkt anzugeben.
flowchart TB subgraph ACCOUNT[AWS Account] subgraph GRP1[" "] ELB@{ img: "https://api.iconify.design/logos/aws-elb.svg", label: "ELB", pos: "b", w: 60, h: 60, constraint: "on" } end subgraph GRP2[" "] EC2@{ img: "https://api.iconify.design/logos/aws-ec2.svg", label: "EC2", pos: "b", w: 60, h: 60, constraint: "on" } end subgraph GRP3[" "] RDS@{ img: "https://api.iconify.design/logos/aws-rds.svg", label: "RDS", pos: "b", w: 60, h: 60, constraint: "on" } end ELB --- EC2 --- RDS end classDef vpc fill:none,color:#0a0,stroke:#0a0 class ACCOUNT vpc classDef group fill:none,stroke:none class GRP1,GRP2,GRP3 group
Beim Rendern in Mermaid sieht es so aus:
Eine andere Methode besteht darin, ein Meerjungfrau-Symbolpaket zu verwenden.Dadurch entfällt die Notwendigkeit, für jedes Symbol eine URL anzugeben.
Referenz: Symbolpaket in Mermaid registrieren |Meerjungfrau
flowchart TB subgraph ACCOUNT[AWS Account] subgraph GRP1[" "] ELB@{ icon: "logos:aws-elb", label: "ELB", pos: "b", h: 60} end subgraph GRP2[" "] EC2@{ icon: "logos:aws-ec2", label: "EC2", pos: "b", h: 60} end subgraph GRP3[" "] RDS@{ icon: "logos:aws-rds", label: "RDS", pos: "b", h: 60} end ELB --- EC2 --- RDS end classDef vpc fill:none,color:#0a0,stroke:#0a0 class ACCOUNT vpc classDef group fill:none,stroke:none class GRP1,GRP2,GRP3 group
Diese Methode kann jedoch nicht auf SaaS-Plattformen wie Qiita oder GitHub verwendet werden. Um ein Icon Pack zu verwenden, müssen Sie eine JSON-Datei laden, die auf einem CDN oder Server gehostet wird, wie unten gezeigt:
<script> mermaid.registerIconPacks([ { name: 'logos', loader: () => fetch('https://unpkg.com/@iconify-json/logos@1/icons.json').then((res) => res.json()), }, ]); mermaid.initialize({startOnLoad:true}); </script>
Auf dieser Website verwenden wir ein benutzerdefiniertes Symbolpaket, das mit den neuesten Symbolen der AWS-Architektur erstellt wurde.
Um die neuesten AWS-Architektursymbole verwenden zu können, müssen Sie ein benutzerdefiniertes Mermaid-Symbolpaket erstellen. In diesem Abschnitt wird erläutert, wie Sie ein Mermaid-Symbolpaket erstellen und die neuesten AWS-Architektursymbole verwenden.
Laden Sie zunächst die neuesten AWS-Architektursymbole von der folgenden Website herunter. Klicken Sie auf [Erste Schritte] -> [Symbolpaket], um den Download zu starten.
Einfache AWS-Symbole – AWS Architecture Center |AWS
Die heruntergeladene Datei trägt derzeit den Namen „Asset-Package_02072025.dee42cd0a6eaacc3da1ad9519579357fb546f803.zip“. Nach dem Extrahieren sehen Sie eine Ordnerstruktur wie unten.Verwenden Sie diese Dateien, um Ihr Meerjungfrau-Symbolpaket zu erstellen.
Asset-Package_02072025.dee42cd0a6eaacc3da1ad9519579357fb546f803/ ├── Architecture-Group-Icons_02072025 │ ├── _32.png │ ├── _32.svg │ └── ... ├── Architecture-Service-Icons_02072025 │ ├── Arch_Cloud-Financial-Management │ ├── Arch_Compute │ └── ... ├── Category-Icons_02072025 │ ├── Arch-Category_16 │ ├── Arch-Category_32 │ └── ... └── Resource-Icons_02072025 ├── Res_Analytics └── Resource-Icons_02072025 ├── Res_Analytics ├── Res_Application-Integration └── ...
Speichern Sie als Nächstes das folgende Python-Skript in einem geeigneten Verzeichnis (z. B. „collect_mermaid_icons.py“). Das Skript verwendet nur Standardbibliotheken: „re“, „os“, „json“ und „argparse“.
import re import argparse FOLDER_FILE_PATTERNS = { "Architecture-Group-Icons": "_32.svg", "Architecture-Service-Icons": "_48.svg", "Category-Icons": "_48.svg", "Resource-Icons": "_48.svg", } def get_icon_folders(icon_root): return [name for name in os.listdir(icon_root) if os.path.isdir(os.path.join(icon_root, name))] def extract_svg_size(svg_content): m = re.search(r'<svg[^>]*width=["\']?(\d+)["\']?[^>]*height=["\']?(\d+)["\']?', svg_content) if m: return int(m.group(1)), int(m.group(2)) return 0, 0 def collect_svg_icons(icon_root): icon_folders = get_icon_folders(icon_root) icons = {} for folder in icon_folders: print(f"Processing folder: {folder}") folder_path = os.path.join(icon_root, folder) if not os.path.isdir(folder_path): continue pattern = None for key, value in FOLDER_FILE_PATTERNS.items(): if folder.startswith(key): pattern = value break for root, dirs, files in os.walk(folder_path): for file in files: icon_name = os.path.splitext(file)[0] normalized_name = icon_name.replace(pattern.replace(".svg", "").replace(".png", ""), "") if pattern else icon_name file_path = os.path.join(root, file) if pattern: if not file.endswith(pattern): continue svg_content = "" try: with open(file_path, "r", encoding="utf-8") as svg_file: svg_content = svg_file.read() fill_colors = re.findall(r'fill=["\'](#[0-9a-fA-F]{3,6})["\']', svg_content, flags=re.IGNORECASE) if fill_colors: main_color = fill_colors[0] if fill_colors else None svg_content = re.sub(r'fill=["\']#fff(?:fff)?["\']', f'fill="{main_color}"', svg_content, flags=re.IGNORECASE) except Exception: svg_content = "" width, height = extract_svg_size(svg_content) icons[normalized_name] = {"body": svg_content, "width": width, "height": height} continue return icons def main(): parser.add_argument("--icon-root", type=str, help="Root directory of AWS architecture icons") parser.add_argument("--output-json", type=str, default="./icons.json", help="Path to output JSON file (default: ./icons.json)") parser.add_argument("--icon-list-txt", type=str, default="./icon_list.txt", help="Path to icon name list TXT file (default: ./icon_list.txt)") args = parser.parse_args() error_flags = False error_messages = [] if not args.icon_root or not os.path.isdir(args.icon_root): error_flags = True error_messages.append("The icon root directory is not specified correctly. Please use the --icon-root option.") if not args.output_json: error_flags = True error_messages.append("The path to the output JSON file is not specified. Please use the --output-json option.") if not args.icon_list_txt: error_flags = True error_messages.append("The path to the icon name list TXT file is not specified. Please use the --icon-list-txt option.") if error_flags: for msg in error_messages: print(f"Error: {msg}") return icons = collect_svg_icons(args.icon_root) output = {"prefix": "logos", "icons": icons} with open(args.output_json, "w", encoding="utf-8") as f: json.dump(output, f, ensure_ascii=False, indent=2) icon_names = sorted(icons.keys()) with open(args.icon_list_txt, "w", encoding="utf-8") as f: for name in icon_names: f.write(name + "\n") if __name__ == "__main__": main()
By running this script, you can collect SVG icons from the specified AWS architecture icon root directory and generate a JSON file in the Mermaid icon pack format.
To execute the script, run the following command from the terminal. This will collect icons from the specified directory and generate both icons.json and icon_list.txt files.
icons.json
icon_list.txt
python collect_mermaid_icons.py \ --icon-root /path/to/Asset-Package_02072025.dee42cd0a6eaacc3da1ad9519579357fb546f803 \ # Optional --output-json ./icons.json \ --icon-list-txt ./icon_list.txt
The generated icons.json file can be used as a Mermaid icon pack. Below is an example of the actual icon pack JSON generated by the script.
{ "prefix": "logos", "icons": { "Arch-Category_Storage": { "body": "<svg width=\"74px\" height=\"74px\" viewBox=\"0 0 74 74\" xmlns=\"http://www.w3.org/2000/svg\">...</svg>", "width": 74, "height": 74 }, "Arch_Amazon-EC2": { "body": "<svg width=\"64px\" height=\"64px\" viewBox=\"0 0 64 64\" xmlns=\"http://www.w3.org/2000/svg\">...</svg>", "width": 64, "height": 64 }, "Arch_Amazon-RDS": { "body": "<svg width=\"64px\" height=\"64px\" viewBox=\"0 0 64 64\" xmlns=\"http://www.w3.org/2000/svg\">...</svg>", "width": 64, "height": 64 }, "Arch_Elastic-Load-Balancing": { "body": "<svg width=\"64px\" height=\"64px\" viewBox=\"0 0 64 64\" xmlns=\"http://www.w3.org/2000/svg\">...</svg>", "width": 64, "height": 64 }, "Arch_Amazon-Simple-Storage-Service": { "body": "<svg width=\"64px\" height=\"64px\" viewBox=\"0 0 64 64\" xmlns=\"http://www.w3.org/2000/svg\">...</svg>", "width": 64, "height": 64 }, "Arch_AWS-Lambda": { "body": "<svg width=\"64px\" height=\"64px\" viewBox=\"0 0 64 64\" xmlns=\"http://www.w3.org/2000/svg\">...</svg>", "width": 64, "height": 64 } } }
Die vollständige Datei icons.json (mit über 780 offiziellen AWS-SVG-Symbolen) wird durch Ausführen von collect_mermaid_icons.py aus Schritt 2 lokal in wenigen Sekunden generiert. Zur Optimierung der Ladezeit zeigt der obige Auszug die repräsentative Struktur (EC2, RDS, ELB, S3 und Lambda).
collect_mermaid_icons.py
Finally, load the Mermaid icon pack. If you want to load the JSON file from your server, add the following code to your HTML file:
<script> mermaid.registerIconPacks([ { name: 'logos', loader: () => fetch('./icons.json').then((res) => res.json()), }, ]); mermaid.initialize({ startOnLoad: true }); </script>
On this site, we implement it by writing the contents of the JSON file into the mermaid-icons-json element according to the page.
mermaid-icons-json
<script type="application/json" id="mermaid-icons-json"> </script> <script> mermaid.registerIconPacks([ { name: 'logos', loader: () => { const jsonText = document.getElementById('mermaid-icons-json').textContent; return Promise.resolve(JSON.parse(jsonText)); }, }, ]); mermaid.initialize({ startOnLoad: true }); </script>
To specify an icon pack, use the icon name after logos: . The available icon names in the pack you created are listed in the icon_list.txt file.
logos:
flowchart TB subgraph ACCOUNT[AWS Account] subgraph GRP1[" "] ELB@{ icon: "logos:Arch_Elastic-Load-Balancing", label: "ELB", pos: "b", w: 60, h: 60, constraint: "on" } end subgraph GRP2[" "] EC2@{ icon: "logos:Res_Amazon-EC2_Instance", label: "EC2", pos: "b", w: 60, h: 60, constraint: "on" } end subgraph GRP3[" "] RDS@{ icon: "logos:Arch_Amazon-RDS", label: "RDS", pos: "b", w: 60, h: 60, constraint: "on" } end ELB --- EC2 --- RDS end classDef vpc fill:none,color:#0a0,stroke:#0a0 class ACCOUNT vpc classDef group fill:none,stroke:none class GRP1,GRP2,GRP3 group
When displayed in Mermaid, it looks like this: As mentioned at the beginning, the ELB and RDS icons have different colors from the latest AWS architecture icons. This is because the color conversion did not work well when processing the AWS architecture icon SVG files.
Real-time AI quant analysis of corporate earnings reports.
Trainieren Sie soziale Fähigkeiten mit realistischen KI-Testanrufen, 5-Achsen-Feedback, 16 interaktiven Lektionen und KI-Porträts.
Belege scannen und blitzschnell mit Gemini AI erfassen. Nahtlose Gruppenabrechnung für Freunde und Reisen.
KI-Persönlichkeiten leiten Spiele und Eisbrecher-Fragen in Echtzeit, um Treffen und Partys unvergesslich zu machen.
人工甘味料や添加物のNG除外と有効成分あたりの実質単価比較データベース。