Feedback

add-template

@tonnywong1052 Claim

Basic information

Repository
TonnyWong1052
Skill
add-template

About add-template

Add new UI style template to the ui-style-react project. This skill should be used when users want to add a new style template with HTML/CSS code, create a new preview page, or register a template in the system. Triggers include "add template", "create new style", "add new template", or when users provide HTML code for a new UI style.

add-template is an agent skill listed in the AddMCP.net directory, published by TonnyWong1052. Runtime: HTML. The repository has 419 GitHub stars. Source code is hosted on github.com.

Overview

What is add-template?


name: add-template description: Add new UI style template to the ui-style-react project. This skill should be used when users want to add a new style template with HTML/CSS code, create a new preview page, or register a template in the system. Triggers include "add template", "create new style", "add new template", or when users provide HTML code for a new UI style.


Add Template

Overview

This skill automates the complete workflow for adding new UI style templates to the ui-style-react project. It handles directory creation, file generation, and automatic registration in the preview system.

When to Use

  • When a user says "add new template" or "create style template"
  • When a user provides HTML/CSS code that should become a new template
  • When a user wants to add a new style to /styles/preview/ pages
  • When migrating templates from external sources

Quick Start

To add a new template, collect the following information:

| Parameter | Required | Description | Example | |-----------|----------|-------------|---------| | category | ✅ | Style category | visual, core, retro, interaction, layout | | familyId | ✅ | Family/group name | grain, glassmorphism, minimalism | | templateId | ✅ | Unique template ID | visual-grain-film-noir | | htmlContent | ✅ | Full HTML content | Complete <!DOCTYPE html> page | | cssContent | ✅ | CSS styles | Corresponding stylesheet | | titleZh | Optional | Chinese title | 胶片黑色风格 | | titleEn | Optional | English title | Film Noir Style | | setAsDefault | ✅ Default: true | Set new template as default (first in list) | true / false |

⭐ Default Template Behavior / 默认模板行为

By default, newly added templates are set as the default template (first in the list).

新添加的模板默认会被设置为默认模板(列表中的第一个)。

  • setAsDefault: true (默认) - 新模板显示在第一位,用户打开预览页面首先看到新模板
  • setAsDefault: false - 新模板添加到列表末尾

Workflow

### 🚨🚨🚨 CRITICAL RULES (READ FIRST!) 🚨🚨🚨 ### 关键规则(必须首先阅读!) **Rule 1: ALWAYS check existing templates BEFORE creating manifest.json** - List existing template directories in `public/data/content/styles/{category}/{familyId}/` - The number of templates in manifest.json MUST equal the number of directories **Rule 2: NEVER overwrite existing templates in manifest.json** - When adding to an existing family, READ the current manifest.json first - ADD your new template to the EXISTING templates array - Do NOT create a new templates array with only your template **Rule 3: New templates are DEFAULT by default (first position)** - Unless user specifies otherwise, place new template FIRST in the templates array - First template = default template shown when user opens preview page **Rule 4: Verify templatesCount after build** - After running build script, check that `templatesCount` matches expected value - If templatesCount is wrong, you likely forgot to include existing templates --- ### ⚠️ Pre-flight Checklist (MUST DO FIRST!) ### ⚠️ 预检清单(必须首先执行!) Before starting the workflow, **ALWAYS check for existing templates** in the target family: ```bash # 1. Check if family directory exists and list existing templates ls -la public/data/content/styles/{category}/{familyId}/ 2>/dev/null || echo "New family - no existing templates" # 2. Check existing manifest.json cat src/data/styles/generated/{category}/{familyId}/manifest.json 2>/dev/null | grep -A 30 '"templates"' || echo "No existing manifest" # 3. Count existing templates EXISTING_COUNT=$(ls -d public/data/content/styles/{category}/{familyId}/*/ 2>/dev/null | wc -l | tr -d ' ') echo "Existing templates: $EXISTING_COUNT" echo "Expected after adding: $((EXISTING_COUNT + 1))" ``` **Record the expected templatesCount** and verify it after Step 8! --- ### Step 1: Validate Parameters Verify all required parameters are provided: - `category` must be one of: `core`, `visual`, `retro`, `interaction`, `layout` - `familyId` should match existing family or be a new valid name - `templateId` should follow format: `{category}-{familyId}-{variant}` (kebab-case) - `htmlContent` should be a complete HTML document with `` - `cssContent` should contain valid CSS ### Step 2: Create Directory Structure Create the template directory: ``` public/data/content/styles/{category}/{familyId}/{templateId}/ ├── fullpage.html └── fullpage.css ``` Execute: ```bash mkdir -p public/data/content/styles/{category}/{familyId}/{templateId} ``` ### Step 3: Write Template Files Write `fullpage.html`: - Ensure the HTML links to `fullpage.css` with: `` - Remove any inline `

