add-astro-icon
GitHub将用户提供的原始SVG标记转换为Astro图标组件。自动命名文件,清理冗余属性,替换颜色为currentColor,添加Props接口,并写入website/src/icons/目录,支持通过Tailwind控制大小。
Trigger Scenarios
Install
npx skills add t4t5/rencal --skill add-astro-icon -g -y
SKILL.md
Frontmatter
{
"name": "add-astro-icon",
"description": "Turn raw SVG markup into an Astro icon component in website\/src\/icons\/. Use when the user provides SVG markup and wants it added as a website Astro icon."
}
You are turning raw SVG markup the user provides into an Astro icon component in website/src/icons/.
Workflow
-
Get the SVG: The user will give you raw SVG markup (often copy-pasted from Streamline, Figma, etc.).
-
Pick a filename: Use a short kebab-case name describing the icon (e.g.
settings.astro,arrow-right.astro). Infer obvious icon names without asking. For common brand logos, use the brand name (e.g. GitHub →github.astro). Ask the user only if the name is truly ambiguous. -
Transform the SVG:
-
Add this Astro frontmatter at the top:
--- interface Props { class?: string } const { class: className } = Astro.props --- -
On the
<svg>tag: keepxmlns,fill, andviewBox. Addclass={className}. Remove hardcodedwidthandheight— size is controlled by Tailwind (size-4,size-6, etc.). -
Replace every hardcoded stroke color (e.g.
stroke="#000000") withstroke="currentColor". Same forfillif it's a color — but leavefill="none"alone. Brand icons that should inherit text color should usefill="currentColor". -
Strip noise:
idattributes,<desc>tags,<title>tags, and any other vendor metadata. -
Keep
stroke-width,stroke-linecap,stroke-linejoin,d, and other geometry-defining attributes. Preserve valid Astro/HTML attribute casing for SVG markup.
-
-
Write the file to
website/src/icons/<name>.astroimmediately. Usebashwith a quoted heredoc instead of thewritetool to avoid slow line-by-line UI rendering:cat > website/src/icons/<name>.astro <<'EOF' ... EOF
Speed rules
- Do not inspect existing icon files unless necessary.
- Infer obvious icon names without asking.
- For common brand logos, use the brand name.
- Immediately write
website/src/icons/<name>.astroafter transforming. - Prefer
bashwith a quoted heredoc for file creation; do not use thewritetool unless bash is unavailable. - Do not run checks unless the user asks.
Example
Input:
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" id="Foo" height="24" width="24">
<desc>Some vendor blurb</desc>
<g id="group"><path id="p1" stroke="#000000" d="M6 0v14" stroke-width="2" /></g>
</svg>
Output (website/src/icons/foo.astro):
---
interface Props {
class?: string
}
const { class: className } = Astro.props
---
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class={className}>
<g>
<path stroke="currentColor" d="M6 0v14" stroke-width="2" />
</g>
</svg>
Usage: <FooIcon class="size-4 text-primary" /> when imported with an alias, or import the .astro component directly and render it with class="size-4 text-primary".
Version History
- 22a53df Current 2026-07-05 10:46


