Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .claude/skills/wordpress-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ letting "migrated" imply completeness.

## 8. Visual parity: reproducing the theme in userland

Migrating content reproduces the markup. Reproducing the *look* is separate work,
Migrating content reproduces the markup. Reproducing the _look_ is separate work,
and it follows one firm rule that comes straight from the goal of a faithful
port: **reproduce the WordPress design in the TanStack app's userland (theme
tokens, block renderers, seed, a little config), and never edit WordPress to make
Expand Down Expand Up @@ -290,7 +290,7 @@ breakpoint", default **921px** (`min-[921px]:`), not Tailwind's 768px.
- **Headings use fixed px, not fluid sizes.** Gutenberg writes an inline
`font-size` (for example a 54px hero `<h1>`), and Astra does not scale inline
sizes down, so the heading stays 54px at every width. A fluid
`clamp(…, 7vw, 54px)` on the ported side renders *smaller* at tablet widths;
`clamp(…, 7vw, 54px)` on the ported side renders _smaller_ at tablet widths;
use the same fixed px.
- **Card titles inherit the theme heading weight (about 600); section headings
are explicit (often 800).** A card `<h3>`/`<h4>` with no explicit weight in the
Expand Down Expand Up @@ -333,7 +333,7 @@ renders, and keep the arrays editable for the next site.

### Measure, do not eyeball

Load both sites in one window at the *same* width and diff `getComputedStyle` on
Load both sites in one window at the _same_ width and diff `getComputedStyle` on
matching elements (font-family, size, weight, line-height, color, padding, and
`grid-template-columns`). A window-width mismatch is the most common false "they
don't match", so equalize width first. Browser-automation windows are often
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ TanStack CMS ships a 14-row starter catalog (12 application classes and 2 delive

## Examples

| Example | What it shows |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| [`blog`](./examples/blog) | The reference app: posts, pages, blocks, AI editing, and the Playwright suite. |
| [`blog-voting`](./examples/blog-voting) | Extending the CMS with your own collections and routes (votes on posts). |
| [`db-sqlite`](./examples/db-sqlite), [`db-federated`](./examples/db-federated) | TanStack DB as the data layer: a writable CMS collection, and CMS copy joined with other services in one live query. |
| [`payload-after`](./examples/payload-after), [`astro-starlight-after`](./examples/astro-starlight-after), [`emdash-after`](./examples/emdash-after), [`wordpress-after`](./examples/wordpress-after) | Sites migrated from Payload, Astro Starlight, EmDash, and WordPress, each next to its `*-before` source. |
| Example | What it shows |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| [`blog`](./examples/blog) | The reference app: posts, pages, blocks, AI editing, and the Playwright suite. |
| [`blog-voting`](./examples/blog-voting) | Extending the CMS with your own collections and routes (votes on posts). |
| [`db-sqlite`](./examples/db-sqlite), [`db-federated`](./examples/db-federated) | TanStack DB as the data layer: a writable CMS collection, and CMS copy joined with other services in one live query. |
| [`payload-after`](./examples/payload-after), [`astro-starlight-after`](./examples/astro-starlight-after), [`emdash-after`](./examples/emdash-after), [`wordpress-after`](./examples/wordpress-after) | Sites migrated from Payload, Astro Starlight, EmDash, and WordPress, each next to its `*-before` source. |

## Migration skills

Expand Down
6 changes: 3 additions & 3 deletions app/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.2.0",
"@vitest/coverage-v8": "4.1.11",
"@vitest/coverage-v8": "4.1.12",
"tailwindcss": "^4.1.18",
"typescript": "5.9.3",
"vite": "^8.2.1",
"vitest": "4.1.11"
"vite": "^8.4.0",
"vitest": "4.1.12"
}
}
20 changes: 10 additions & 10 deletions app/docs-preview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ flagged in the report, not mapped to blocks.

## Configuration

| Env var | Default | Purpose |
| --- | --- | --- |
| `DOCS_DIR` | — | The docs directory to ingest (or pass as the CLI arg). |
| `ANTHROPIC_API_KEY` | — | Enables `/ask`. Else set a key at `/ai-settings`. |
| `DOCS_PREVIEW_MODEL` | `claude-sonnet-4-6` | The Claude model for `/ask`. |
| `DOCS_PREVIEW_TITLE` | source dir name | The site title. |
| `DOCS_PREVIEW_DATA_DIR` | `.data-<corpus>` | Where the PGlite store lives. |
| `DOCS_PREVIEW_INGEST_DIR` | `.ingest-<corpus>` | Where ingest artifacts live. |