Interactive Mode

When parameters are incomplete, ask users step by step:

  1. Category Selection:

"Which category should this template belong to?"

  • core (Core design systems)
  • visual (Visual effects and styles)
  • retro (Retro/vintage styles)
  • interaction (Interactive elements)
  • layout (Layout patterns)
  1. Family ID:

"What family/group should this template belong to? (e.g., grain, glassmorphism, minimalism)"

  1. Template ID:

"What should the unique template ID be? Suggested format: {category}-{familyId}-{variant}"

  1. ⭐ Set as Default Template (默认模板设置):

"Should this template be the default (shown first when users open the preview page)?"

  • Yes (Recommended) - 设为默认,用户打开预览页首先看到此模板
  • No - 添加到列表末尾

Note: By default, new templates are set as the default template (first in list).

  1. HTML Content:

"Please provide the complete HTML content for the template."

  1. CSS Content:

"Please provide the CSS styles. If CSS is inline in the HTML, I'll extract it automatically."

Directory Structure Reference

ui-style-react/
├── public/
│   └── data/
│       └── content/
│           └── styles/
│               └── {category}/       # core, visual, retro, etc.
│                   └── {familyId}/   # grain, glassmorphism, etc.
│                       └── {templateId}/ # visual-grain-film-noir
│                           ├── fullpage.html
│                           └── fullpage.css
├── src/
│   ├── utils/
│   │   └── previewLoader.js          # Contains previewIdMapping
│   └── data/
│       └── metadata/
│           └── styleTagsMapping.js   # Contains styleEnhancements

Available Categories

| Category | Description | |----------|-------------| | core | Core design systems (minimalism, material design, flat design) | | visual | Visual effects (grain, glassmorphism, neon, gradients) | | retro | Retro/vintage styles (vaporwave, art deco, 80s) | | interaction | Interactive elements (mouse tracking, scroll effects) | | layout | Layout patterns (bento grids, masonry) |

向现有 Family 添加第二个/多个模板(关键!)

When adding a new template variant to an existing family (e.g., adding a second Vaporwave template), you must update the manifest.json file. This is the most common mistake!

当向现有 family 添加新模板变体时(例如:向 Vaporwave 添加第二个模板),必须更新 manifest.json 文件。这是最常见的错误!

Why This Matters / 为什么重要

The frontend reads the template list from manifest.json, NOT from the JS template file's previews array. If you only update the JS file but forget to update manifest.json, the new template will NOT appear in the preview selector.

前端从 manifest.json 读取模板列表,而不是从 JS 模板文件的 previews 数组。如果你只更新了 JS 文件而忘记更新 manifest.json,新模板将不会显示在预览选择器中。

Checklist for Adding Template to Existing Family

向现有 Family 添加模板的清单

  1. ✅ Create new template JS file (e.g., templates/visual/vaporwave/vaporwaveDreams.js)

创建新的模板 JS 文件

  1. ✅ Update family's index.js to import and add to previews array

更新 family 的 index.js,导入并添加到 previews 数组

  1. ✅ Add entry to previewIdMapping in src/utils/previewLoader.js

