@donotdev/cli 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dependencies-matrix.json +100 -50
  2. package/dist/bin/commands/agent-setup.js +245 -12
  3. package/dist/bin/commands/build.js +3339 -208
  4. package/dist/bin/commands/bump.js +245 -12
  5. package/dist/bin/commands/cacheout.js +245 -12
  6. package/dist/bin/commands/coach.js +361 -60
  7. package/dist/bin/commands/create-app.js +245 -12
  8. package/dist/bin/commands/create-project.js +253 -12
  9. package/dist/bin/commands/db.js +9114 -2327
  10. package/dist/bin/commands/deploy.js +4074 -694
  11. package/dist/bin/commands/dev.js +347 -33
  12. package/dist/bin/commands/doctor.js +408 -107
  13. package/dist/bin/commands/emu.js +386 -52
  14. package/dist/bin/commands/format.js +245 -12
  15. package/dist/bin/commands/get-demo.js +245 -12
  16. package/dist/bin/commands/make-admin.js +8356 -1516
  17. package/dist/bin/commands/preview.js +347 -33
  18. package/dist/bin/commands/seed.js +9114 -2327
  19. package/dist/bin/commands/setup-cicd.js +452 -132
  20. package/dist/bin/commands/setup.js +407 -107
  21. package/dist/bin/commands/staging.js +4074 -694
  22. package/dist/bin/commands/sync-secrets.js +246 -13
  23. package/dist/bin/commands/type-check.js +245 -12
  24. package/dist/bin/commands/wai.js +245 -12
  25. package/dist/bin/dndev.js +13 -4
  26. package/dist/bin/donotdev.js +13 -4
  27. package/dist/index.js +4169 -812
  28. package/{templates/root-consumer/guides/dndev/advanced/VERSION_CONTROL.md.example → guidelines/VERSION_CONTROL.md} +7 -11
  29. package/package.json +2 -1
  30. package/templates/app-demo/src/themes.css.example +21 -0
  31. package/templates/app-dndev/index.html.example +0 -3
  32. package/templates/app-dndev/src/themes.css.example +21 -0
  33. package/templates/app-next/src/app/layout.tsx.example +13 -4
  34. package/templates/app-next/src/themes.css.example +21 -0
  35. package/templates/app-vite/csp.example.json +44 -0
  36. package/templates/app-vite/index.html.example +0 -3
  37. package/templates/app-vite/src/themes.css.example +21 -0
  38. package/templates/functions-supabase/supabase/migrations/20250101000000_idempotency.sql +3 -0
  39. package/templates/functions-supabase/supabase/migrations/20250101000001_rate_limits.sql +3 -0
  40. package/templates/functions-supabase/supabase/migrations/20250101000003_operation_metrics.sql +3 -0
  41. package/templates/root-consumer/.claude/hooks/framework-compliance.sh.example +56 -0
  42. package/templates/root-consumer/.claude/hooks/guard-bash.sh.example +61 -0
  43. package/templates/root-consumer/.claude/hooks/guard-files.sh.example +46 -0
  44. package/templates/root-consumer/.claude/hooks/guard-mcp.sh.example +91 -0
  45. package/templates/root-consumer/.claude/hooks/guard-secrets.sh.example +67 -0
  46. package/templates/root-consumer/.claude/hooks/guard-write.sh.example +89 -0
  47. package/templates/root-consumer/.claude/hooks/session-start.sh.example +50 -0
  48. package/templates/root-consumer/.claude/hooks/track-mcp-lookup.sh.example +20 -0
  49. package/templates/root-consumer/.claude/hooks/typecheck-stop.sh.example +18 -0
  50. package/templates/root-consumer/.claude/rules/consumer-ux.md.example +32 -0
  51. package/templates/root-consumer/.claude/rules/definition-of-done.md.example +32 -0
  52. package/templates/root-consumer/.claude/rules/framework.md.example +39 -0
  53. package/templates/root-consumer/.claude/rules/git.md.example +14 -0
  54. package/templates/root-consumer/.claude/rules/security.md.example +13 -0
  55. package/templates/root-consumer/.claude/settings.json.example +123 -1
  56. package/templates/root-consumer/.claude/skills/build/SKILL.md.example +103 -25
  57. package/templates/root-consumer/.claude/skills/grill/SKILL.md.example +26 -15
  58. package/templates/root-consumer/.claude/skills/polish/SKILL.md.example +50 -37
  59. package/templates/root-consumer/AI.md.example +2 -2
  60. package/templates/root-consumer/CLAUDE.md.example +33 -1
  61. package/templates/root-consumer/guides/dndev/INDEX.md.example +23 -27
  62. package/templates/root-consumer/guides/dndev/SETUP_AUTH.md.example +3 -2
  63. package/templates/root-consumer/guides/dndev/SETUP_OAUTH.md.example +10 -5
  64. package/templates/root-consumer/guides/dndev/SETUP_SUPABASE.md.example +50 -3
  65. package/templates/root-consumer/guides/wai-way/blueprints/3_compose.md.example +13 -15
  66. package/templates/app-demo/public/manifest.json.example +0 -10
  67. package/templates/app-dndev/public/manifest.json.example +0 -10
  68. package/templates/root-consumer/.claude/commands/brainstorm.md.example +0 -175
  69. package/templates/root-consumer/.claude/commands/build.md.example +0 -131
  70. package/templates/root-consumer/.claude/commands/design.md.example +0 -184
  71. package/templates/root-consumer/.claude/commands/grill.md.example +0 -135
  72. package/templates/root-consumer/.claude/commands/polish.md.example +0 -146
  73. package/templates/root-consumer/.claude/commands/techdebt.md.example +0 -28
  74. package/templates/root-consumer/guides/dndev/COMPONENTS_ATOMIC.md.example +0 -180
  75. package/templates/root-consumer/guides/dndev/COMPONENTS_CRUD.md.example +0 -234
  76. package/templates/root-consumer/guides/dndev/COMPONENTS_UI.md.example +0 -136
  77. package/templates/root-consumer/guides/dndev/COMPONENT_API.md.example +0 -195
  78. package/templates/root-consumer/guides/dndev/ENV_SETUP.md.example +0 -219
  79. package/templates/root-consumer/guides/dndev/GOTCHAS.md.example +0 -197
  80. package/templates/root-consumer/guides/dndev/SETUP_APP_CONFIG.md.example +0 -132
  81. package/templates/root-consumer/guides/dndev/SETUP_BLOG.md.example +0 -280
  82. package/templates/root-consumer/guides/dndev/SETUP_CICD.md.example +0 -115
  83. package/templates/root-consumer/guides/dndev/SETUP_CRUD.md.example +0 -334
  84. package/templates/root-consumer/guides/dndev/SETUP_FUNCTIONS.md.example +0 -9
  85. package/templates/root-consumer/guides/dndev/SETUP_I18N.md.example +0 -233
  86. package/templates/root-consumer/guides/dndev/SETUP_LAYOUTS.md.example +0 -158
  87. package/templates/root-consumer/guides/dndev/SETUP_PAGES.md.example +0 -205
  88. package/templates/root-consumer/guides/dndev/SETUP_PWA.md.example +0 -213
  89. package/templates/root-consumer/guides/dndev/SETUP_TESTING.md.example +0 -184
  90. package/templates/root-consumer/guides/dndev/SETUP_THEMES.md.example +0 -111
  91. package/templates/root-consumer/guides/dndev/SETUP_VERCEL.md.example +0 -260
  92. package/templates/root-consumer/guides/dndev/USE_ROUTING.md.example +0 -499
  93. package/templates/root-consumer/guides/dndev/essences_reference.css.example +0 -288