**BYOK.** The AI chat takes a key from `ANTHROPIC_API_KEY` *or* one pasted at
| Env var | Default | Purpose |
| ------------------------- | ------------------- | ------------------------------------------------------ |
| `DOCS_DIR` | — | The docs directory to ingest (or pass as the CLI arg). |
| `ANTHROPIC_API_KEY` | — | Enables `/ask`. Else set a key at `/ai-settings`. |
| `DOCS_PREVIEW_MODEL` | `claude-sonnet-4-6` | The Claude model for `/ask`. |
| `DOCS_PREVIEW_TITLE` | source dir name | The site title. |
| `DOCS_PREVIEW_DATA_DIR` | `.data-<corpus>` | Where the PGlite store lives. |
| `DOCS_PREVIEW_INGEST_DIR` | `.ingest-<corpus>` | Where ingest artifacts live. |

**BYOK.** The AI chat takes a key from `ANTHROPIC_API_KEY` _or_ one pasted at
`/ai-settings` (stored in the data dir, local use only). With no key, `/ask` is
disabled and says so — search and preview still work.

Expand Down
4 changes: 2 additions & 2 deletions app/docs-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"jiti": "^2.7.0",
"tailwindcss": "^4.1.18",
"typescript": "5.9.3",
"vite": "^8.2.1",
"vitest": "4.1.11"
"vite": "^8.4.0",
"vitest": "4.1.12"
}
}
60 changes: 47 additions & 13 deletions app/docs-preview/scripts/ingest-docs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const CMS_EXPORT_VERSION = 1
// ---------------------------------------------------------------------------
const docsDir = path.resolve(process.argv[2] || process.env.DOCS_DIR || '')
const outDir = path.resolve(
process.argv[3] || process.env.DOCS_PREVIEW_OUT || path.join(process.cwd(), '.ingest'),
process.argv[3] ||
process.env.DOCS_PREVIEW_OUT ||
path.join(process.cwd(), '.ingest'),
)
if (!process.argv[2] && !process.env.DOCS_DIR) {
console.error('ingest-docs: pass a docs directory (argv or DOCS_DIR).')
Expand All @@ -53,7 +55,13 @@ if (!existsSync(docsDir) || !statSync(docsDir).isDirectory()) {
// ---------------------------------------------------------------------------
// fs helpers
// ---------------------------------------------------------------------------
const SKIP_DIRS = new Set(['node_modules', '.git', '.vitepress', 'dist', 'build'])
const SKIP_DIRS = new Set([
'node_modules',
'.git',
'.vitepress',
'dist',
'build',
])

/** Every file under `dir`, recursively, as absolute paths. */
function walk(dir, acc = []) {
Expand Down Expand Up @@ -88,7 +96,10 @@ function toSlug(relPath) {
/** A stable document id from a slug. */
function toId(slug) {
if (slug === '/') return 'index'
return slug.replace(/[^a-z0-9]+/gi, '-').replace(/^-+|-+$/g, '').toLowerCase()
return slug
.replace(/[^a-z0-9]+/gi, '-')
.replace(/^-+|-+$/g, '')
.toLowerCase()
}

/**
Expand Down Expand Up @@ -149,7 +160,8 @@ function readConfigNav() {
const sections = [] // ordered [{ label, slugs: [slug...] }]
const targets = [] // every `to` the config references
const configFile = path.join(docsDir, 'config.json')
if (!existsSync(configFile)) return { bySlug, sections, targets, present: false }
if (!existsSync(configFile))
return { bySlug, sections, targets, present: false }
let config
try {
config = JSON.parse(readFileSync(configFile, 'utf8'))
Expand All @@ -162,7 +174,10 @@ function readConfigNav() {
const slugs = []
const addChild = (child) => {
if (child.to != null) {
const slug = `/${String(child.to).replace(/^\/+/, '')}`.replace(/^\/\//, '/')
const slug = `/${String(child.to).replace(/^\/+/, '')}`.replace(
/^\/\//,
'/',
)
const norm = slug === '/' ? '/' : slug.replace(/^\//, '')
targets.push(norm)
if (!bySlug.has(norm)) {
Expand Down Expand Up @@ -298,7 +313,8 @@ for (const abs of mdFiles) {
id: toId(slug),
slug,
title,
description: typeof data.description === 'string' ? data.description : undefined,
description:
typeof data.description === 'string' ? data.description : undefined,
section,
sidebarLabel,
sidebarOrder,
Expand Down Expand Up @@ -493,19 +509,32 @@ if (configNav.present) {
const pg = pageBySlug.get(slug)
if (!pg) continue
placed.add(slug)
navPages.push({ slug, title: pg.title, label: pg.sidebarLabel, framework: pg.framework })
navPages.push({
slug,
title: pg.title,
label: pg.sidebarLabel,
framework: pg.framework,
})
}
if (navPages.length) navSections.push({ label: sec.label, pages: navPages })
}
}
const leftover = pages.filter((p) => !placed.has(p.slug))
const bySection = new Map()
for (const p of leftover.sort((a, b) => a.sidebarOrder - b.sidebarOrder || a.slug.localeCompare(b.slug))) {
for (const p of leftover.sort(
(a, b) => a.sidebarOrder - b.sidebarOrder || a.slug.localeCompare(b.slug),
)) {
const list = bySection.get(p.section) ?? []
list.push({ slug: p.slug, title: p.title, label: p.sidebarLabel, framework: p.framework })
list.push({
slug: p.slug,
title: p.title,
label: p.sidebarLabel,
framework: p.framework,
})
bySection.set(p.section, list)
}
for (const [label, navPages] of bySection) navSections.push({ label, pages: navPages })
for (const [label, navPages] of bySection)
navSections.push({ label, pages: navPages })

writeFileSync(
path.join(outDir, 'nav.json'),
Expand All @@ -518,7 +547,8 @@ for (const i of issues) issuesByKind[i.kind] = (issuesByKind[i.kind] ?? 0) + 1
const issuesBySeverity = { error: 0, warning: 0, info: 0 }
for (const i of issues) issuesBySeverity[i.severity] += 1
const navSourceCounts = {}
for (const p of pages) navSourceCounts[p.navSource] = (navSourceCounts[p.navSource] ?? 0) + 1
for (const p of pages)
navSourceCounts[p.navSource] = (navSourceCounts[p.navSource] ?? 0) + 1

const report = {
generatedAt: exportedAt,
Expand Down Expand Up @@ -548,12 +578,16 @@ writeFileSync(
// ---------------------------------------------------------------------------
console.log(`ingest-docs: ${docsDir}`)
console.log(` pages: ${pages.length} (from ${mdFiles.length} files)`)
console.log(` sections: ${navSections.length}${configNav.present ? ' (config.json)' : ' (derived)'}`)
console.log(
` sections: ${navSections.length}${configNav.present ? ' (config.json)' : ' (derived)'}`,
)
console.log(` links: ${linksChecked} checked`)
console.log(` assets: ${assetsReferenced} referenced`)
console.log(` nav source: ${JSON.stringify(navSourceCounts)}`)
console.log(
` issues: ${issues.length} — ${issuesBySeverity.error} error, ${issuesBySeverity.warning} warning, ${issuesBySeverity.info} info`,
)
console.log(` ${JSON.stringify(issuesByKind)}`)
console.log(` → ${path.relative(process.cwd(), outDir)}/{cms-export,nav,ingest-report}.json`)
console.log(
` → ${path.relative(process.cwd(), outDir)}/{cms-export,nav,ingest-report}.json`,
)
16 changes: 11 additions & 5 deletions app/docs-preview/scripts/preview.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import path from 'node:path'

const docsDir = path.resolve(process.argv[2] || process.env.DOCS_DIR || '')
if (!process.argv[2] && !process.env.DOCS_DIR) {
console.error('Usage: pnpm preview <docs-dir> (or DOCS_DIR=<docs-dir> pnpm preview)')
console.error(
'Usage: pnpm preview <docs-dir> (or DOCS_DIR=<docs-dir> pnpm preview)',
)
process.exit(1)
}
if (!existsSync(docsDir) || !statSync(docsDir).isDirectory()) {
Expand All @@ -43,7 +45,10 @@ const env = {

function run(step, file, args) {
console.log(`\n▸ ${step}`)
const r = spawnSync(process.execPath, [file, ...args], { stdio: 'inherit', env })
const r = spawnSync(process.execPath, [file, ...args], {
stdio: 'inherit',
env,
})
if (r.status !== 0) {
console.error(`\n✗ ${step} failed.`)
process.exit(r.status ?? 1)
Expand All @@ -63,9 +68,10 @@ run('Load into the CMS', 'scripts/load-export.mjs', [

console.log(`\n▸ Serving — http://localhost:3017 (Ctrl-C to stop)`)
if (!process.env.ANTHROPIC_API_KEY && !process.env.ANTHROPIC_AUTH_TOKEN) {
console.log(' (no ANTHROPIC_API_KEY — /ask is off; set one or use /ai-settings)')
console.log(
' (no ANTHROPIC_API_KEY — /ask is off; set one or use /ai-settings)',
)
}
const serve = spawn('pnpm', ['dev'], { stdio: 'inherit', env })
serve.on('exit', (code) => process.exit(code ?? 0))
for (const sig of ['SIGINT', 'SIGTERM'])
process.on(sig, () => serve.kill(sig))
for (const sig of ['SIGINT', 'SIGTERM']) process.on(sig, () => serve.kill(sig))
22 changes: 13 additions & 9 deletions app/docs-preview/src/byok.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import { createServerFn } from '@tanstack/react-start'
import { z } from 'zod'

export const byokStatus = createServerFn({ method: 'GET' }).handler(async () => {
const m = await import('./byok.server')
return { source: m.keySource(), model: m.resolveModel() }
})
export const byokStatus = createServerFn({ method: 'GET' }).handler(
async () => {
const m = await import('./byok.server')
return { source: m.keySource(), model: m.resolveModel() }
},
)

export const byokSet = createServerFn({ method: 'POST' })
.validator(z.object({ key: z.string().min(1).max(500) }))
Expand All @@ -19,8 +21,10 @@ export const byokSet = createServerFn({ method: 'POST' })
return { source: m.keySource(), model: m.resolveModel() }
})

export const byokClear = createServerFn({ method: 'POST' }).handler(async () => {
const m = await import('./byok.server')
m.clearStoredKey()
return { source: m.keySource(), model: m.resolveModel() }
})
export const byokClear = createServerFn({ method: 'POST' }).handler(
async () => {
const m = await import('./byok.server')
m.clearStoredKey()
return { source: m.keySource(), model: m.resolveModel() }
},
)
5 changes: 4 additions & 1 deletion app/docs-preview/src/byok.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ export function getStoredKey(): string | undefined {
export function setStoredKey(key: string): void {
const dir = resolveDataDir()
mkdirSync(dir, { recursive: true })
writeFileSync(byokFile(), `${JSON.stringify({ anthropicKey: key.trim() }, null, 2)}\n`)
writeFileSync(
byokFile(),
`${JSON.stringify({ anthropicKey: key.trim() }, null, 2)}\n`,
)
}

export function clearStoredKey(): void {
Expand Down
18 changes: 14 additions & 4 deletions app/docs-preview/src/cms.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
* to the source tree. There is no editing surface: this app ingests, renders,
* searches, and answers questions about a corpus; it does not change it.
*/
import { defineCmsDefinition, defineCollection } from '@tanstack/cms-core/definition'
import {
defineCmsDefinition,
defineCollection,
} from '@tanstack/cms-core/definition'

/** The framework variants TanStack docs template with `{$framework}`. */
export const FRAMEWORKS = [
Expand Down Expand Up @@ -60,7 +63,8 @@ const collections = [
type: 'slug',
nested: true,
required: true,
description: 'Docs path, e.g. /guide/data-loading ("/" is the docs home)',
description:
'Docs path, e.g. /guide/data-loading ("/" is the docs home)',
},
{ name: 'sidebarLabel', label: 'Sidebar label', type: 'text' },
{ name: 'sidebarOrder', label: 'Sidebar order', type: 'number' },
Expand All @@ -81,7 +85,8 @@ const collections = [
name: 'sourcePath',
label: 'Source path',
type: 'text',
description: 'Original file, relative to the docs dir (read-only provenance)',
description:
'Original file, relative to the docs dir (read-only provenance)',
},
{
name: 'navSource',
Expand All @@ -91,7 +96,12 @@ const collections = [
description: 'Where this page’s nav placement came from',
},
{ name: 'blocks', label: 'Content', type: 'blocks' },
{ name: 'published', label: 'Published', type: 'boolean', defaultValue: true },
{
name: 'published',
label: 'Published',
type: 'boolean',
defaultValue: true,
},
],
}),
]
Expand Down
4 changes: 3 additions & 1 deletion app/docs-preview/src/components/docs-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export function DocsSidebar({
}

/** Flatten the nav into reading order, for prev/next. */
export function flattenNav(nav: NavData | null): Array<{ slug: string; title: string }> {
export function flattenNav(
nav: NavData | null,
): Array<{ slug: string; title: string }> {
if (!nav) return []
return nav.sections.flatMap((s) =>
s.pages.map((p) => ({ slug: p.slug, title: p.label || p.title })),
Expand Down
4 changes: 3 additions & 1 deletion app/docs-preview/src/ingest-artifacts.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export interface NavData {
}

export function ingestDir(): string {
return process.env.DOCS_PREVIEW_INGEST_DIR || path.join(process.cwd(), '.ingest')
return (
process.env.DOCS_PREVIEW_INGEST_DIR || path.join(process.cwd(), '.ingest')
)
}

function readJson<T>(name: string): T | null {
Expand Down
3 changes: 1 addition & 2 deletions app/docs-preview/src/lib/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const PREFIX = '/docs'

/** Resolve a relative link target against a page's slug into a doc slug. */
export function resolveDocSlug(fromSlug: string, target: string): string {
const fromDir =
fromSlug === '/' ? [] : fromSlug.split('/').slice(0, -1)
const fromDir = fromSlug === '/' ? [] : fromSlug.split('/').slice(0, -1)
const clean = target.replace(/\.mdx?$/i, '').replace(/\/index$/i, '')
const stack = [...fromDir]
for (const part of clean.split('/')) {
Expand Down
Loading
Loading