refactor(tools): modularize CLI with urfave/cli/v2, externalise template metadata

- Split monolithic build-preview.go into modular packages:
  tools.go (entry), cli/ (list/create/delete/preview commands),
  config/ (JSON loading), preview/ (rendering engine, funcs, locale)
- Extract all template metadata into data/templates_config.json
  as single source of truth — no hardcoded template data in Go
- Replace hand-rolled CLI parsing with github.com/urfave/cli/v2
- Add sensible defaults for --folder (../themes) and --config
  (./data/templates_config.json) — most commands now run bare
- Add type-coercing gt/lt/ge/le template funcs for JSON float64
- Fix AppUrl to gitea.com matching official template convention
- rendered.js now exports __REGISTRY__ and __PARAMS__ alongside
  __RENDERED__ — preview/index.html reads all from single source
- Cross-validate all 11 template data contexts against official
  Gitea source (services/mailer/*.go + templates/mail/*.tmpl)
- Update all docs (README, AGENTS, CONTRIBUTING, 5 languages)
  to reflect new CLI workflow with create scaffolding command

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
KenanZhuandClaude Opus 4.8 committed 2026-06-04 12:26:44 +08:00
1 parent 77854ee0ed
commit 0bf982ffb9
30 files changed
+1274 -540

No files matched your search

+31 -18
View File
@@ -7,15 +7,24 @@ A curated collection of email template themes (10 visual styles) for self-hosted
## Repository Layout
```
themes/ # Template themes (5 styles, 11 .tmpl each = 55 source files)
horizon/ # Enterprise / Corporate
terminal/ # Developers / Tech
ember/ # Community / Open Source
themes/ # Template themes (10 styles, 11 .tmpl each = 110 source files)
aurora/ # Ethereal / Dreamlike
bloom/ # Creative / Startup (glassmorphism)
ember/ # Community / Open Source
heritage/ # Education / Research
tools/ # Go build tooling
build-preview.go # Pre-renders all templates into preview/rendered.js
go.mod # Go module (stdlib only, zero dependencies)
horizon/ # Enterprise / Corporate
ink/ # Editorial / Publishing
mono/ # Minimal / Swiss design
neon/ # Cyberpunk / Gaming
terminal/ # Developers / Tech
terra/ # Nature / Sustainability
tools/ # Go CLI tooling (modular, zero dependencies)
tools.go # Main entry point
cli/ # CLI subcommands: list, create, delete, preview
config/ # Config types and templates_config.json loading
data/ # templates_config.json — single source of truth for template metadata
preview/ # Template rendering engine (funcs, locale, engine)
go.mod # Go module (stdlib only, zero dependencies)
preview/ # Browser-based live preview
index.html # SPA with style/template/client/viewport switching
rendered.js # Pre-rendered HTML (generated, committed for clone-and-preview)
@@ -32,30 +41,34 @@ docs/ # Multi-language documentation
- Each style must have all 11 template types
### Adding a New Theme
1. Create `themes/<name>/` with the full `mail/` directory structure
1. Scaffold the new theme: `cd tools && go run . create <name>` — creates the full directory structure with placeholder `.tmpl` files for all 11 email types
2. Write all 11 `.tmpl` files with unique visual design
3. Run `go run ./tools/build-preview.go` to regenerate preview data
4. Add the theme to the `<select id="sel-theme">` in `preview/index.html`
5. Update README.md style gallery table
3. Run `cd tools && go run . preview all` to regenerate preview data
4. Update README.md style gallery table
### Preview System
- `preview/index.html` loads `preview/rendered.js` (pre-rendered by Go) and displays in iframes
- Supports theme switching, template type switching, client simulation (Modern/Gmail/Outlook/Raw), and viewport toggle (Desktop 1386x780 / Mobile 390x780)
- Entries in `REGISTRY` and `PARAMS` objects must match the Go build script's template definitions
- `REGISTRY` and `PARAMS` are auto-generated from `templates_config.json` by the build tool — no manual syncing needed
### Build Script
- `tools/build-preview.go` uses Go's native `html/template` package
- Defines mock data for each template type matching Gitea's actual data contexts
- Post-processes favicon URLs for preview display
- Zero external dependencies (stdlib only)
### Build Tool
- `tools/tools.go` is the main entry point for the modular CLI
- Subcommands: `list`, `create`, `delete`, `preview`
- Template metadata lives in `tools/data/templates_config.json` — the single source of truth
- `tools/config/` handles config loading and data flattening
- `tools/preview/` implements the rendering engine (template funcs, locale, engine)
- `tools/cli/` implements CLI subcommands using `github.com/urfave/cli/v2`
- Uses Go's native `html/template` package for template rendering
## Commit Conventions
- `style(name):` — template changes for a specific theme
- `preview:` — preview tooling changes
- `tools:` — Go build script changes
- `tools:` — Go CLI/build tooling changes
- `docs:` — documentation and translations
- `fix:` — bug fixes
- `project:` — README, LICENSE, AGENTS.md, meta
- `refactor:` — code restructuring (e.g. modularization)
- `chore:` — maintenance (config updates, build scripts)
## Constraints
- No JavaScript framework dependencies — preview is vanilla JS