在 previewIdMapping 中添加条目

  1. ✅ Create content directory: public/data/content/styles/{category}/{familyId}/{templateId}/

创建内容目录(fullpage.html + fullpage.css)

  1. ⚠️ CRITICAL: Update manifest.json - Add new template to templates array:

⚠️ 关键:更新 manifest.json - 添加新模板到 templates 数组:

File: src/data/styles/generated/{category}/{familyId}/manifest.json

   {
     "templates": [
       {
         "id": "existing-template-id",
         "title": { "zh-CN": "现有模板", "en-US": "Existing Template" }
       },
       {
         "id": "new-template-id",
         "title": { "zh-CN": "新模板", "en-US": "New Template" }
       }
     ]
   }
  1. ✅ Run build script: node scripts/build-styles-index.js

运行构建脚本

  1. ✅ Verify templatesCount increased in public/data/styles-index.json

验证 templatesCount 已增加

Quick Verification / 快速验证

After adding a new template variant, check: 添加新模板变体后检查:

# Check manifest.json has multiple templates
# 检查 manifest.json 有多个模板
cat src/data/styles/generated/{category}/{familyId}/manifest.json | grep -A 20 '"templates"'

# Verify templatesCount in styles-index.json
# 验证 styles-index.json 中的 templatesCount
grep -A 5 '"familyId": "{familyId}"' public/data/styles-index.json | grep templatesCount

Common Issues

🚨 CI Test Failure: "Cannot find module" or "Missing content directories" (NEW!)

🚨 CI 测试失败:"Cannot find module" 或 "Missing content directories"(新!)

Symptoms / 症状:

  • CI/GitHub Actions fails with: Cannot find module '...'
  • CI fails with: Missing content directories for template
  • Tests pass locally but fail in CI
  • Files exist on your machine but CI can't find them

Root Cause / 根本原因: You created files locally but forgot to commit them to git! Untracked files (shown as ?? in git status) won't be pushed to the remote repository.

你在本地创建了文件,但忘记提交到 git!未追踪的文件(在 git status 中显示为 ??)不会被推送到远程仓库。

Solution / 解决方案:

# 1. Check for untracked files
git status

# 2. Stage the missing files
git add "public/data/content/styles/{category}/{familyId}/{templateId}/"
git add "src/data/styles/generated/{category}/{familyId}/manifest.json"
git add "public/data/compiled-jsx/*"  # If JSX template
git add "src/utils/*.js"              # If new utility files

# 3. Commit and push
git commit -m "🐛 fix: add missing template files"
git push

Prevention / 预防:

  • Always run git status before pushing
  • Follow Step 9 (Stage Files for Git) in this workflow
  • The success report includes a Git Status section - verify it!

🚨 JSX Runtime Error: "Unexpected token 'export'" (NEW!)

🚨 JSX 运行时错误:"Unexpected token 'export'"(新!)

Symptoms / 症状:

  • Preview shows: Runtime Error: Uncaught SyntaxError: Unexpected token 'export' (line XXX)
  • The line number matches the location of export default ComponentName; at the end of the file

Root Cause / 根本原因: The JSX file uses arrow function + separate export syntax, which the JSX compiler cannot process:

// ❌ This pattern causes the error:
const MyComponent = () => { ... };
export default MyComponent;  // ← This line is NOT stripped by compiler!

Solution / 解决方案: Convert to export default function syntax:

// ✅ Change to this:
export default function MyComponent() {
  // ... component code
}
// No separate export statement needed!

Technical Explanation / 技术说明: The JSX compiler (src/utils/jsxCompiler.js) uses this regex to match exports:

const exportMatch = processedCode.match(/export\s+default\s+function\s+(\w+)/);
processedCode = processedCode.replace(/export\s+default\s+function\s+/, 'function ');

It ONLY matches export default function Name, not export default Name (variable export).


🚨 CRITICAL BUG: Second/Multiple Templates Not Showing! (Most Common!)

🚨 关键 BUG:第二个/多个模板未显示!(最常见!)

