Kanji
・雲端架構工程師 / 自由職業 ・1993年出生 ・愛媛縣出身 / 現居東京都澀谷區 ・5年 AWS 實戰經驗 個人檔案詳情
目錄
在Mermaid中使用影象時,主要有兩種方法:“①使用 img 標籤指定影象URL”和“②使用圖示包”。下面介紹如何使用舊的AWS架構圖示。
img
參考: 如何在美人魚流程圖中更改節點形狀並指定影象/圖示#Beginner -奇塔
使用 Mermaid 的“img”標籤直接指定 AWS 圖示的 URL。
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
當在 Mermaid 中渲染時,它看起來像這樣:
另一種方法是使用美人魚圖示包。這樣就無需為每個圖示指定 URL。
參考:【在美人魚中註冊圖示包|美人魚](https://mermaid.js.org/config/icons.html)
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
但是,這種方法不能在 Qiita 或 GitHub 等 SaaS 平臺上使用。 要使用圖示包,您需要載入託管在 CDN 或伺服器上的 JSON 檔案,如下所示:
<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>
在此站點上,我們使用使用最新的 AWS 架構圖示建立的自定義圖示包。
要使用最新的 AWS 架構圖示,您需要建立自定義 Mermaid 圖示包。 本節介紹如何建立 Mermaid 圖示包並使用最新的 AWS 架構圖示。
首先,從以下站點下載最新的 AWS 架構圖示。 點選【開始】->【圖示包】開始下載。
AWS 簡單圖示 - AWS 架構中心 | AWS 簡單圖示AWS
下載的檔案當前名為“Asset-Package_02072025.dee42cd0a6eaacc3da1ad9519579357fb546f803.zip”。 解壓後,您將看到如下所示的資料夾結構。使用這些檔案建立您的美人魚圖示包。
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 └── ...
接下來,將以下 Python 指令碼儲存在適當的目錄中(例如“collect_mermaid_icons.py”)。 該指令碼僅使用標準庫:“re”、“os”、“json”和“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 } } }
完整的 icons.json 檔案(包含 780 多個 AWS 官方 SVG 圖示定義)可透過執行上述第 2 步的 collect_mermaid_icons.py 在本機數秒內產生。為確保頁面載入速度,上方僅展示核心服務(EC2、RDS、ELB、S3、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.
提供逼真 AI 模擬通話與多維反饋,結合 16 講實戰社交學院與工作室級 AI 肖像生成,全面提升社交互動品質。
拍發票即可完成高精度智慧拆單,支援 LINE 登入無縫結算團隊聚會支出,告別繁雜帳單分攤。
占卜師、管家、調酒師等 AI 角色即時引導話題與聚會遊戲,讓線下與線上聚餐氛圍瞬間升溫。
人工甘味料や添加物のNG除外と有効成分あたりの実質単価比較データベース。