@@ -1,197 +0,0 @@
1
- # Framework Gotchas
2
-
3
- **Common mistakes. Read before coding. Phase tags show when each matters most.**
4
-
5
- ---
6
-
7
- ## Imports [Phase 1, 2, 3]
8
-
9
- **Server code MUST use `/server` imports — client imports crash on deploy.**
10
-
11
- ```typescript
12
- // ✅ CORRECT
13
- import { getFirebaseAdminFirestore } from '@donotdev/firebase/server';
14
- import { handleError } from '@donotdev/core/server';
15
-
16
- // ❌ WRONG - crashes on deploy
17
- import { getFirestore } from '@donotdev/firebase';
18
- import { handleError } from '@donotdev/core';
19
- ```
20
-
21
- **Rule:** Always use `/server` suffix for `@donotdev/core/server`, `@donotdev/firebase/server`, `@donotdev/security/server`.
22
-
23
- **ESM only — never use `require()`.**
24
-
25
- ```typescript
26
- // ❌ WRONG
27
- const { something } = require('@donotdev/package');
28
-
29
- // ✅ CORRECT
30
- import { something } from '@donotdev/package';
31
- ```
32
-
33
- **Import ordering is mandatory:**
34
- 1. React (values, then types)
35
- 2. Other vendors (values, then types)
36
- 3. `@donotdev/*` packages (values, then types)
37
- 4. Relative imports (values, then types)
38
-
39
- One line for values, one line for types. Blank line between categories.
40
-
41
- ---
42
-
43
- ## Routing [Phase 1, 3]
44
-
45
- **Never import from `react-router-dom` — use framework routing.**
46
-
47
- ```tsx
48
- // ❌ WRONG - breaks framework features
49
- import { Link, useNavigate, useParams } from 'react-router-dom';
50
-
51
- // ✅ CORRECT
52
- import { Link, useNavigate, useParams } from '@donotdev/ui';
53
- ```
54
-
55
- **Routes are auto-discovered** from `src/pages/*Page.tsx` with `pageMeta`. Don't use `<Routes>`, `<Route>`, or manual `<Outlet />`.
56
-
57
- **Use `useRouteParam('id')` for typed route params** — not `useParams()` from react-router-dom.
58
-
59
- **Navigation is auto-built.** Use `<DnDevNavigationMenu>` or `useNavigationItems()`. Don't build nav manually — you lose auth filtering and route discovery.
60
-
61
- ---
62
-
63
- ## Styling [Phase 3, 4]
64
-
65
- **No inline `fontSize` or `font-size` — use `Text` level prop.**
66
-
67
- ```tsx
68
- // ❌ WRONG
69
- <Text style={{ fontSize: '18px' }}>Title</Text>
70
-
71
- // ✅ CORRECT
72
- <Text level="h2">Title</Text>
73
- ```
74
-
75
- Levels: `h1`, `h2`, `h3`, `h4`, `body`, `small`, `caption`. Limit to 2–3 levels per page.
76
-
77
- **RTL: Always use `start`/`end` — never `left`/`right`.**
78
-
79
- ```css
80
- /* ❌ WRONG - breaks RTL */
81
- text-align: left;
82
-
83
- /* ✅ CORRECT - works in both LTR and RTL */
84
- text-align: start;
85
- ```
86
-
87
- Same for inline styles: `textAlign: 'start'` not `textAlign: 'left'`. Same for data attributes: `data-text-align="start|center|end"`.
88
-
89
- ---
90
-
91
- ## Components [Phase 3]
92
-
93
- **Always `lookup_symbol` before using any `@donotdev` component.** Never guess props.
94
-
95
- Common wrong props:
96
- - `Button`: no `size`, `tone`, `gap` — use `variant`, `display`
97
- - `Text`: no `size`, `tone`, `color` — use `level`, `variant`
98
- - `Stack`: no `spacing`, `size` — use `gap`
99
- - `Card`: no `padding`, `margin`, `size` — use `title`, `subtitle`, `content`, `footer`
100
- - `Grid`: no `columns` — use `cols`
101
-
102
- **If you can't do it with framework components:** Stop. Tell the user what's missing. Don't invent custom workarounds.
103
-
104
- ---
105
-
106
- ## CRUD [Phase 2, 3]
107
-
108
- **Hidden fields are auto-added by `defineEntity()` — don't define them manually:**
109
- - `id`, `createdAt`, `updatedAt`, `createdById`, `updatedById`
110
-
111
- **Status field — extend, don't redefine.**
112
- The `status` field is auto-added with locked `visibility: 'admin'`, `editable: 'admin'`, `type: 'select'`. Only `validation.options` can be extended.
113
-
114
- ```typescript
115
- // ❌ WRONG - these properties are silently ignored
116
- status: { type: 'select', visibility: 'owner', editable: 'admin', validation: { options: [...] } }
117
-
118
- // ✅ CORRECT - only extend options (merged after defaults: draft, available, deleted)
119
- status: { validation: { options: [{ value: 'shipped', label: 'Shipped' }] } }
120
- ```
121
-
122
- **Scope field is auto-added** when `scope` is configured. Don't manually define the scope field (e.g., `companyId`).
123
-
124
- **Custom form fields MUST use framework's `useController`:**
125
-
126
- ```typescript
127
- // ❌ WRONG
128
- import { useController } from 'react-hook-form';
129
-
130
- // ✅ CORRECT
131
- import { useController } from '@donotdev/crud';
132
- ```
133
-
134
- **Form components receive `control` prop, not `field` prop.**
135
-
136
- **Price field is structured:** `{ amount, currency, vatIncluded, discountPercent }`. Don't store computed discount amounts.
137
-
138
- **File uploads are deferred** — files upload on form submit, not on selection. Images show optimistic blob URLs.
139
-
140
- **Entity namespace defaults to `entity-{name}`** (lowercase). Translation files must match: `locales/entity-product_en.json`.
141
-
142
- ---
143
-
144
- ## Functions [Phase 3, 4]
145
-
146
- **Use `createFunction` for custom functions — 3 params, everything included:**
147
-
148
- ```typescript
149
- import { createFunction } from '@donotdev/functions/firebase';
150
-
151
- export const myFunction = createFunction(schema, 'operation_name', async (data, { uid }) => {
152
- // Your logic
153
- });
154
- ```
155
-
156
- **Use `createBaseFunction` only when you need custom config** (memory, timeout, region override).
157
-
158
- **Deploy with `dndev deploy`** — not `firebase deploy`. Manual deploy causes CORS 403 on preflight because Cloud Run blocks unauthenticated OPTIONS by default.
159
-
160
- **Naming:** Export in camelCase (`getDashboardMetrics`), operation ID in snake_case (`get_dashboard_metrics`).
161
-
162
- **CRUD functions are one-liner:** `export const crud = createCrudFunctions(entities);` — generates all CRUD endpoints per entity. Access controlled via `entity.access`.
163
-
164
- ---
165
-
166
- ## i18n [Phase 3, 4]
167
-
168
- **Phase 3: hardcode strings. Phase 4: add translations.** Don't i18n too early.
169
-
170
- **Two loading strategies:**
171
- - **Eager** (always loaded): `src/locales/common_en.json` — navigation, buttons, common UI
172
- - **Lazy** (loaded per page): `src/pages/locales/home_en.json` — page-specific content
173
-
174
- **Status field translations** fall back: `entity-{name}` namespace → `crud` namespace.
175
-
176
- **Rich text uses `<Trans>` component** with supported tags only: `<accent>`, `<primary>`, `<muted>`, `<success>`, `<warning>`, `<error>`, `<bold>`, `<code>`.
177
-
178
- **Array translations use `tList`:**
179
- ```tsx
180
- import { tList } from '@donotdev/ui';
181
- <Card content={tList(t, 'features.items', 4)} />
182
- ```
183
-
184
- ---
185
-
186
- ## Dependencies [Phase 1]
187
-
188
- **Apps don't declare bundled deps.** Framework packages (`@donotdev/*`) provide everything. Don't add `react-router-dom`, `react-hook-form`, `valibot`, etc. to app's `package.json` — they come through framework deps.
189
-
190
- **Environment variables:**
191
- - Client: `apps/my-app/.env` (prefix with `VITE_*`)
192
- - Server: `functions/.env` (secrets: `STRIPE_*`, OAuth tokens)
193
- - Local overrides: `.env.local` (gitignored)
194
-
195
- ---
196
-
197
- **When in doubt: search the codebase first, ask the user second, never guess.**
@@ -1,132 +0,0 @@
1
- # Configuration Setup
2
-
3
- **For AI Agents:** Configure `src/config/app.ts` and `vite.config.ts`. Framework handles the rest.
4
-
5
- ---
6
-
7
- ## 1. App Configuration
8
-
9
- ```typescript
10
- // src/config/app.ts
11
- import type { AppConfig } from '@donotdev/core';
12
-
13
- export const appConfig: AppConfig = {
14
- app: {
15
- name: 'My App',
16
- shortName: 'App', // Required for PWA
17
- description: 'My app description', // Required for PWA
18
- url: 'https://myapp.com',
19
- },
20
-
21
- preset: 'landing', // landing | admin | moolti | docs | blog | game | plain
22
-
23
- features: {
24
- debug: false, // Enable debug tools
25
- requiredCookies: ['necessary'], // Cookie consent categories
26
- },
27
-
28
- auth: {
29
- authRoute: '/login',
30
- roleRoute: '/404',
31
- tierRoute: '/404',
32
- loginPath: '/login',
33
- profilePath: '/profile',
34
- },
35
-
36
- i18n: {
37
- defaultLanguage: 'en',
38
- fallbackLanguage: 'en',
39
- },
40
-
41
- theme: {
42
- defaultTheme: 'light',
43
- },
44
- };
45
- ```
46
-
47
- ---
48
-
49
- ## 2. Vite Configuration
50
-
51
- ```typescript
52
- // vite.config.ts
53
- import { defineViteConfig } from '@donotdev/core/vite';
54
- import { appConfig } from './src/config/app';
55
-
56
- export default defineViteConfig({
57
- appConfig, // Required
58
- });
59
- ```
60
-
61
- **Done.** Routes, themes, and translations are automatically detected from your `src/` directory.
62
-
63
- ---
64
-
65
- ## 3. Optional Vite Options
66
-
67
- ```typescript
68
- export default defineViteConfig({
69
- appConfig,
70
-
71
- // Debug
72
- debug: true,
73
- verbose: true,
74
-
75
- // Debug options
76
- routes: { debug: true },
77
- themes: { debug: true },
78
- i18n: { debug: true },
79
-
80
- // Server
81
- server: {
82
- port: 3000,
83
- https: true,
84
- },
85
-
86
- // Build
87
- build: {
88
- sourcemap: false,
89
- },
90
-
91
- // SEO
92
- seo: {
93
- disabled: false,
94
- generateRobotsTxt: true,
95
- generateSitemap: true,
96
- },
97
-
98
- // PWA (see SETUP_PWA.md for full guide)
99
- pwa: {
100
- enabled: false, // Enable PWA in production
101
- devEnabled: false, // Enable PWA in development (optional)
102
- },
103
- });
104
- ```
105
-
106
- ---
107
-
108
- ## 4. Environment Variables
109
-
110
- **Vite loads `.env` from the app directory only.** Not the repo root.
111
-
112
- Run `dndev coach` to see what to configure, then `dndev setup` to validate and automate. See [SETUP_FIREBASE.md](./SETUP_FIREBASE.md).
113
-
114
- ```bash
115
- # apps/<your-app>/.env — client-side variables (exposed to browser)
116
- VITE_APP_URL=http://localhost:5173
117
- VITE_DONOTDEV_LICENSE_KEY=dndev_your_key_here
118
- VITE_FIREBASE_API_KEY=... # Written by dndev setup
119
- VITE_FIREBASE_PROJECT_ID=... # Written by dndev setup
120
- VITE_AUTH_PARTNERS=github,google
121
- VITE_STRIPE_PUBLISHABLE_KEY=pk_test_...
122
-
123
- # functions/.env — server-side secrets (never exposed to browser)
124
- STRIPE_SECRET_KEY=sk_test_...
125
- STRIPE_WEBHOOK_SECRET=whsec_...
126
- ```
127
-
128
- Push server secrets to Firebase: `dndev sync-secrets`
129
-
130
- ---
131
-
132
- **Zero config. Override when needed.**
@@ -1,280 +0,0 @@
1
- # Setup: Blog
2
-
3
- **Convention-based markdown blog.** Drop `slug_lang.md` files in `src/content/blog/`, get a fully functional blog with i18n, reading time, tags, RSS, and sitemap.
4
-
5
- ---
6
-
7
- ## Quick Start
8
-
9
- ### 1. Create the content directory
10
-
11
- ```
12
- src/content/blog/
13
- ├── my-first-post_en.md
14
- ├── my-first-post_fr.md
15
- └── another-post_en.md
16
- ```
17
-
18
- ### 2. Write a post with frontmatter
19
-
20
- ```markdown
21
- ---
22
- title: My First Post
23
- description: A short summary for listings and SEO
24
- date: 2025-06-01
25
- tags: tutorial, getting-started
26
- image: /blog/my-first-post.png
27
- ---
28
-
29
- Your markdown content here. Supports:
30
- - **Bold**, *italic*, ~~strikethrough~~
31
- - [Internal links](/faq) and [external links](https://example.com)
32
- - Images: ![alt text](/blog/my-image.png)
33
- - Code blocks with syntax highlighting
34
- ```
35
-
36
- ### 3. Create the data loader
37
-
38
- ```typescript
39
- // src/data/blog/index.ts
40
- import { createBlogLoader } from '@donotdev/templates';
41
- import type { BlogLoader } from '@donotdev/templates';
42
-
43
- const markdownFiles = import.meta.glob('../../content/blog/*.md', {
44
- query: '?raw',
45
- import: 'default',
46
- eager: true,
47
- });
48
-
49
- export function getBlogLoader(lang: string = 'en'): BlogLoader {
50
- return createBlogLoader(markdownFiles as Record<string, string>, lang);
51
- }
52
- ```
53
-
54
- ### 4. Create the listing page
55
-
56
- ```typescript
57
- // src/pages/BlogPage.tsx
58
- import { BookOpen } from 'lucide-react';
59
- import { HeroSection } from '@donotdev/components';
60
- import { useTranslation, type PageMeta } from '@donotdev/core';
61
- import { BlogList } from '@donotdev/templates';
62
- import { PageContainer } from '@donotdev/ui';
63
- import { getBlogLoader } from '../data/blog';
64
-
65
- export const NAMESPACE = 'blog';
66
- export const meta: PageMeta = { namespace: NAMESPACE, icon: <BookOpen /> };
67
-
68
- export default function BlogPage() {
69
- const { t, i18n } = useTranslation([NAMESPACE]);
70
- const posts = getBlogLoader(i18n?.language).getAllPosts();
71
-
72
- return (
73
- <PageContainer variant="docs">
74
- <HeroSection title={t('title')} subtitle={t('subtitle')} />
75
- <BlogList posts={posts} />
76
- </PageContainer>
77
- );
78
- }
79
- ```
80
-
81
- ### 5. Create the post page (dynamic route)
82
-
83
- ```typescript
84
- // src/pages/BlogPostPage.tsx
85
- import { BookOpen } from 'lucide-react';
86
- import { useTranslation, type PageMeta } from '@donotdev/core';
87
- import { BlogPostView } from '@donotdev/templates';
88
- import { PageContainer, useRouteParam } from '@donotdev/ui';
89
- import { getBlogLoader } from '../data/blog';
90
-
91
- export const NAMESPACE = 'blog';
92
- export const meta: PageMeta = {
93
- namespace: NAMESPACE,
94
- icon: <BookOpen />,
95
- route: '/blog/:slug',
96
- hideFromMenu: true,
97
- };
98
-
99
- export default function BlogPostPage() {
100
- const { i18n } = useTranslation([NAMESPACE]);
101
- const slug = useRouteParam('slug');
102
- const post = slug ? getBlogLoader(i18n?.language).getPostBySlug(slug) : null;
103
-
104
- return (
105
- <PageContainer variant="docs">
106
- <BlogPostView post={post} />
107
- </PageContainer>
108
- );
109
- }
110
- ```
111
-
112
- ### 6. Add locale files
113
-
114
- Blog UI labels (`readMore`, `backToBlog`, `publishedOn`, etc.) are provided by the framework via `blog_*.json` in `@donotdev/core`. Override any key by creating the same file in your app.
115
-
116
- Page-specific strings (title, subtitle) go in your app locale:
117
-
118
- ```json
119
- // src/pages/locales/blog_en.json
120
- {
121
- "title": "Blog",
122
- "subtitle": "Your subtitle here"
123
- }
124
- ```
125
-
126
- ---
127
-
128
- ## File Convention
129
-
130
- **Pattern:** `slug_lang.md`
131
-
132
- | File | Slug | Language |
133
- |------|------|----------|
134
- | `my-post_en.md` | `my-post` | English |
135
- | `my-post_fr.md` | `my-post` | French |
136
- | `my-post_de.md` | `my-post` | German |
137
- | `solo-post_en.md` | `solo-post` | English (no FR = falls back to EN) |
138
-
139
- **Rules:**
140
- - Slug = everything before the last `_xx` suffix
141
- - Language suffix must be 2-5 characters (ISO codes)
142
- - English (`_en`) is the fallback language
143
- - If a post only exists in `_en`, it's shown for all languages
144
-
145
- ---
146
-
147
- ## Frontmatter Fields
148
-
149
- | Field | Required | Description |
150
- |-------|----------|-------------|
151
- | `title` | Yes | Post title |
152
- | `description` | Yes | Summary for listings and SEO |
153
- | `date` | Yes | Publication date (YYYY-MM-DD) |
154
- | `tags` | No | Comma-separated tags |
155
- | `image` | No | Hero image path — must be in `public/blog/` (see Images section) |
156
-
157
- Custom fields are preserved in `meta[key]`.
158
-
159
- ---
160
-
161
- ## Images
162
-
163
- ### Hero Images (frontmatter `image` field)
164
-
165
- One image per post. Used in blog listing cards, article page, RSS feed, and OG/social sharing.
166
-
167
- **Convention:**
168
- - **Location:** `public/blog/[slug].png` (matches the post slug)
169
- - **Size:** 1200×630px minimum (standard OG ratio, sharp on retina)
170
- - **Format:** PNG or JPG
171
- - **Reference:** `image: /blog/my-post.png` in frontmatter
172
-
173
- ```
174
- public/
175
- └── blog/
176
- ├── my-first-post.png ← matches my-first-post_en.md
177
- ├── another-post.png ← matches another-post_en.md
178
- └── inline-diagram.svg ← used in markdown body
179
- ```
180
-
181
- **Where it shows:**
182
- | Context | Sizing |
183
- |---------|--------|
184
- | Blog listing (featured card) | `width: 100%`, `max-height: 360px`, `object-fit: cover` |
185
- | Blog listing (grid cards) | `width: 100%`, `max-height: 180px`, `object-fit: cover` |
186
- | Article page | `width: 100%`, `max-height: 480px`, `object-fit: cover` |
187
- | RSS feed | `<enclosure>` with full URL |
188
-
189
- ### Inline Images (in markdown body)
190
-
191
- Images referenced in markdown content also go in `public/blog/`:
192
-
193
- ```markdown
194
- ![Architecture diagram](/blog/inline-diagram.svg)
195
- ```
196
-
197
- Rendered with `loading="lazy"` and `decoding="async"`.
198
-
199
- **Co-located images (next to .md files) do NOT work** — `?raw` imports treat markdown as text strings, not processed modules.
200
-
201
- ---
202
-
203
- ## Tags & Filtering
204
-
205
- ```typescript
206
- const blog = getBlogLoader('en');
207
- const allTags = blog.getAllTags(); // ['react', 'typescript', ...]
208
- const filtered = blog.getPostsByTag('react'); // Posts tagged 'react'
209
- ```
210
-
211
- ---
212
-
213
- ## RSS & Sitemap
214
-
215
- **Fully automatic — zero configuration.** The framework handles everything:
216
-
217
- ### Build-time generation
218
-
219
- The SEO pipeline (Vite `SEOPlugin` / Next.js `SEOHandler`) automatically:
220
-
221
- 1. Discovers `src/content/blog/*_en.md` files
222
- 2. Appends blog post URLs to `sitemap.xml`
223
- 3. Generates `rss.xml` (RSS 2.0 with Atom self-link) with all posts
224
-
225
- No manual scripts needed. Just drop `.md` files and build.
226
-
227
- ### RSS auto-discovery
228
-
229
- A `<link rel="alternate" type="application/rss+xml">` tag is automatically injected in the `<head>` by `AutoMetaTags`. This lets browsers and feed readers detect the feed without users needing to know the URL.
230
-
231
- **Requires:** `VITE_APP_URL` (or `NEXT_PUBLIC_APP_URL`) set in `.env` — the RSS link uses the base URL to construct `https://yourdomain.com/rss.xml`.
232
-
233
- ### RSS feed contents
234
-
235
- Each blog post entry includes:
236
- - `<title>`, `<description>`, `<link>`, `<guid>`, `<pubDate>`
237
- - `<category>` (from frontmatter `tags`)
238
- - `<enclosure>` (from frontmatter `image`, if set)
239
-
240
- ---
241
-
242
- ## Scaling (50+ Posts)
243
-
244
- Default uses `eager: true` (all posts bundled into JS). For large blogs, switch to lazy loading:
245
-
246
- ```typescript
247
- // Lazy: posts loaded on demand, not bundled
248
- const markdownFiles = import.meta.glob('../../content/blog/*.md', {
249
- query: '?raw',
250
- import: 'default',
251
- eager: false, // ← Change this
252
- });
253
-
254
- // Now each value is () => Promise<string> instead of string
255
- // You'll need to await them before passing to createBlogLoader
256
- ```
257
-
258
- For most apps (< 50 posts), eager loading is optimal.
259
-
260
- ---
261
-
262
- ## Auto-Deploy
263
-
264
- Push a new `.md` file → CI builds → `import.meta.glob` picks it up at build time → deployed. No CMS, no API.
265
-
266
- ---
267
-
268
- ## API Reference
269
-
270
- From `@donotdev/templates`:
271
-
272
- | Export | Type | Description |
273
- |--------|------|-------------|
274
- | `createBlogLoader` | Function | Create loader from glob results + language |
275
- | `parseFrontmatter` | Function | Parse `---` frontmatter from raw markdown |
276
- | `BlogList` | Component | Renders post listing with cards |
277
- | `BlogPostView` | Component | Renders single post with MarkdownViewer |
278
- | `BlogPost` | Type | Post with slug, meta, content, readingTime, tags |
279
- | `BlogMeta` | Type | Frontmatter metadata |
280
- | `BlogLoader` | Type | Loader interface |