This happens when you add a new template to an existing family but manifest.json only shows 1 template!

这发生在你添加新模板到现有 family 时,但 manifest.json 只显示 1 个模板!

Symptoms / 症状:

  • Preview page shows "Only 1 template available"
  • Dropdown/selector only has 1 template option
  • Expected 2+ templates, but only 1 shows
  • Build script shows templatesCount: 1 instead of 2

Root Cause / 根本原因: You replaced the existing templates array instead of adding to it.

Example of WRONG approach:

// ❌ WRONG: This deletes the original template!
"templates": [
  { "id": "visual-antiDesign-studio", "title": {...} }  // Lost the original!
]

Solution / 解决方案 (Do This NOW):

  1. Read the existing manifest.json and check what templates exist:
   cat src/data/styles/generated/{category}/{familyId}/manifest.json | grep -A 50 '"templates"'
  1. Edit manifest.json and ADD your new template to the existing array:
   "templates": [
     { "id": "visual-tech-anti-design", "title": {...} },      // ← EXISTING
     { "id": "visual-antiDesign-studio", "title": {...} }      // ← NEW (added)
   ]
  1. Rebuild the styles index:
   node scripts/build-styles-index.js
  1. Verify templatesCount increased:
   # Before: templatesCount: 1
   # After: templatesCount: 2
   grep -A 3 '"familyId": "{familyId}"' public/data/styles-index.json | grep templatesCount
  1. Restart dev server:
   npm run dev
  1. Check preview page - Should now show both templates!

⚠️ Second template not showing in preview selector (Most Common!)

⚠️ 第二个模板没有显示在预览选择器中(最常见!)

Cause / 原因: manifest.json was not updated with the new template entry. The frontend reads template list from manifest.json, not from the JS file's previews array.

manifest.json 没有更新新模板条目。前端从 manifest.json 读取模板列表,而不是从 JS 文件的 previews 数组。

Solution / 解决方案:

  1. Edit src/data/styles/generated/{category}/{familyId}/manifest.json
  2. Add new template to the templates array
  3. Run node scripts/build-styles-index.js
  4. Verify templatesCount is now correct (e.g., 2 instead of 1)
  5. Restart dev server

Example / 示例:

// Before (错误 - 只有1个模板)
"templates": [
  { "id": "visual-vaporwave-vaporwave-aesthetic", "title": {...} }
]

// After (正确 - 2个模板)
"templates": [
  { "id": "visual-vaporwave-vaporwave-aesthetic", "title": {...} },
  { "id": "visual-vaporwave-vaporwave-dreams", "title": {...} }
]

Template not showing in style list

Cause: templatesCount is 0 in public/data/styles-index.json

Solution:

  1. Ensure manifest.json exists at: src/data/styles/generated/{category}/{familyId}/manifest.json
  2. Manifest must be in correct JSON format with valid templates array
  3. Run build script: node scripts/build-styles-index.js
  4. Verify templatesCount is > 0 in public/data/styles-index.json

Template not showing in preview (404 error)

Cause: Preview route mapping or file path mismatch

Solutions:

  • Verify directory path matches exactly: public/data/content/styles/{category}/{familyId}/{templateId}/
  • Check that templateId in previewIdMapping matches the directory name exactly
  • Verify previewIdMapping entry is added correctly
  • Restart the dev server after making changes

CSS not loading in preview

Cause: Missing or incorrectly named CSS file

Solutions:

  • Ensure fullpage.html has: <link rel="stylesheet" href="fullpage.css">
  • Check that CSS file is named exactly fullpage.css
  • Verify CSS file is in the correct directory: public/data/content/styles/{category}/{familyId}/{templateId}/

Build script fails or shows ❌ for new family

Cause: manifest.json is missing or malformed

Solutions:

  1. Verify manifest.json exists and is valid JSON
  2. Check manifest structure matches the template in Step 6
  3. Ensure templates array is not empty
  4. Run build script again: node scripts/build-styles-index.js

Template ID conflicts

  • Use unique IDs following the pattern: {category}-{familyId}-{variant}
  • Check existing mappings before creating new ones
  • Verify no duplicate entries in previewIdMapping

自动化脚本(推荐!)

IMPORTANT: The project has a built-in create-template.js script that automates the entire workflow, including manifest.json update!

重要:项目有内置的 create-template.js 脚本,可以自动化整个工作流,包括自动更新 manifest.json!

Quick Usage / 快速使用

# Interactive mode (recommended) / 交互式模式(推荐)
npm run create-template

# Or with CLI parameters / 或使用命令行参数
npm run create-template -- \
  -c visual \
  -f vaporwave \
  -t visual-vaporwave-dreams \
  --title-zh "梦幻美学" \
  --title-en "Dreams Aesthetic"

What the Script Does Automatically / 脚本自动完成的工作

  1. ✅ Creates directory structure: public/data/content/styles/{category}/{family}/{templateId}/
  2. ✅ Generates HTML/CSS template files (demo.html, fullpage.html, etc.)
  3. ✅ Updates manifest.json - Adds new template to the templates array
  4. ✅ Updates styleTagsMapping.js - Adds template enhancement config
  5. ✅ Creates Prompt files (optional): custom.md and style.md

CLI Parameters / 命令行参数

| Parameter | Short | Description | Required | |-----------|-------|-------------|----------| | --category | -c | Category (core/visual/retro/interaction/layout) | ✅ | | --family | -f | Family name | ✅ | | --template-id | -t | Template ID (format: {category}-{family}-{variant}) | ✅ | | --title-zh | - | Chinese title | ❌ | | --title-en | - | English title | ❌ | | --format | - | File format (html/jsx) | ❌ | | --skip-prompts | - | Skip Prompt file creation | ❌ |

Examples / 示例

# Add second template to existing vaporwave family
# 向现有 vaporwave family 添加第二个模板
npm run create-template -- \
  -c visual \
  -f vaporwave \
  -t visual-vaporwave-neon-city \
  --title-zh "霓虹都市" \
  --title-en "Neon City"

# JSX format template
# JSX 格式模板
npm run create-template -- \
  -c visual \
  -f glassmorphism \
  -t visual-glassmorphism-dashboard \
  --title-zh "仪表板" \
  --title-en "Dashboard" \
  --format jsx

# Skip Prompt files
# 跳过 Prompt 文件
npm run create-template -- \
  -c retro \
  -f arcadeCRT \
  -t retro-arcadeCRT-game-ui \
  --title-zh "游戏界面" \
  --title-en "Game UI" \
  --skip-prompts

After Running the Script / 脚本运行后

  1. Edit template files - Add your actual HTML/CSS content

编辑模板文件 - 添加实际的 HTML/CSS 内容

  1. Run build script - Regenerate styles index

运行构建脚本 - 重新生成样式索引

   node scripts/build-styles-index.js
  1. Add to previewIdMapping - If preview route is needed

添加到 previewIdMapping - 如果需要预览路由

   // src/utils/previewLoader.js
   '{templateId}': { category: '{category}', familyId: '{familyId}', templateId: '{templateId}' },
  1. Restart dev server and test

重启开发服务器并测试

   npm run dev

Script Architecture / 脚本架构

scripts/
├── create-template.js          # Main CLI entry point
└── lib/
    ├── interactive.js          # Interactive input logic
    ├── generators.js           # File template generators
    ├── metadata-updater.js     # manifest.json & styleTagsMapping.js updater
    └── validator.js            # Input validators

Resources

references/

See references/existing-families.md for a complete list of existing family IDs and their descriptions.

scripts/

  • scripts/create-template.js - Main template creation script (recommended!)
  • scripts/build-styles-index.js - Rebuild styles-index.json after changes
  • scripts/README.md - Full documentation for the create-template script

Comments

No comments yet

Be the first to share feedback about this listing. Sign in to leave a comment.

Sign In

Feedback 💬