@pagesmith/core 0.3.0 → 0.4.0
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.
- package/README.md +9 -4
- package/REFERENCE.md +5 -2
- package/dist/ai/index.d.mts +5 -3
- package/dist/ai/index.d.mts.map +1 -1
- package/dist/ai/index.mjs +300 -206
- package/dist/ai/index.mjs.map +1 -1
- package/dist/assets/index.d.mts +10 -1
- package/dist/assets/index.d.mts.map +1 -1
- package/dist/assets/index.mjs +2 -2
- package/dist/{assets-DXiWF_KI.mjs → assets-CAPOqQ_P.mjs} +42 -5
- package/dist/assets-CAPOqQ_P.mjs.map +1 -0
- package/dist/{content-config-Bfe4W9us.d.mts → content-config-DJXUOcNG.d.mts} +49 -17
- package/dist/{content-config-Bfe4W9us.d.mts.map → content-config-DJXUOcNG.d.mts.map} +1 -1
- package/dist/{content-layer-DPK1EmfY.mjs → content-layer-B5enqWeJ.mjs} +123 -28
- package/dist/content-layer-B5enqWeJ.mjs.map +1 -0
- package/dist/content-layer-CpHYUYNN.d.mts +121 -0
- package/dist/content-layer-CpHYUYNN.d.mts.map +1 -0
- package/dist/create/index.d.mts.map +1 -1
- package/dist/create/index.mjs +26 -28
- package/dist/create/index.mjs.map +1 -1
- package/dist/css/index.d.mts +1 -1
- package/dist/{heading-BpDXnl-7.d.mts → heading-Dhvzlay-.d.mts} +1 -1
- package/dist/{heading-BpDXnl-7.d.mts.map → heading-Dhvzlay-.d.mts.map} +1 -1
- package/dist/{index-Bg9srb5U.d.mts → index-B7NRZAxd.d.mts} +1 -1
- package/dist/{index-Bg9srb5U.d.mts.map → index-B7NRZAxd.d.mts.map} +1 -1
- package/dist/{index-BBYkDxwI.d.mts → index-C0QFHYwb.d.mts} +1 -1
- package/dist/{index-BBYkDxwI.d.mts.map → index-C0QFHYwb.d.mts.map} +1 -1
- package/dist/{index-CbOKbkjJ.d.mts → index-CJkBs8YQ.d.mts} +2 -2
- package/dist/index-CJkBs8YQ.d.mts.map +1 -0
- package/dist/{index-YXQxMV6J.d.mts → index-DCznbvaV.d.mts} +2 -2
- package/dist/{index-YXQxMV6J.d.mts.map → index-DCznbvaV.d.mts.map} +1 -1
- package/dist/index.d.mts +15 -99
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +13 -9
- package/dist/index.mjs.map +1 -1
- package/dist/loaders/index.d.mts +2 -2
- package/dist/markdown/index.d.mts +2 -2
- package/dist/markdown/index.mjs +1 -1
- package/dist/{markdown-CyrHoDhP.mjs → markdown-BmDJgYeB.mjs} +23 -1
- package/dist/{markdown-CyrHoDhP.mjs.map → markdown-BmDJgYeB.mjs.map} +1 -1
- package/dist/mcp/index.d.mts +23 -0
- package/dist/mcp/index.d.mts.map +1 -0
- package/dist/mcp/index.mjs +2 -0
- package/dist/mcp/server.d.mts +13 -0
- package/dist/mcp/server.d.mts.map +1 -0
- package/dist/mcp/server.mjs +2 -0
- package/dist/runtime/index.mjs +1 -1
- package/dist/schemas/index.d.mts +3 -3
- package/dist/server-D3DHoh5f.mjs +202 -0
- package/dist/server-D3DHoh5f.mjs.map +1 -0
- package/dist/ssg-utils/index.d.mts +61 -0
- package/dist/ssg-utils/index.d.mts.map +1 -0
- package/dist/ssg-utils/index.mjs +118 -0
- package/dist/ssg-utils/index.mjs.map +1 -0
- package/dist/{types-Cn52sdoq.d.mts → types-B-V5qemH.d.mts} +1 -1
- package/dist/{types-Cn52sdoq.d.mts.map → types-B-V5qemH.d.mts.map} +1 -1
- package/dist/vite/index.d.mts +69 -34
- package/dist/vite/index.d.mts.map +1 -1
- package/dist/vite/index.mjs +294 -226
- package/dist/vite/index.mjs.map +1 -1
- package/docs/agents/AGENTS.md.template +9 -0
- package/docs/agents/changelog-notes.md +15 -0
- package/docs/agents/errors.md +96 -0
- package/docs/agents/migration.md +25 -0
- package/docs/agents/recipes.md +26 -0
- package/docs/agents/usage.md +58 -0
- package/docs/llms-full.txt +53 -0
- package/docs/llms.txt +29 -0
- package/package.json +56 -4
- package/dist/assets-DXiWF_KI.mjs.map +0 -1
- package/dist/content-layer-DPK1EmfY.mjs.map +0 -1
- package/dist/index-CbOKbkjJ.d.mts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/create/index.ts"],"sourcesContent":["/**\n * Project scaffolding for `pagesmith create`.\n *\n * Supports local templates (bundled) and remote templates (GitHub examples).\n */\n\nimport {\n cpSync,\n existsSync,\n mkdirSync,\n mkdtempSync,\n readdirSync,\n readFileSync,\n rmSync,\n unlinkSync,\n writeFileSync,\n} from 'fs'\nimport { join, resolve } from 'path'\nimport { execSync } from 'child_process'\nimport { tmpdir } from 'os'\n\nconst GITHUB_REPO = 'sujeet-pro/pagesmith'\nconst PACKAGE_VERSION = '^0.1.0'\n\nexport type Template = {\n name: string\n description: string\n source: 'local' | 'github'\n path: string\n dependency: '@pagesmith/core' | '@pagesmith/docs'\n scripts: Record<string, string>\n}\n\nexport const templates: Template[] = [\n {\n name: 'docs',\n description: 'Documentation site with @pagesmith/docs',\n source: 'local',\n path: 'templates/docs',\n dependency: '@pagesmith/docs',\n scripts: { dev: 'pagesmith dev', build: 'pagesmith build', preview: 'pagesmith preview' },\n },\n {\n name: 'blog',\n description: 'Blog with custom layouts using @pagesmith/core',\n source: 'github',\n path: 'examples/blog-site',\n dependency: '@pagesmith/core',\n scripts: { dev: 'node --watch build.mjs', build: 'node build.mjs' },\n },\n {\n name: 'react',\n description: 'React SSG site with react-router',\n source: 'github',\n path: 'examples/with-react',\n dependency: '@pagesmith/core',\n scripts: {\n dev: 'vp dev',\n build: 'node build.mjs',\n preview: 'vp preview',\n },\n },\n {\n name: 'solid',\n description: 'SolidJS SSG site',\n source: 'github',\n path: 'examples/with-solid',\n dependency: '@pagesmith/core',\n scripts: {\n dev: 'vp dev',\n build: 'node build.mjs',\n preview: 'vp preview',\n },\n },\n {\n name: 'svelte',\n description: 'Svelte SSG site',\n source: 'github',\n path: 'examples/with-svelte',\n dependency: '@pagesmith/core',\n scripts: {\n dev: 'vp dev',\n build: 'node build.mjs',\n preview: 'vp preview',\n },\n },\n {\n name: 'ejs',\n description: 'Vanilla Node.js + EJS templates',\n source: 'github',\n path: 'examples/with-vanilla-ejs',\n dependency: '@pagesmith/core',\n scripts: {\n dev: 'node --watch build.mjs',\n build: 'node build.mjs',\n },\n },\n {\n name: 'hbs',\n description: 'Vanilla Node.js + Handlebars templates',\n source: 'github',\n path: 'examples/with-vanilla-hbs',\n dependency: '@pagesmith/core',\n scripts: {\n dev: 'node --watch build.mjs',\n build: 'node build.mjs',\n },\n },\n]\n\nexport function listTemplates(): string {\n const maxName = Math.max(...templates.map((t) => t.name.length))\n return templates.map((t) => ` ${t.name.padEnd(maxName + 2)} ${t.description}`).join('\\n')\n}\n\nasync function downloadFromGithub(templatePath: string, destination: string): Promise<void> {\n const tarballUrl = `https://github.com/${GITHUB_REPO}/archive/refs/heads/main.tar.gz`\n console.log('Downloading template from GitHub...')\n\n const response = await fetch(tarballUrl, { redirect: 'follow' })\n if (!response.ok) {\n throw new Error(`Failed to download: ${response.status} ${response.statusText}`)\n }\n\n const tmpFile = join(tmpdir(), `pagesmith-${Date.now()}.tar.gz`)\n const tmpExtract = mkdtempSync(join(tmpdir(), 'pagesmith-'))\n\n try {\n writeFileSync(tmpFile, Buffer.from(await response.arrayBuffer()))\n\n // Extract full tarball\n execSync(`tar xzf ${tmpFile} -C ${tmpExtract}`, { stdio: 'pipe' })\n\n // Find the extracted top-level directory\n const dirs = readdirSync(tmpExtract)\n const topDir = dirs[0]\n if (!topDir) throw new Error('Empty tarball')\n\n const sourcePath = join(tmpExtract, topDir, templatePath)\n if (!existsSync(sourcePath)) {\n throw new Error(`Template path not found in repo: ${templatePath}`)\n }\n\n mkdirSync(destination, { recursive: true })\n cpSync(sourcePath, destination, { recursive: true })\n\n // Also copy shared-content for framework examples\n const sharedContentPath = join(tmpExtract, topDir, 'examples/shared-content')\n if (existsSync(sharedContentPath) && templatePath.startsWith('examples/with-')) {\n const contentDest = join(destination, 'content')\n mkdirSync(contentDest, { recursive: true })\n\n // Copy markdown/data files from shared-content\n for (const subDir of ['posts', 'pages', 'authors']) {\n const srcDir = join(sharedContentPath, subDir)\n if (existsSync(srcDir)) {\n cpSync(srcDir, join(contentDest, subDir), { recursive: true })\n }\n }\n\n // Copy content config\n const configSrc = join(sharedContentPath, 'content.config.mjs')\n if (existsSync(configSrc)) {\n cpSync(configSrc, join(destination, 'content.config.mjs'))\n }\n }\n } finally {\n unlinkSync(tmpFile)\n rmSync(tmpExtract, { recursive: true, force: true })\n }\n}\n\nfunction adaptForStandalone(destination: string, template: Template): void {\n // Update content.config.mjs paths (from ./posts to ./content/posts)\n const configPath = join(destination, 'content.config.mjs')\n if (existsSync(configPath)) {\n let config = readFileSync(configPath, 'utf-8')\n config = config.replace(/directory: '\\.\\/posts'/g, \"directory: './content/posts'\")\n config = config.replace(/directory: '\\.\\/pages'/g, \"directory: './content/pages'\")\n config = config.replace(/directory: '\\.\\/authors'/g, \"directory: './content/authors'\")\n config = config.replace(/directory: '\\.\\/config'/g, \"directory: './content/config'\")\n writeFileSync(configPath, config)\n }\n\n // Update vite.config.ts shared-content references\n const viteConfigPath = join(destination, 'vite.config.ts')\n if (existsSync(viteConfigPath)) {\n let config = readFileSync(viteConfigPath, 'utf-8')\n config = config.replace(\n /import content from '\\.\\.\\/shared-content\\/content\\.config'/g,\n \"import content from './content.config.mjs'\",\n )\n config = config.replace(\n /configPath:\\s*'\\.\\.\\/shared-content\\/content\\.config\\.ts'/g,\n \"configPath: './content.config.mjs'\",\n )\n config = config.replace(\n /root:\\s*resolve\\(import\\.meta\\.dirname,\\s*'\\.\\.\\/shared-content'\\)/g,\n 'root: import.meta.dirname',\n )\n writeFileSync(viteConfigPath, config)\n }\n\n // Update build.mjs (remove shared-content references)\n const buildPath = join(destination, 'build.mjs')\n if (existsSync(buildPath)) {\n let script = readFileSync(buildPath, 'utf-8')\n // Replace shared-content imports\n script = script.replace(\n /import .* from '\\.\\.\\/shared-content\\/content\\.config\\.mjs'/g,\n \"import content from './content.config.mjs'\",\n )\n // Simplify content layer setup\n script = script.replace(\n /const contentRoot = resolve\\(root, '\\.\\.\\/shared-content'\\)/g,\n 'const contentRoot = root',\n )\n // Fix named imports\n script = script.replace(\n /import \\{ pages, posts \\} from '\\.\\.\\/shared-content\\/content\\.config\\.mjs'/g,\n \"import content from './content.config.mjs'\\nconst { pages, posts } = content\",\n )\n writeFileSync(buildPath, script)\n }\n\n // Remove workspace-specific tsconfig paths\n const tsconfigPath = join(destination, 'tsconfig.json')\n if (existsSync(tsconfigPath)) {\n const tsconfig = JSON.parse(readFileSync(tsconfigPath, 'utf-8'))\n if (tsconfig.compilerOptions?.paths) {\n delete tsconfig.compilerOptions.paths\n }\n writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2) + '\\n')\n }\n}\n\nfunction writePackageJson(destination: string, projectName: string, template: Template): void {\n const existingPkg = join(destination, 'package.json')\n let pkg: Record<string, any> = {}\n\n if (existsSync(existingPkg)) {\n pkg = JSON.parse(readFileSync(existingPkg, 'utf-8'))\n }\n\n pkg.name = projectName\n pkg.private = true\n pkg.type = 'module'\n pkg.version = '0.0.0'\n pkg.scripts = template.scripts\n\n // Replace workspace \"*\" deps with actual versions\n if (pkg.dependencies) {\n for (const [name, version] of Object.entries(pkg.dependencies)) {\n if (version === '*' && name.startsWith('@pagesmith/')) {\n pkg.dependencies[name] = PACKAGE_VERSION\n }\n }\n }\n\n // Ensure the primary dependency is present\n pkg.dependencies = pkg.dependencies ?? {}\n pkg.dependencies[template.dependency] = PACKAGE_VERSION\n\n // Keep Vite+ in standalone examples that already use it\n if (pkg.devDependencies?.vite && !pkg.devDependencies['vite-plus']) {\n pkg.devDependencies['vite-plus'] = '^0.1.13'\n }\n\n pkg.packageManager = 'npm@11.12.0'\n\n writeFileSync(existingPkg, JSON.stringify(pkg, null, 2) + '\\n')\n}\n\nexport async function createProject(projectName: string, templateName: string): Promise<void> {\n const template = templates.find((t) => t.name === templateName)\n if (!template) {\n throw new Error(`Unknown template \"${templateName}\". Available templates:\\n${listTemplates()}`)\n }\n\n const destination = resolve(projectName)\n if (existsSync(destination) && readdirSync(destination).length > 0) {\n throw new Error(`Directory \"${projectName}\" already exists and is not empty.`)\n }\n\n if (template.source === 'local') {\n const templateDir = resolve(\n import.meta.dirname,\n '../../templates',\n template.path.split('/').pop()!,\n )\n mkdirSync(destination, { recursive: true })\n cpSync(templateDir, destination, { recursive: true })\n } else {\n await downloadFromGithub(template.path, destination)\n adaptForStandalone(destination, template)\n }\n\n writePackageJson(destination, projectName, template)\n\n console.log(`\\nCreated \"${projectName}\" from the \"${template.name}\" template.\\n`)\n console.log('Next steps:')\n console.log(` cd ${projectName}`)\n console.log(' vp install')\n if (template.scripts.dev) {\n console.log(` vp run dev`)\n } else {\n console.log(` vp run build`)\n }\n console.log()\n}\n"],"mappings":";;;;;;;;;;AAqBA,MAAM,cAAc;AACpB,MAAM,kBAAkB;AAWxB,MAAa,YAAwB;CACnC;EACE,MAAM;EACN,aAAa;EACb,QAAQ;EACR,MAAM;EACN,YAAY;EACZ,SAAS;GAAE,KAAK;GAAiB,OAAO;GAAmB,SAAS;GAAqB;EAC1F;CACD;EACE,MAAM;EACN,aAAa;EACb,QAAQ;EACR,MAAM;EACN,YAAY;EACZ,SAAS;GAAE,KAAK;GAA0B,OAAO;GAAkB;EACpE;CACD;EACE,MAAM;EACN,aAAa;EACb,QAAQ;EACR,MAAM;EACN,YAAY;EACZ,SAAS;GACP,KAAK;GACL,OAAO;GACP,SAAS;GACV;EACF;CACD;EACE,MAAM;EACN,aAAa;EACb,QAAQ;EACR,MAAM;EACN,YAAY;EACZ,SAAS;GACP,KAAK;GACL,OAAO;GACP,SAAS;GACV;EACF;CACD;EACE,MAAM;EACN,aAAa;EACb,QAAQ;EACR,MAAM;EACN,YAAY;EACZ,SAAS;GACP,KAAK;GACL,OAAO;GACP,SAAS;GACV;EACF;CACD;EACE,MAA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KAAI,WAAW,YAAY,IAAI,YAAY,YAAY,CAAC,SAAS,EAC/D,OAAM,IAAI,MAAM,cAAc,YAAY,oCAAoC;AAGhF,KAAI,SAAS,WAAW,SAAS;EAC/B,MAAM,cAAc,QAClB,OAAO,KAAK,SACZ,mBACA,SAAS,KAAK,MAAM,IAAI,CAAC,KAAK,CAC/B;AACD,YAAU,aAAa,EAAE,WAAW,MAAM,CAAC;AAC3C,SAAO,aAAa,aAAa,EAAE,WAAW,MAAM,CAAC;QAChD;AACL,QAAM,mBAAmB,SAAS,MAAM,YAAY;AACpD,qBAAmB,aAAa,SAAS;;AAG3C,kBAAiB,aAAa,aAAa,SAAS;AAEpD,SAAQ,IAAI,cAAc,YAAY,cAAc,SAAS,KAAK,eAAe;AACjF,SAAQ,IAAI,cAAc;AAC1B,SAAQ,IAAI,QAAQ,cAAc;AAClC,SAAQ,IAAI,eAAe;AAC3B,KAAI,SAAS,QAAQ,IACnB,SAAQ,IAAI,eAAe;KAE3B,SAAQ,IAAI,iBAAiB;AAE/B,SAAQ,KAAK"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/create/index.ts"],"sourcesContent":["/**\n * Project scaffolding for `pagesmith create`.\n *\n * Supports local templates (bundled) and remote templates (GitHub examples).\n */\n\nimport {\n cpSync,\n existsSync,\n mkdirSync,\n mkdtempSync,\n readdirSync,\n readFileSync,\n rmSync,\n unlinkSync,\n writeFileSync,\n} from 'fs'\nimport { join, resolve } from 'path'\nimport { execSync } from 'child_process'\nimport { tmpdir } from 'os'\n\nconst GITHUB_REPO = 'sujeet-pro/pagesmith'\n\nfunction getPackageVersion(): string {\n try {\n const pkgPath = resolve(import.meta.dirname, '..', '..', 'package.json')\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) as { version?: string }\n return `^${pkg.version ?? '0.1.0'}`\n } catch {\n return '^0.1.0'\n }\n}\n\nexport type Template = {\n name: string\n description: string\n source: 'local' | 'github'\n path: string\n dependency: '@pagesmith/core' | '@pagesmith/docs'\n scripts: Record<string, string>\n}\n\nexport const templates: Template[] = [\n {\n name: 'docs',\n description: 'Documentation site with @pagesmith/docs',\n source: 'local',\n path: 'templates/docs',\n dependency: '@pagesmith/docs',\n scripts: { dev: 'pagesmith dev', build: 'pagesmith build', preview: 'pagesmith preview' },\n },\n {\n name: 'blog',\n description: 'Blog with custom layouts using @pagesmith/core',\n source: 'github',\n path: 'examples/blog-site',\n dependency: '@pagesmith/core',\n scripts: { dev: 'vp dev', build: 'vp build', check: 'vp check' },\n },\n {\n name: 'react',\n description: 'React SSG site with react-router',\n source: 'github',\n path: 'examples/with-react',\n dependency: '@pagesmith/core',\n scripts: {\n dev: 'vp dev',\n build: 'vp build',\n check: 'vp check',\n preview: 'vp preview',\n },\n },\n {\n name: 'solid',\n description: 'SolidJS SSG site',\n source: 'github',\n path: 'examples/with-solid',\n dependency: '@pagesmith/core',\n scripts: {\n dev: 'vp dev',\n build: 'vp build',\n check: 'vp check',\n preview: 'vp preview',\n },\n },\n {\n name: 'svelte',\n description: 'Svelte SSG site',\n source: 'github',\n path: 'examples/with-svelte',\n dependency: '@pagesmith/core',\n scripts: {\n dev: 'vp dev',\n build: 'vp build',\n check: 'vp check',\n preview: 'vp preview',\n },\n },\n {\n name: 'ejs',\n description: 'Vanilla Node.js + EJS templates',\n source: 'github',\n path: 'examples/with-vanilla-ejs',\n dependency: '@pagesmith/core',\n scripts: {\n dev: 'vp dev',\n build: 'vp build',\n check: 'vp check',\n },\n },\n {\n name: 'hbs',\n description: 'Vanilla Node.js + Handlebars templates',\n source: 'github',\n path: 'examples/with-vanilla-hbs',\n dependency: '@pagesmith/core',\n scripts: {\n dev: 'vp dev',\n build: 'vp build',\n check: 'vp check',\n },\n },\n]\n\nexport function listTemplates(): string {\n const maxName = Math.max(...templates.map((t) => t.name.length))\n return templates.map((t) => ` ${t.name.padEnd(maxName + 2)} ${t.description}`).join('\\n')\n}\n\nasync function downloadFromGithub(templatePath: string, destination: string): Promise<void> {\n const tarballUrl = `https://github.com/${GITHUB_REPO}/archive/refs/heads/main.tar.gz`\n console.log('Downloading template from GitHub...')\n\n const response = await fetch(tarballUrl, { redirect: 'follow' })\n if (!response.ok) {\n throw new Error(`Failed to download: ${response.status} ${response.statusText}`)\n }\n\n const tmpFile = join(tmpdir(), `pagesmith-${Date.now()}.tar.gz`)\n const tmpExtract = mkdtempSync(join(tmpdir(), 'pagesmith-'))\n\n try {\n writeFileSync(tmpFile, Buffer.from(await response.arrayBuffer()))\n\n // Extract full tarball\n execSync(`tar xzf ${tmpFile} -C ${tmpExtract}`, { stdio: 'pipe' })\n\n // Find the extracted top-level directory\n const dirs = readdirSync(tmpExtract)\n const topDir = dirs[0]\n if (!topDir) throw new Error('Empty tarball')\n\n const sourcePath = join(tmpExtract, topDir, templatePath)\n if (!existsSync(sourcePath)) {\n throw new Error(`Template path not found in repo: ${templatePath}`)\n }\n\n mkdirSync(destination, { recursive: true })\n cpSync(sourcePath, destination, { recursive: true })\n } finally {\n unlinkSync(tmpFile)\n rmSync(tmpExtract, { recursive: true, force: true })\n }\n}\n\nfunction adaptForStandalone(destination: string, template: Template): void {\n // Update content.config.mjs paths (from ./posts to ./content/posts)\n const configPath = join(destination, 'content.config.mjs')\n if (existsSync(configPath)) {\n let config = readFileSync(configPath, 'utf-8')\n config = config.replace(/directory: '\\.\\/posts'/g, \"directory: './content/posts'\")\n config = config.replace(/directory: '\\.\\/pages'/g, \"directory: './content/pages'\")\n config = config.replace(/directory: '\\.\\/authors'/g, \"directory: './content/authors'\")\n config = config.replace(/directory: '\\.\\/config'/g, \"directory: './content/config'\")\n writeFileSync(configPath, config)\n }\n\n // Update vite.config.ts shared-content references\n const viteConfigPath = join(destination, 'vite.config.ts')\n if (existsSync(viteConfigPath)) {\n let config = readFileSync(viteConfigPath, 'utf-8')\n config = config.replace(\n /import content from '\\.\\.\\/shared-content\\/content\\.config'/g,\n \"import content from './content.config.mjs'\",\n )\n config = config.replace(\n /configPath:\\s*'\\.\\.\\/shared-content\\/content\\.config\\.ts'/g,\n \"configPath: './content.config.mjs'\",\n )\n config = config.replace(\n /root:\\s*resolve\\(import\\.meta\\.dirname,\\s*'\\.\\.\\/shared-content'\\)/g,\n 'root: import.meta.dirname',\n )\n writeFileSync(viteConfigPath, config)\n }\n\n // Update build.mjs (remove shared-content references)\n const buildPath = join(destination, 'build.mjs')\n if (existsSync(buildPath)) {\n let script = readFileSync(buildPath, 'utf-8')\n // Replace shared-content imports\n script = script.replace(\n /import .* from '\\.\\.\\/shared-content\\/content\\.config\\.mjs'/g,\n \"import content from './content.config.mjs'\",\n )\n // Simplify content layer setup\n script = script.replace(\n /const contentRoot = resolve\\(root, '\\.\\.\\/shared-content'\\)/g,\n 'const contentRoot = root',\n )\n // Fix named imports\n script = script.replace(\n /import \\{ pages, posts \\} from '\\.\\.\\/shared-content\\/content\\.config\\.mjs'/g,\n \"import content from './content.config.mjs'\\nconst { pages, posts } = content\",\n )\n writeFileSync(buildPath, script)\n }\n\n // Remove workspace-specific tsconfig paths\n const tsconfigPath = join(destination, 'tsconfig.json')\n if (existsSync(tsconfigPath)) {\n const tsconfig = JSON.parse(readFileSync(tsconfigPath, 'utf-8'))\n if (tsconfig.compilerOptions?.paths) {\n delete tsconfig.compilerOptions.paths\n }\n writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2) + '\\n')\n }\n}\n\nfunction writePackageJson(destination: string, projectName: string, template: Template): void {\n const existingPkg = join(destination, 'package.json')\n let pkg: Record<string, any> = {}\n\n if (existsSync(existingPkg)) {\n pkg = JSON.parse(readFileSync(existingPkg, 'utf-8'))\n }\n\n pkg.name = projectName\n pkg.private = true\n pkg.type = 'module'\n pkg.version = '0.0.0'\n pkg.scripts = template.scripts\n\n // Replace workspace \"*\" deps with actual versions\n if (pkg.dependencies) {\n for (const [name, version] of Object.entries(pkg.dependencies)) {\n if (version === '*' && name.startsWith('@pagesmith/')) {\n pkg.dependencies[name] = getPackageVersion()\n }\n }\n }\n\n // Ensure the primary dependency is present\n pkg.dependencies = pkg.dependencies ?? {}\n pkg.dependencies[template.dependency] = getPackageVersion()\n\n // Keep Vite+ in standalone examples that already use it\n if (pkg.devDependencies?.vite && !pkg.devDependencies['vite-plus']) {\n pkg.devDependencies['vite-plus'] = '^0.1.13'\n }\n\n pkg.packageManager = 'npm@11.12.0'\n\n writeFileSync(existingPkg, JSON.stringify(pkg, null, 2) + '\\n')\n}\n\nexport async function createProject(projectName: string, templateName: string): Promise<void> {\n const template = templates.find((t) => t.name === templateName)\n if (!template) {\n throw new Error(`Unknown template \"${templateName}\". Available templates:\\n${listTemplates()}`)\n }\n\n const destination = resolve(projectName)\n if (existsSync(destination) && readdirSync(destination).length > 0) {\n throw new Error(`Directory \"${projectName}\" already exists and is not empty.`)\n }\n\n if (template.source === 'local') {\n const templateDir = resolve(\n import.meta.dirname,\n '../../templates',\n template.path.split('/').pop()!,\n )\n mkdirSync(destination, { recursive: true })\n cpSync(templateDir, destination, { recursive: true })\n } else {\n await downloadFromGithub(template.path, destination)\n adaptForStandalone(destination, template)\n }\n\n writePackageJson(destination, projectName, template)\n\n console.log(`\\nCreated \"${projectName}\" from the \"${template.name}\" template.\\n`)\n console.log('Next steps:')\n console.log(` cd ${projectName}`)\n console.log(' vp install')\n if (template.scripts.dev) {\n console.log(` vp run dev`)\n } else {\n console.log(` vp run build`)\n }\n console.log()\n}\n"],"mappings":";;;;;;;;;;AAqBA,MAAM,cAAc;AAEpB,SAAS,oBAA4B;AACnC,KAAI;EACF,MAAM,UAAU,QAAQ,OAAO,KAAK,SAAS,MAAM,MAAM,eAAe;AAExE,SAAO,IADK,KAAK,MAAM,aAAa,SAAS,QAAQ,CAAC,CACvC,WAAW;SACpB;AACN,SAAO;;;AAaX,MAAa,YAAwB;CACnC;EACE,MAAM;EACN,aAAa;EACb,QAAQ;EACR,MAAM;EACN,YAAY;EACZ,SAAS;GAAE,KAAK;GAAiB,OAAO;GAAmB,SAAS;GAAqB;EAC1F;CACD;EACE,MAAM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AAG;CAGjG,MAAM,cAAc,QAAQ,YAAY;AACxC,KAAI,WAAW,YAAY,IAAI,YAAY,YAAY,CAAC,SAAS,EAC/D,OAAM,IAAI,MAAM,cAAc,YAAY,oCAAoC;AAGhF,KAAI,SAAS,WAAW,SAAS;EAC/B,MAAM,cAAc,QAClB,OAAO,KAAK,SACZ,mBACA,SAAS,KAAK,MAAM,IAAI,CAAC,KAAK,CAC/B;AACD,YAAU,aAAa,EAAE,WAAW,MAAM,CAAC;AAC3C,SAAO,aAAa,aAAa,EAAE,WAAW,MAAM,CAAC;QAChD;AACL,QAAM,mBAAmB,SAAS,MAAM,YAAY;AACpD,qBAAmB,aAAa,SAAS;;AAG3C,kBAAiB,aAAa,aAAa,SAAS;AAEpD,SAAQ,IAAI,cAAc,YAAY,cAAc,SAAS,KAAK,eAAe;AACjF,SAAQ,IAAI,cAAc;AAC1B,SAAQ,IAAI,QAAQ,cAAc;AAClC,SAAQ,IAAI,eAAe;AAC3B,KAAI,SAAS,QAAQ,IACnB,SAAQ,IAAI,eAAe;KAE3B,SAAQ,IAAI,iBAAiB;AAE/B,SAAQ,KAAK"}
|
package/dist/css/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as buildCss } from "../index-
|
|
1
|
+
import { n as buildCss } from "../index-B7NRZAxd.mjs";
|
|
2
2
|
export { buildCss };
|
|
@@ -24,4 +24,4 @@ declare const HeadingSchema: z.ZodObject<{
|
|
|
24
24
|
type Heading = z.infer<typeof HeadingSchema>;
|
|
25
25
|
//#endregion
|
|
26
26
|
export { MarkdownConfigSchema as i, HeadingSchema as n, MarkdownConfig as r, Heading as t };
|
|
27
|
-
//# sourceMappingURL=heading-
|
|
27
|
+
//# sourceMappingURL=heading-Dhvzlay-.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heading-
|
|
1
|
+
{"version":3,"file":"heading-Dhvzlay-.d.mts","names":[],"sources":["../src/schemas/markdown-config.ts","../src/schemas/heading.ts"],"mappings":";;;cAIa,oBAAA,EAAoB,CAAA,CAAA,SAAA;;;;;;;;;;;;KAerB,cAAA,GAAiB,CAAA,CAAE,KAAA,QAAa,oBAAA;;;cCf/B,aAAA,EAAa,CAAA,CAAA,SAAA;;;;;KAMd,OAAA,GAAU,CAAA,CAAE,KAAA,QAAa,aAAA"}
|
|
@@ -10,4 +10,4 @@ type CssBuildOptions = {
|
|
|
10
10
|
declare function buildCss(entryPath: string, config?: CssBuildOptions): string;
|
|
11
11
|
//#endregion
|
|
12
12
|
export { buildCss as n, CssBuildOptions as t };
|
|
13
|
-
//# sourceMappingURL=index-
|
|
13
|
+
//# sourceMappingURL=index-B7NRZAxd.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-B7NRZAxd.d.mts","names":[],"sources":["../src/css/builder.ts"],"mappings":";KAGY,eAAA;EACV,MAAA;EACA,OAAA;IACE,MAAA;IACA,OAAA;IACA,MAAA;EAAA;AAAA;AAAA,iBAIY,QAAA,CAAS,SAAA,UAAmB,MAAA,GAAS,eAAA"}
|
|
@@ -38,4 +38,4 @@ declare const BlogFrontmatterSchema: z.ZodObject<{
|
|
|
38
38
|
type BlogFrontmatter = z.infer<typeof BlogFrontmatterSchema>;
|
|
39
39
|
//#endregion
|
|
40
40
|
export { ProjectFrontmatter as a, BlogFrontmatterSchema as i, BaseFrontmatterSchema as n, ProjectFrontmatterSchema as o, BlogFrontmatter as r, BaseFrontmatter as t };
|
|
41
|
-
//# sourceMappingURL=index-
|
|
41
|
+
//# sourceMappingURL=index-C0QFHYwb.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-C0QFHYwb.d.mts","names":[],"sources":["../src/schemas/frontmatter.ts"],"mappings":";;;cAIa,qBAAA,EAAqB,CAAA,CAAA,SAAA;;;;;;;;KAWtB,eAAA,GAAkB,CAAA,CAAE,KAAA,QAAa,qBAAA;AAAA,cAIhC,wBAAA,EAAwB,CAAA,CAAA,SAAA;;;;;;;;;;;;;KAYzB,kBAAA,GAAqB,CAAA,CAAE,KAAA,QAAa,wBAAA;AAAA,cAInC,qBAAA,EAAqB,CAAA,CAAA,SAAA;;;;;;;;;;;KAMtB,eAAA,GAAkB,CAAA,CAAE,KAAA,QAAa,qBAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as MarkdownConfig, t as Heading } from "./heading-
|
|
1
|
+
import { r as MarkdownConfig, t as Heading } from "./heading-Dhvzlay-.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/markdown/pipeline.d.ts
|
|
4
4
|
type MarkdownResult = {
|
|
@@ -12,4 +12,4 @@ declare function processMarkdown(raw: string, config?: MarkdownConfig, preExtrac
|
|
|
12
12
|
}): Promise<MarkdownResult>;
|
|
13
13
|
//#endregion
|
|
14
14
|
export { processMarkdown as n, MarkdownResult as t };
|
|
15
|
-
//# sourceMappingURL=index-
|
|
15
|
+
//# sourceMappingURL=index-CJkBs8YQ.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-CJkBs8YQ.d.mts","names":[],"sources":["../src/markdown/pipeline.ts"],"mappings":";;;KAuBY,cAAA;EACV,IAAA;EACA,QAAA,EAAU,OAAA;EACV,WAAA,EAAa,MAAA;AAAA;AAAA,iBAoJO,eAAA,CACpB,GAAA,UACA,MAAA,GAAS,cAAA,EACT,YAAA;EAAiB,OAAA;EAAiB,WAAA,EAAa,MAAA;AAAA,IAC9C,OAAA,CAAQ,cAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as LoaderResult, r as LoaderType, t as Loader } from "./types-
|
|
1
|
+
import { n as LoaderResult, r as LoaderType, t as Loader } from "./types-B-V5qemH.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/loaders/json.d.ts
|
|
4
4
|
declare class JsonLoader implements Loader {
|
|
@@ -58,4 +58,4 @@ declare function resolveLoader(loaderOrType: LoaderType | Loader): Loader;
|
|
|
58
58
|
declare function defaultIncludePatterns(loader: Loader): string[];
|
|
59
59
|
//#endregion
|
|
60
60
|
export { TomlLoader as a, JsoncLoader as c, YamlLoader as i, JsonLoader as l, registerLoader as n, MarkdownLoader as o, resolveLoader as r, LoaderError as s, defaultIncludePatterns as t };
|
|
61
|
-
//# sourceMappingURL=index-
|
|
61
|
+
//# sourceMappingURL=index-DCznbvaV.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-DCznbvaV.d.mts","names":[],"sources":["../src/loaders/json.ts","../src/loaders/jsonc.ts","../src/loaders/errors.ts","../src/loaders/markdown.ts","../src/loaders/toml.ts","../src/loaders/yaml.ts","../src/loaders/index.ts"],"mappings":";;;cAWa,UAAA,YAAsB,MAAA;EACjC,IAAA;EACA,IAAA;EACA,UAAA;EAEM,IAAA,CAAK,QAAA,WAAmB,OAAA,CAAQ,YAAA;AAAA;;;cCoC3B,WAAA,YAAuB,MAAA;EAClC,IAAA;EACA,IAAA;EACA,UAAA;EAEM,IAAA,CAAK,QAAA,WAAmB,OAAA,CAAQ,YAAA;AAAA;;;cCzD3B,WAAA,SAAoB,KAAA;EAAA,SACtB,QAAA;EAAA,SACA,MAAA;EAAA,SACA,IAAA;EAAA,SACA,MAAA;cAEG,OAAA,UAAiB,QAAA,UAAkB,MAAA,UAAgB,IAAA,WAAe,MAAA;AAAA;;;cCOnE,cAAA,YAA0B,MAAA;EACrC,IAAA;EACA,IAAA;EACA,UAAA;EAEM,IAAA,CAAK,QAAA,WAAmB,OAAA,CAAQ,YAAA;AAAA;;;cCT3B,UAAA,YAAsB,MAAA;EACjC,IAAA;EACA,IAAA;EACA,UAAA;EAEM,IAAA,CAAK,QAAA,WAAmB,OAAA,CAAQ,YAAA;AAAA;;;cCL3B,UAAA,YAAsB,MAAA;EACjC,IAAA;EACA,IAAA;EACA,UAAA;EAEM,IAAA,CAAK,QAAA,WAAmB,OAAA,CAAQ,YAAA;AAAA;;;;iBCgBxB,cAAA,CAAe,IAAA,UAAc,MAAA,EAAQ,MAAA;;iBAKrC,aAAA,CAAc,YAAA,EAAc,UAAA,GAAa,MAAA,GAAS,MAAA;;iBAwBlD,sBAAA,CAAuB,MAAA,EAAQ,MAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as
|
|
3
|
-
import { n as
|
|
4
|
-
import {
|
|
5
|
-
import { i as
|
|
1
|
+
import { n as buildCss, t as CssBuildOptions } from "./index-B7NRZAxd.mjs";
|
|
2
|
+
import { n as LoaderResult, r as LoaderType, t as Loader } from "./types-B-V5qemH.mjs";
|
|
3
|
+
import { a as CollectionMap, c as RawEntry, d as ValidatorContext, f as ValidationEntryResult, i as CollectionDef, l as ContentValidator, m as ValidationResult, n as ContentPlugin, o as InferCollectionData, p as ValidationIssue, r as CollectionComputed, s as InferCollectionLoaderKind, t as ContentLayerConfig, u as ResolvedValidatorContext } from "./content-config-DJXUOcNG.mjs";
|
|
4
|
+
import { i as MarkdownConfigSchema, n as HeadingSchema, r as MarkdownConfig, t as Heading } from "./heading-Dhvzlay-.mjs";
|
|
5
|
+
import { _ as ConvertResult, a as WatchEvent, c as builtinMarkdownValidators, d as linkValidator, f as headingValidator, g as ConvertOptions, h as RenderedContent, i as WatchCallback, l as runValidators, m as ContentEntry, n as LayerConvertOptions, o as WatchHandle, p as codeBlockValidator, r as TypedContentLayer, s as createContentLayer, t as ContentLayer, u as createLinkValidator, v as convert } from "./content-layer-CpHYUYNN.mjs";
|
|
6
6
|
import { Fragment, HtmlString, h } from "./jsx-runtime/index.mjs";
|
|
7
|
-
import { n as processMarkdown, t as MarkdownResult } from "./index-
|
|
8
|
-
import { a as ProjectFrontmatter, i as BlogFrontmatterSchema, n as BaseFrontmatterSchema, o as ProjectFrontmatterSchema, r as BlogFrontmatter, t as BaseFrontmatter } from "./index-
|
|
9
|
-
import { a as TomlLoader, c as JsoncLoader, i as YamlLoader, l as JsonLoader, n as registerLoader, o as MarkdownLoader } from "./index-
|
|
7
|
+
import { n as processMarkdown, t as MarkdownResult } from "./index-CJkBs8YQ.mjs";
|
|
8
|
+
import { a as ProjectFrontmatter, i as BlogFrontmatterSchema, n as BaseFrontmatterSchema, o as ProjectFrontmatterSchema, r as BlogFrontmatter, t as BaseFrontmatter } from "./index-C0QFHYwb.mjs";
|
|
9
|
+
import { a as TomlLoader, c as JsoncLoader, i as YamlLoader, l as JsonLoader, n as registerLoader, o as MarkdownLoader } from "./index-DCznbvaV.mjs";
|
|
10
10
|
import { ZodSchema, z, z as z$1 } from "zod";
|
|
11
11
|
|
|
12
12
|
//#region src/config.d.ts
|
|
@@ -19,95 +19,6 @@ declare function defineCollection<const S extends z$1.ZodType, const TComputed e
|
|
|
19
19
|
/** Define a named collection map with strong literal inference. */
|
|
20
20
|
declare function defineCollections<const TCollections extends CollectionMap>(collections: TCollections): TCollections;
|
|
21
21
|
//#endregion
|
|
22
|
-
//#region src/convert.d.ts
|
|
23
|
-
type ConvertOptions = {
|
|
24
|
-
markdown?: MarkdownConfig;
|
|
25
|
-
};
|
|
26
|
-
type ConvertResult = {
|
|
27
|
-
html: string;
|
|
28
|
-
toc: Heading[];
|
|
29
|
-
frontmatter: Record<string, unknown>;
|
|
30
|
-
};
|
|
31
|
-
declare function convert(input: string, options?: ConvertOptions): Promise<ConvertResult>;
|
|
32
|
-
//#endregion
|
|
33
|
-
//#region src/entry.d.ts
|
|
34
|
-
type RenderedContent = {
|
|
35
|
-
/** Processed HTML */html: string; /** Extracted headings for TOC */
|
|
36
|
-
headings: Heading[]; /** Estimated read time in minutes */
|
|
37
|
-
readTime: number;
|
|
38
|
-
};
|
|
39
|
-
declare class ContentEntry<T = Record<string, any>> {
|
|
40
|
-
/** URL-friendly identifier */
|
|
41
|
-
readonly slug: string;
|
|
42
|
-
/** Collection this entry belongs to */
|
|
43
|
-
readonly collection: string;
|
|
44
|
-
/** Absolute path to source file */
|
|
45
|
-
readonly filePath: string;
|
|
46
|
-
/** Validated data (frontmatter or parsed data) */
|
|
47
|
-
readonly data: T;
|
|
48
|
-
/** Raw body content (markdown only) */
|
|
49
|
-
readonly rawContent?: string;
|
|
50
|
-
/** Cached render result */
|
|
51
|
-
private _rendered?;
|
|
52
|
-
/** Markdown config for rendering */
|
|
53
|
-
private _markdownConfig;
|
|
54
|
-
constructor(slug: string, collection: string, filePath: string, data: T, rawContent: string | undefined, markdownConfig: MarkdownConfig);
|
|
55
|
-
/** Render the entry content to HTML. Cached after first call. */
|
|
56
|
-
render(options?: {
|
|
57
|
-
force?: boolean;
|
|
58
|
-
}): Promise<RenderedContent>;
|
|
59
|
-
/** Clear cached render result. */
|
|
60
|
-
clearRenderCache(): void;
|
|
61
|
-
}
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/validation/code-block-validator.d.ts
|
|
64
|
-
declare const codeBlockValidator: ContentValidator;
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/validation/heading-validator.d.ts
|
|
67
|
-
declare const headingValidator: ContentValidator;
|
|
68
|
-
//#endregion
|
|
69
|
-
//#region src/validation/link-validator.d.ts
|
|
70
|
-
type LinkValidatorOptions = {
|
|
71
|
-
/** Glob patterns for internal links to skip file-existence checks on. */skipPatterns?: string[];
|
|
72
|
-
};
|
|
73
|
-
declare function createLinkValidator(options?: LinkValidatorOptions): ContentValidator;
|
|
74
|
-
declare const linkValidator: ContentValidator;
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/validation/runner.d.ts
|
|
77
|
-
/** The built-in validators for markdown content. */
|
|
78
|
-
declare const builtinMarkdownValidators: ContentValidator[];
|
|
79
|
-
/** Run all validators on a single content entry. */
|
|
80
|
-
declare function runValidators(ctx: ValidatorContext, validators: ContentValidator[]): Promise<ValidationIssue[]>;
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/content-layer.d.ts
|
|
83
|
-
interface ContentLayer {
|
|
84
|
-
/** Get all entries in a collection. */
|
|
85
|
-
getCollection(name: string): Promise<ContentEntry[]>;
|
|
86
|
-
/** Get a single entry by collection name and slug. */
|
|
87
|
-
getEntry(collection: string, slug: string): Promise<ContentEntry | undefined>;
|
|
88
|
-
/** Convert raw markdown to HTML (no collection, no validation). */
|
|
89
|
-
convert(markdown: string, options?: LayerConvertOptions): Promise<ConvertResult>;
|
|
90
|
-
/** Invalidate a single entry's cache. */
|
|
91
|
-
invalidate(collection: string, slug: string): Promise<void>;
|
|
92
|
-
/** Invalidate an entire collection's cache. */
|
|
93
|
-
invalidateCollection(collection: string): Promise<void>;
|
|
94
|
-
/** Invalidate all cached data. */
|
|
95
|
-
invalidateAll(): void;
|
|
96
|
-
/** Validate all entries in a collection (or all collections). */
|
|
97
|
-
validate(collection?: string): Promise<ValidationResult[]>;
|
|
98
|
-
/** Get the names of all configured collections. */
|
|
99
|
-
getCollectionNames(): string[];
|
|
100
|
-
/** Get the definition of a collection. */
|
|
101
|
-
getCollectionDef(name: string): CollectionDef | undefined;
|
|
102
|
-
/** Get all collection definitions. */
|
|
103
|
-
getCollections(): Record<string, CollectionDef>;
|
|
104
|
-
}
|
|
105
|
-
type LayerConvertOptions = {
|
|
106
|
-
markdown?: MarkdownConfig;
|
|
107
|
-
};
|
|
108
|
-
/** Create a new content layer from a configuration. */
|
|
109
|
-
declare function createContentLayer(config: ContentLayerConfig): ContentLayer;
|
|
110
|
-
//#endregion
|
|
111
22
|
//#region src/frontmatter.d.ts
|
|
112
23
|
type FrontmatterResult = {
|
|
113
24
|
frontmatter: Record<string, any>;
|
|
@@ -115,7 +26,12 @@ type FrontmatterResult = {
|
|
|
115
26
|
};
|
|
116
27
|
/** Extract frontmatter from raw markdown using gray-matter. */
|
|
117
28
|
declare function extractFrontmatter(raw: string): FrontmatterResult;
|
|
118
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Validate frontmatter against a Zod schema. Returns parsed data or errors.
|
|
31
|
+
*
|
|
32
|
+
* @deprecated Use `validateSchema()` from `@pagesmith/core` for richer
|
|
33
|
+
* validation results including field paths and severity levels.
|
|
34
|
+
*/
|
|
119
35
|
declare function validateFrontmatter<T>(frontmatter: Record<string, any>, schema: ZodSchema<T>): {
|
|
120
36
|
success: true;
|
|
121
37
|
data: T;
|
|
@@ -133,5 +49,5 @@ declare function validateFrontmatter<T>(frontmatter: Record<string, any>, schema
|
|
|
133
49
|
*/
|
|
134
50
|
declare function extractToc(html: string): Heading[];
|
|
135
51
|
//#endregion
|
|
136
|
-
export { type
|
|
52
|
+
export { type BaseFrontmatter, BaseFrontmatterSchema, type BlogFrontmatter, BlogFrontmatterSchema, type CollectionComputed, type CollectionDef, type CollectionMap, ContentEntry, type ContentLayer, type ContentLayerConfig, type ContentPlugin, type ContentValidator, type ConvertOptions, type ConvertResult, type CssBuildOptions, Fragment, type FrontmatterResult, type Heading, HeadingSchema, HtmlString, type InferCollectionData, type InferCollectionLoaderKind, JsonLoader, JsoncLoader, type LayerConvertOptions, type Loader, type LoaderResult, type LoaderType, type MarkdownConfig, MarkdownConfigSchema, MarkdownLoader, type MarkdownResult, type ProjectFrontmatter, ProjectFrontmatterSchema, type RawEntry, type RenderedContent, type ResolvedValidatorContext, TomlLoader, type TypedContentLayer, type ValidationEntryResult, type ValidationIssue, type ValidationResult, type ValidatorContext, type WatchCallback, type WatchEvent, type WatchHandle, YamlLoader, buildCss, builtinMarkdownValidators, codeBlockValidator, convert, createContentLayer, createLinkValidator, defineCollection, defineCollections, defineConfig, extractFrontmatter, extractToc, h, headingValidator, linkValidator, processMarkdown, registerLoader, runValidators, validateFrontmatter, z };
|
|
137
53
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/config.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/config.ts","../src/frontmatter.ts","../src/toc.ts"],"mappings":";;;;;;;;;;;;;iBAagB,YAAA,CAAa,MAAA,EAAQ,kBAAA,GAAqB,kBAAA;AAA1D;AAAA,iBAKgB,gBAAA,iBACE,GAAA,CAAE,OAAA,0BACM,kBAAA,6BACF,UAAA,GAAa,MAAA,GAAS,UAAA,GAAa,MAAA,CAAA,CAEzD,GAAA,EAAK,IAAA,CAAK,aAAA,CAAc,CAAA,EAAG,SAAA,EAAW,OAAA;EACpC,QAAA,GAAW,SAAA,GAAY,kBAAA;AAAA,IAExB,aAAA,CAAc,CAAA,EAAG,SAAA,EAAW,OAAA;;iBAKf,iBAAA,4BAA6C,aAAA,CAAA,CAC3D,WAAA,EAAa,YAAA,GACZ,YAAA;;;KCrBS,iBAAA;EACV,WAAA,EAAa,MAAA;EACb,OAAA;AAAA;;iBAIc,kBAAA,CAAmB,GAAA,WAAc,iBAAA;;;;;;;iBAWjC,mBAAA,GAAA,CACd,WAAA,EAAa,MAAA,eACb,MAAA,EAAQ,SAAA,CAAU,CAAA;EACf,OAAA;EAAe,IAAA,EAAM,CAAA;AAAA;EAAQ,OAAA;EAAgB,MAAA;AAAA;;;;;;;;;iBCxBlC,UAAA,CAAW,IAAA,WAAe,OAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { t as processMarkdown } from "./markdown-
|
|
2
|
-
import { a as linkValidator,
|
|
1
|
+
import { t as processMarkdown } from "./markdown-BmDJgYeB.mjs";
|
|
2
|
+
import { a as linkValidator, c as validateSchema, d as convert, i as createLinkValidator, n as builtinMarkdownValidators, o as headingValidator, r as runValidators, s as codeBlockValidator, t as createContentLayer, u as ContentEntry } from "./content-layer-B5enqWeJ.mjs";
|
|
3
3
|
import { a as TomlLoader, c as JsonLoader, i as YamlLoader, n as registerLoader, o as MarkdownLoader, s as JsoncLoader } from "./loaders-Cf-BXf2L.mjs";
|
|
4
4
|
import { Fragment, HtmlString, h } from "./jsx-runtime/index.mjs";
|
|
5
5
|
import { t as buildCss } from "./css-BneO430t.mjs";
|
|
6
6
|
import { a as ProjectFrontmatterSchema, i as BlogFrontmatterSchema, n as HeadingSchema, r as BaseFrontmatterSchema, t as MarkdownConfigSchema } from "./schemas-UL4ynWsA.mjs";
|
|
7
|
-
import { getAiArtifactContent, getAiArtifacts, installAiArtifacts } from "./ai/index.mjs";
|
|
8
7
|
import matter from "gray-matter";
|
|
9
8
|
import { parse } from "yaml";
|
|
10
9
|
import { z } from "zod";
|
|
@@ -37,16 +36,21 @@ function extractFrontmatter(raw) {
|
|
|
37
36
|
content
|
|
38
37
|
};
|
|
39
38
|
}
|
|
40
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Validate frontmatter against a Zod schema. Returns parsed data or errors.
|
|
41
|
+
*
|
|
42
|
+
* @deprecated Use `validateSchema()` from `@pagesmith/core` for richer
|
|
43
|
+
* validation results including field paths and severity levels.
|
|
44
|
+
*/
|
|
41
45
|
function validateFrontmatter(frontmatter, schema) {
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
46
|
+
const { issues, validatedData } = validateSchema(frontmatter, schema);
|
|
47
|
+
if (issues.length === 0) return {
|
|
44
48
|
success: true,
|
|
45
|
-
data:
|
|
49
|
+
data: validatedData
|
|
46
50
|
};
|
|
47
51
|
return {
|
|
48
52
|
success: false,
|
|
49
|
-
errors:
|
|
53
|
+
errors: issues.map((issue) => issue.field ? `${issue.field}: ${issue.message}` : issue.message)
|
|
50
54
|
};
|
|
51
55
|
}
|
|
52
56
|
//#endregion
|
|
@@ -74,6 +78,6 @@ function extractToc(html) {
|
|
|
74
78
|
return headings;
|
|
75
79
|
}
|
|
76
80
|
//#endregion
|
|
77
|
-
export { BaseFrontmatterSchema, BlogFrontmatterSchema, ContentEntry, Fragment, HeadingSchema, HtmlString, JsonLoader, JsoncLoader, MarkdownConfigSchema, MarkdownLoader, ProjectFrontmatterSchema, TomlLoader, YamlLoader, buildCss, builtinMarkdownValidators, codeBlockValidator, convert, createContentLayer, createLinkValidator, defineCollection, defineCollections, defineConfig, extractFrontmatter, extractToc,
|
|
81
|
+
export { BaseFrontmatterSchema, BlogFrontmatterSchema, ContentEntry, Fragment, HeadingSchema, HtmlString, JsonLoader, JsoncLoader, MarkdownConfigSchema, MarkdownLoader, ProjectFrontmatterSchema, TomlLoader, YamlLoader, buildCss, builtinMarkdownValidators, codeBlockValidator, convert, createContentLayer, createLinkValidator, defineCollection, defineCollections, defineConfig, extractFrontmatter, extractToc, h, headingValidator, linkValidator, processMarkdown, registerLoader, runValidators, validateFrontmatter, z };
|
|
78
82
|
|
|
79
83
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["parseYaml"],"sources":["../src/config.ts","../src/frontmatter.ts","../src/toc.ts"],"sourcesContent":["/**\n * Configuration helpers.\n *\n * defineConfig() and defineCollection() are type-safe identity functions\n * that provide TypeScript inference for collection schemas.\n */\n\nimport type { z } from 'zod'\nimport type { CollectionComputed, CollectionDef, CollectionMap } from './schemas/collection'\nimport type { Loader, LoaderType } from './loaders/types'\nimport type { ContentLayerConfig } from './schemas/content-config'\n\n/** Define a content layer configuration with type inference. */\nexport function defineConfig(config: ContentLayerConfig): ContentLayerConfig {\n return config\n}\n\n/** Define a collection with Zod schema type inference. */\nexport function defineCollection<\n const S extends z.ZodType,\n const TComputed extends CollectionComputed = {},\n const TLoader extends LoaderType | Loader = LoaderType | Loader,\n>(\n def: Omit<CollectionDef<S, TComputed, TLoader>, 'computed'> & {\n computed?: TComputed & CollectionComputed\n },\n): CollectionDef<S, TComputed, TLoader> {\n return def\n}\n\n/** Define a named collection map with strong literal inference. */\nexport function defineCollections<const TCollections extends CollectionMap>(\n collections: TCollections,\n): TCollections {\n return collections\n}\n","/**\n * Frontmatter extraction and validation.\n *\n * Uses gray-matter to parse YAML frontmatter from markdown,\n * and optionally validates against a Zod schema.\n */\n\nimport matter from 'gray-matter'\nimport { parse as parseYaml } from 'yaml'\nimport type { ZodSchema } from 'zod'\n\nexport type FrontmatterResult = {\n frontmatter: Record<string, any>\n content: string\n}\n\n/** Extract frontmatter from raw markdown using gray-matter. */\nexport function extractFrontmatter(raw: string): FrontmatterResult {\n const { data, content } = matter(raw, { engines: { yaml: parseYaml } })\n return { frontmatter: data, content }\n}\n\n
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["parseYaml"],"sources":["../src/config.ts","../src/frontmatter.ts","../src/toc.ts"],"sourcesContent":["/**\n * Configuration helpers.\n *\n * defineConfig() and defineCollection() are type-safe identity functions\n * that provide TypeScript inference for collection schemas.\n */\n\nimport type { z } from 'zod'\nimport type { CollectionComputed, CollectionDef, CollectionMap } from './schemas/collection'\nimport type { Loader, LoaderType } from './loaders/types'\nimport type { ContentLayerConfig } from './schemas/content-config'\n\n/** Define a content layer configuration with type inference. */\nexport function defineConfig(config: ContentLayerConfig): ContentLayerConfig {\n return config\n}\n\n/** Define a collection with Zod schema type inference. */\nexport function defineCollection<\n const S extends z.ZodType,\n const TComputed extends CollectionComputed = {},\n const TLoader extends LoaderType | Loader = LoaderType | Loader,\n>(\n def: Omit<CollectionDef<S, TComputed, TLoader>, 'computed'> & {\n computed?: TComputed & CollectionComputed\n },\n): CollectionDef<S, TComputed, TLoader> {\n return def\n}\n\n/** Define a named collection map with strong literal inference. */\nexport function defineCollections<const TCollections extends CollectionMap>(\n collections: TCollections,\n): TCollections {\n return collections\n}\n","/**\n * Frontmatter extraction and validation.\n *\n * Uses gray-matter to parse YAML frontmatter from markdown,\n * and optionally validates against a Zod schema.\n */\n\nimport matter from 'gray-matter'\nimport { parse as parseYaml } from 'yaml'\nimport type { ZodSchema } from 'zod'\nimport { validateSchema } from './validation/schema-validator'\n\nexport type FrontmatterResult = {\n frontmatter: Record<string, any>\n content: string\n}\n\n/** Extract frontmatter from raw markdown using gray-matter. */\nexport function extractFrontmatter(raw: string): FrontmatterResult {\n const { data, content } = matter(raw, { engines: { yaml: parseYaml } })\n return { frontmatter: data, content }\n}\n\n/**\n * Validate frontmatter against a Zod schema. Returns parsed data or errors.\n *\n * @deprecated Use `validateSchema()` from `@pagesmith/core` for richer\n * validation results including field paths and severity levels.\n */\nexport function validateFrontmatter<T>(\n frontmatter: Record<string, any>,\n schema: ZodSchema<T>,\n): { success: true; data: T } | { success: false; errors: string[] } {\n const { issues, validatedData } = validateSchema(frontmatter, schema)\n\n if (issues.length === 0) {\n return { success: true, data: validatedData as T }\n }\n\n const errors = issues.map((issue) =>\n issue.field ? `${issue.field}: ${issue.message}` : issue.message,\n )\n return { success: false, errors }\n}\n","import type { Heading } from './schemas/heading'\n\n/**\n * Extract table of contents headings from an HTML string.\n *\n * Regex-based: finds <h[1-6] id=\"...\">text</h[1-6]>, strips inner HTML tags.\n * No dependency on unified — works on any HTML string.\n */\nexport function extractToc(html: string): Heading[] {\n const headings: Heading[] = []\n const re = /<h([1-6])\\s+id=\"([^\"]*)\"[^>]*>([\\s\\S]*?)<\\/h\\1>/gi\n let match: RegExpExecArray | null\n\n while ((match = re.exec(html)) !== null) {\n const depth = parseInt(match[1], 10)\n const slug = match[2]\n // Strip inner HTML tags to get plain text\n const text = match[3].replace(/<[^>]+>/g, '').trim()\n headings.push({ depth, text, slug })\n }\n\n return headings\n}\n"],"mappings":";;;;;;;;;;;AAaA,SAAgB,aAAa,QAAgD;AAC3E,QAAO;;;AAIT,SAAgB,iBAKd,KAGsC;AACtC,QAAO;;;AAIT,SAAgB,kBACd,aACc;AACd,QAAO;;;;;;;;;;;AChBT,SAAgB,mBAAmB,KAAgC;CACjE,MAAM,EAAE,MAAM,YAAY,OAAO,KAAK,EAAE,SAAS,EAAE,MAAMA,OAAW,EAAE,CAAC;AACvE,QAAO;EAAE,aAAa;EAAM;EAAS;;;;;;;;AASvC,SAAgB,oBACd,aACA,QACmE;CACnE,MAAM,EAAE,QAAQ,kBAAkB,eAAe,aAAa,OAAO;AAErE,KAAI,OAAO,WAAW,EACpB,QAAO;EAAE,SAAS;EAAM,MAAM;EAAoB;AAMpD,QAAO;EAAE,SAAS;EAAO,QAHV,OAAO,KAAK,UACzB,MAAM,QAAQ,GAAG,MAAM,MAAM,IAAI,MAAM,YAAY,MAAM,QAC1D;EACgC;;;;;;;;;;AClCnC,SAAgB,WAAW,MAAyB;CAClD,MAAM,WAAsB,EAAE;CAC9B,MAAM,KAAK;CACX,IAAI;AAEJ,SAAQ,QAAQ,GAAG,KAAK,KAAK,MAAM,MAAM;EACvC,MAAM,QAAQ,SAAS,MAAM,IAAI,GAAG;EACpC,MAAM,OAAO,MAAM;EAEnB,MAAM,OAAO,MAAM,GAAG,QAAQ,YAAY,GAAG,CAAC,MAAM;AACpD,WAAS,KAAK;GAAE;GAAO;GAAM;GAAM,CAAC;;AAGtC,QAAO"}
|
package/dist/loaders/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as LoaderResult, r as LoaderType, t as Loader } from "../types-
|
|
2
|
-
import { a as TomlLoader, c as JsoncLoader, i as YamlLoader, l as JsonLoader, n as registerLoader, o as MarkdownLoader, r as resolveLoader, s as LoaderError, t as defaultIncludePatterns } from "../index-
|
|
1
|
+
import { n as LoaderResult, r as LoaderType, t as Loader } from "../types-B-V5qemH.mjs";
|
|
2
|
+
import { a as TomlLoader, c as JsoncLoader, i as YamlLoader, l as JsonLoader, n as registerLoader, o as MarkdownLoader, r as resolveLoader, s as LoaderError, t as defaultIncludePatterns } from "../index-DCznbvaV.mjs";
|
|
3
3
|
export { JsonLoader, JsoncLoader, Loader, LoaderError, LoaderResult, LoaderType, MarkdownLoader, TomlLoader, YamlLoader, defaultIncludePatterns, registerLoader, resolveLoader };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { r as MarkdownConfig } from "../heading-
|
|
2
|
-
import { n as processMarkdown, t as MarkdownResult } from "../index-
|
|
1
|
+
import { r as MarkdownConfig } from "../heading-Dhvzlay-.mjs";
|
|
2
|
+
import { n as processMarkdown, t as MarkdownResult } from "../index-CJkBs8YQ.mjs";
|
|
3
3
|
export { MarkdownConfig, MarkdownResult, processMarkdown };
|
package/dist/markdown/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as processMarkdown } from "../markdown-
|
|
1
|
+
import { t as processMarkdown } from "../markdown-BmDJgYeB.mjs";
|
|
2
2
|
export { processMarkdown };
|
|
@@ -86,6 +86,28 @@ function createProcessor(config) {
|
|
|
86
86
|
processor.use(rehypeStringify, { allowDangerousHtml: true });
|
|
87
87
|
return processor;
|
|
88
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Processor cache keyed by MarkdownConfig object reference.
|
|
91
|
+
*
|
|
92
|
+
* **Why a WeakMap keyed by object reference?**
|
|
93
|
+
* Building a unified processor chain is expensive — it loads Shiki grammars,
|
|
94
|
+
* theme JSON, and instantiates every remark/rehype plugin. Caching the
|
|
95
|
+
* processor by config reference lets callers that reuse the same config object
|
|
96
|
+
* (the common case) skip all of that setup on subsequent calls. The WeakMap
|
|
97
|
+
* also ensures that if a config object is garbage-collected, its processor is
|
|
98
|
+
* too, so long-running processes don't leak memory.
|
|
99
|
+
*
|
|
100
|
+
* **Why is the config frozen?**
|
|
101
|
+
* The cache assumes the config does not change after the processor is built.
|
|
102
|
+
* If a caller mutated a config object after the processor was created, later
|
|
103
|
+
* calls would still receive the stale processor (keyed by the same reference),
|
|
104
|
+
* producing silently wrong output. Freezing the config at first use turns that
|
|
105
|
+
* silent bug into a loud TypeError on any attempted mutation.
|
|
106
|
+
*
|
|
107
|
+
* **What if a consumer needs different settings?**
|
|
108
|
+
* Pass a new config object — a fresh reference gets its own cache entry.
|
|
109
|
+
* For example: `processMarkdown(md, { ...existingConfig, remarkPlugins: [...] })`.
|
|
110
|
+
*/
|
|
89
111
|
const processorCache = /* @__PURE__ */ new WeakMap();
|
|
90
112
|
async function processMarkdown(raw, config, preExtracted) {
|
|
91
113
|
let frontmatter;
|
|
@@ -120,4 +142,4 @@ async function processMarkdown(raw, config, preExtracted) {
|
|
|
120
142
|
//#endregion
|
|
121
143
|
export { processMarkdown as t };
|
|
122
144
|
|
|
123
|
-
//# sourceMappingURL=markdown-
|
|
145
|
+
//# sourceMappingURL=markdown-BmDJgYeB.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-CyrHoDhP.mjs","names":["parseYaml"],"sources":["../src/markdown/pipeline.ts"],"sourcesContent":["import matter from 'gray-matter'\nimport { parse as parseYaml } from 'yaml'\nimport { rehypeAccessibleEmojis } from 'rehype-accessible-emojis'\nimport rehypeAutolinkHeadings from 'rehype-autolink-headings'\nimport rehypeExpressiveCode, {\n type BundledShikiTheme,\n type RehypeExpressiveCodeOptions,\n} from 'rehype-expressive-code'\nimport rehypeExternalLinks from 'rehype-external-links'\nimport rehypeMathjax from 'rehype-mathjax/svg'\nimport rehypeSlug from 'rehype-slug'\nimport rehypeStringify from 'rehype-stringify'\nimport remarkFrontmatter from 'remark-frontmatter'\nimport remarkGfm from 'remark-gfm'\nimport remarkGithubAlerts from 'remark-github-alerts'\nimport remarkMath from 'remark-math'\nimport remarkParse from 'remark-parse'\nimport remarkRehype from 'remark-rehype'\nimport remarkSmartypants from 'remark-smartypants'\nimport { unified } from 'unified'\nimport type { Heading } from '../schemas/heading'\nimport type { MarkdownConfig } from '../schemas/markdown-config'\n\nexport type MarkdownResult = {\n html: string\n headings: Heading[]\n frontmatter: Record<string, unknown>\n}\n\nexport type { MarkdownConfig }\n\nconst DEFAULT_MARKDOWN_CONFIG: MarkdownConfig = {}\n\n/** Default language aliases for fenced code blocks that Shiki doesn't recognize natively. */\nconst DEFAULT_LANG_ALIASES: Record<string, string> = {\n dot: 'text',\n mermaid: 'text',\n plantuml: 'text',\n excalidraw: 'json',\n drawio: 'xml',\n proto: 'protobuf',\n ejs: 'html',\n hbs: 'handlebars',\n}\n\nfunction getTextContent(node: any): string {\n if (node.type === 'text') return node.value || ''\n if (node.children) return node.children.map(getTextContent).join('')\n return ''\n}\n\nfunction extractHeadings(tree: any, headings: Heading[]): void {\n if (tree.type === 'element' && /^h[1-6]$/.test(tree.tagName)) {\n headings.push({\n depth: parseInt(tree.tagName[1]),\n text: getTextContent(tree),\n slug: tree.properties?.id || '',\n })\n }\n if (tree.children) {\n for (const child of tree.children) {\n extractHeadings(child, headings)\n }\n }\n}\n\nfunction createProcessor(config: MarkdownConfig) {\n const processor = unified()\n .use(remarkParse)\n .use(remarkGfm)\n .use(remarkMath)\n .use(remarkFrontmatter, ['yaml'])\n // GitHub-flavored alerts: > [!NOTE], > [!TIP], > [!IMPORTANT], > [!WARNING], > [!CAUTION]\n .use(remarkGithubAlerts)\n // Smart typography: \"smart quotes\", em—dashes, el…lipses\n .use(remarkSmartypants)\n\n if (config.remarkPlugins) {\n for (const plugin of config.remarkPlugins) {\n if (Array.isArray(plugin)) processor.use(plugin[0], plugin[1])\n else processor.use(plugin)\n }\n }\n\n // Apply language aliases to fenced code blocks before Expressive Code processes them.\n // Merge defaults with user-provided aliases (user overrides take precedence).\n const langAlias = { ...DEFAULT_LANG_ALIASES, ...config.shiki?.langAlias }\n processor.use(() => (tree: any) => {\n const visit = (node: any): void => {\n if (node?.type === 'code' && typeof node.lang === 'string' && langAlias[node.lang]) {\n node.lang = langAlias[node.lang]\n }\n if (Array.isArray(node?.children)) {\n for (const child of node.children) visit(child)\n }\n }\n visit(tree)\n })\n\n processor.use(remarkRehype, { allowDangerousHtml: true })\n\n // MathJax must run before Expressive Code so that math elements (from remark-math)\n // are rendered to SVG before Expressive Code tries to highlight them as code blocks.\n processor.use(rehypeMathjax)\n\n // Expressive Code — syntax highlighting, code frames, tabs, copy button\n const lightTheme = (config.shiki?.themes?.light || 'github-light') as BundledShikiTheme\n const darkTheme = (config.shiki?.themes?.dark || 'github-dark') as BundledShikiTheme\n\n processor.use(rehypeExpressiveCode, {\n themes: [darkTheme, lightTheme],\n useDarkModeMediaQuery: true,\n styleOverrides: {\n uiFontFamily: 'var(--ps-font-sans, var(--font-family, system-ui, sans-serif))',\n codeFontFamily: 'var(--ps-font-mono, var(--font-mono, ui-monospace, monospace))',\n codeFontSize: 'var(--ps-font-size-sm, 0.875rem)',\n codeLineHeight: '1.7',\n borderRadius: 'var(--ps-radius-lg, 0.5rem)',\n borderColor: 'var(--ps-color-border-subtle, var(--color-border-subtle, #e5e7eb))',\n },\n } satisfies RehypeExpressiveCodeOptions)\n\n processor\n .use(rehypeSlug)\n .use(rehypeAutolinkHeadings, { behavior: 'wrap' })\n // External links: add target=\"_blank\" rel=\"noopener noreferrer\" to absolute URLs\n .use(rehypeExternalLinks, {\n target: '_blank',\n rel: ['noopener', 'noreferrer'],\n })\n // Accessible emojis: wrap emoji characters in <span role=\"img\" aria-label=\"...\">\n .use(rehypeAccessibleEmojis)\n\n processor.use(() => (tree: any, file: any) => {\n const headings: Heading[] = []\n extractHeadings(tree, headings)\n file.data.headings = headings\n })\n\n if (config.rehypePlugins) {\n for (const plugin of config.rehypePlugins) {\n if (Array.isArray(plugin)) processor.use(plugin[0], plugin[1])\n else processor.use(plugin)\n }\n }\n\n processor.use(rehypeStringify, { allowDangerousHtml: true })\n return processor\n}\n\nconst processorCache = new WeakMap<MarkdownConfig, ReturnType<typeof createProcessor>>()\n\nexport async function processMarkdown(\n raw: string,\n config?: MarkdownConfig,\n preExtracted?: { content: string; frontmatter: Record<string, unknown> },\n): Promise<MarkdownResult> {\n let frontmatter: Record<string, unknown>\n let content: string\n if (preExtracted) {\n frontmatter = preExtracted.frontmatter\n content = preExtracted.content\n } else {\n const parsed = matter(raw, { engines: { yaml: parseYaml } })\n frontmatter = parsed.data\n content = parsed.content\n }\n const resolvedConfig = config && Object.keys(config).length > 0 ? config : DEFAULT_MARKDOWN_CONFIG\n // Freeze to prevent mutation — the processor is cached by object reference.\n if (Object.isFrozen(resolvedConfig) === false) Object.freeze(resolvedConfig)\n let processor = processorCache.get(resolvedConfig)\n if (!processor) {\n processor = createProcessor(resolvedConfig)\n processorCache.set(resolvedConfig, processor)\n }\n try {\n const result = await processor.process(content)\n const headings = Array.isArray(result.data.headings) ? (result.data.headings as Heading[]) : []\n return { html: String(result), headings, frontmatter }\n } catch (err) {\n throw new Error(\n `Markdown processing failed: ${err instanceof Error ? err.message : String(err)}`,\n { cause: err },\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA+BA,MAAM,0BAA0C,EAAE;;AAGlD,MAAM,uBAA+C;CACnD,KAAK;CACL,SAAS;CACT,UAAU;CACV,YAAY;CACZ,QAAQ;CACR,OAAO;CACP,KAAK;CACL,KAAK;CACN;AAED,SAAS,eAAe,MAAmB;AACzC,KAAI,KAAK,SAAS,OAAQ,QAAO,KAAK,SAAS;AAC/C,KAAI,KAAK,SAAU,QAAO,KAAK,SAAS,IAAI,eAAe,CAAC,KAAK,GAAG;AACpE,QAAO;;AAGT,SAAS,gBAAgB,MAAW,UAA2B;AAC7D,KAAI,KAAK,SAAS,aAAa,WAAW,KAAK,KAAK,QAAQ,CAC1D,UAAS,KAAK;EACZ,OAAO,SAAS,KAAK,QAAQ,GAAG;EAChC,MAAM,eAAe,KAAK;EAC1B,MAAM,KAAK,YAAY,MAAM;EAC9B,CAAC;AAEJ,KAAI,KAAK,SACP,MAAK,MAAM,SAAS,KAAK,SACvB,iBAAgB,OAAO,SAAS;;AAKtC,SAAS,gBAAgB,QAAwB;CAC/C,MAAM,YAAY,SAAS,CACxB,IAAI,YAAY,CAChB,IAAI,UAAU,CACd,IAAI,WAAW,CACf,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAEhC,IAAI,mBAAmB,CAEvB,IAAI,kBAAkB;AAEzB,KAAI,OAAO,cACT,MAAK,MAAM,UAAU,OAAO,cAC1B,KAAI,MAAM,QAAQ,OAAO,CAAE,WAAU,IAAI,OAAO,IAAI,OAAO,GAAG;KACzD,WAAU,IAAI,OAAO;CAM9B,MAAM,YAAY;EAAE,GAAG;EAAsB,GAAG,OAAO,OAAO;EAAW;AACzE,WAAU,WAAW,SAAc;EACjC,MAA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AS,OAAO,KAAK,EAAE,SAAS,EAAE,MAAMA,OAAW,EAAE,CAAC;AAC5D,gBAAc,OAAO;AACrB,YAAU,OAAO;;CAEnB,MAAM,iBAAiB,UAAU,OAAO,KAAK,OAAO,CAAC,SAAS,IAAI,SAAS;AAE3E,KAAI,OAAO,SAAS,eAAe,KAAK,MAAO,QAAO,OAAO,eAAe;CAC5E,IAAI,YAAY,eAAe,IAAI,eAAe;AAClD,KAAI,CAAC,WAAW;AACd,cAAY,gBAAgB,eAAe;AAC3C,iBAAe,IAAI,gBAAgB,UAAU;;AAE/C,KAAI;EACF,MAAM,SAAS,MAAM,UAAU,QAAQ,QAAQ;EAC/C,MAAM,WAAW,MAAM,QAAQ,OAAO,KAAK,SAAS,GAAI,OAAO,KAAK,WAAyB,EAAE;AAC/F,SAAO;GAAE,MAAM,OAAO,OAAO;GAAE;GAAU;GAAa;UAC/C,KAAK;AACZ,QAAM,IAAI,MACR,+BAA+B,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,IAC/E,EAAE,OAAO,KAAK,CACf"}
|
|
1
|
+
{"version":3,"file":"markdown-BmDJgYeB.mjs","names":["parseYaml"],"sources":["../src/markdown/pipeline.ts"],"sourcesContent":["import matter from 'gray-matter'\nimport { parse as parseYaml } from 'yaml'\nimport { rehypeAccessibleEmojis } from 'rehype-accessible-emojis'\nimport rehypeAutolinkHeadings from 'rehype-autolink-headings'\nimport rehypeExpressiveCode, {\n type BundledShikiTheme,\n type RehypeExpressiveCodeOptions,\n} from 'rehype-expressive-code'\nimport rehypeExternalLinks from 'rehype-external-links'\nimport rehypeMathjax from 'rehype-mathjax/svg'\nimport rehypeSlug from 'rehype-slug'\nimport rehypeStringify from 'rehype-stringify'\nimport remarkFrontmatter from 'remark-frontmatter'\nimport remarkGfm from 'remark-gfm'\nimport remarkGithubAlerts from 'remark-github-alerts'\nimport remarkMath from 'remark-math'\nimport remarkParse from 'remark-parse'\nimport remarkRehype from 'remark-rehype'\nimport remarkSmartypants from 'remark-smartypants'\nimport { unified } from 'unified'\nimport type { Heading } from '../schemas/heading'\nimport type { MarkdownConfig } from '../schemas/markdown-config'\n\nexport type MarkdownResult = {\n html: string\n headings: Heading[]\n frontmatter: Record<string, unknown>\n}\n\nexport type { MarkdownConfig }\n\nconst DEFAULT_MARKDOWN_CONFIG: MarkdownConfig = {}\n\n/** Default language aliases for fenced code blocks that Shiki doesn't recognize natively. */\nconst DEFAULT_LANG_ALIASES: Record<string, string> = {\n dot: 'text',\n mermaid: 'text',\n plantuml: 'text',\n excalidraw: 'json',\n drawio: 'xml',\n proto: 'protobuf',\n ejs: 'html',\n hbs: 'handlebars',\n}\n\nfunction getTextContent(node: any): string {\n if (node.type === 'text') return node.value || ''\n if (node.children) return node.children.map(getTextContent).join('')\n return ''\n}\n\nfunction extractHeadings(tree: any, headings: Heading[]): void {\n if (tree.type === 'element' && /^h[1-6]$/.test(tree.tagName)) {\n headings.push({\n depth: parseInt(tree.tagName[1]),\n text: getTextContent(tree),\n slug: tree.properties?.id || '',\n })\n }\n if (tree.children) {\n for (const child of tree.children) {\n extractHeadings(child, headings)\n }\n }\n}\n\nfunction createProcessor(config: MarkdownConfig) {\n const processor = unified()\n .use(remarkParse)\n .use(remarkGfm)\n .use(remarkMath)\n .use(remarkFrontmatter, ['yaml'])\n // GitHub-flavored alerts: > [!NOTE], > [!TIP], > [!IMPORTANT], > [!WARNING], > [!CAUTION]\n .use(remarkGithubAlerts)\n // Smart typography: \"smart quotes\", em—dashes, el…lipses\n .use(remarkSmartypants)\n\n if (config.remarkPlugins) {\n for (const plugin of config.remarkPlugins) {\n if (Array.isArray(plugin)) processor.use(plugin[0], plugin[1])\n else processor.use(plugin)\n }\n }\n\n // Apply language aliases to fenced code blocks before Expressive Code processes them.\n // Merge defaults with user-provided aliases (user overrides take precedence).\n const langAlias = { ...DEFAULT_LANG_ALIASES, ...config.shiki?.langAlias }\n processor.use(() => (tree: any) => {\n const visit = (node: any): void => {\n if (node?.type === 'code' && typeof node.lang === 'string' && langAlias[node.lang]) {\n node.lang = langAlias[node.lang]\n }\n if (Array.isArray(node?.children)) {\n for (const child of node.children) visit(child)\n }\n }\n visit(tree)\n })\n\n processor.use(remarkRehype, { allowDangerousHtml: true })\n\n // MathJax must run before Expressive Code so that math elements (from remark-math)\n // are rendered to SVG before Expressive Code tries to highlight them as code blocks.\n processor.use(rehypeMathjax)\n\n // Expressive Code — syntax highlighting, code frames, tabs, copy button\n const lightTheme = (config.shiki?.themes?.light || 'github-light') as BundledShikiTheme\n const darkTheme = (config.shiki?.themes?.dark || 'github-dark') as BundledShikiTheme\n\n processor.use(rehypeExpressiveCode, {\n themes: [darkTheme, lightTheme],\n useDarkModeMediaQuery: true,\n styleOverrides: {\n uiFontFamily: 'var(--ps-font-sans, var(--font-family, system-ui, sans-serif))',\n codeFontFamily: 'var(--ps-font-mono, var(--font-mono, ui-monospace, monospace))',\n codeFontSize: 'var(--ps-font-size-sm, 0.875rem)',\n codeLineHeight: '1.7',\n borderRadius: 'var(--ps-radius-lg, 0.5rem)',\n borderColor: 'var(--ps-color-border-subtle, var(--color-border-subtle, #e5e7eb))',\n },\n } satisfies RehypeExpressiveCodeOptions)\n\n processor\n .use(rehypeSlug)\n .use(rehypeAutolinkHeadings, { behavior: 'wrap' })\n // External links: add target=\"_blank\" rel=\"noopener noreferrer\" to absolute URLs\n .use(rehypeExternalLinks, {\n target: '_blank',\n rel: ['noopener', 'noreferrer'],\n })\n // Accessible emojis: wrap emoji characters in <span role=\"img\" aria-label=\"...\">\n .use(rehypeAccessibleEmojis)\n\n processor.use(() => (tree: any, file: any) => {\n const headings: Heading[] = []\n extractHeadings(tree, headings)\n file.data.headings = headings\n })\n\n if (config.rehypePlugins) {\n for (const plugin of config.rehypePlugins) {\n if (Array.isArray(plugin)) processor.use(plugin[0], plugin[1])\n else processor.use(plugin)\n }\n }\n\n processor.use(rehypeStringify, { allowDangerousHtml: true })\n return processor\n}\n\n/**\n * Processor cache keyed by MarkdownConfig object reference.\n *\n * **Why a WeakMap keyed by object reference?**\n * Building a unified processor chain is expensive — it loads Shiki grammars,\n * theme JSON, and instantiates every remark/rehype plugin. Caching the\n * processor by config reference lets callers that reuse the same config object\n * (the common case) skip all of that setup on subsequent calls. The WeakMap\n * also ensures that if a config object is garbage-collected, its processor is\n * too, so long-running processes don't leak memory.\n *\n * **Why is the config frozen?**\n * The cache assumes the config does not change after the processor is built.\n * If a caller mutated a config object after the processor was created, later\n * calls would still receive the stale processor (keyed by the same reference),\n * producing silently wrong output. Freezing the config at first use turns that\n * silent bug into a loud TypeError on any attempted mutation.\n *\n * **What if a consumer needs different settings?**\n * Pass a new config object — a fresh reference gets its own cache entry.\n * For example: `processMarkdown(md, { ...existingConfig, remarkPlugins: [...] })`.\n */\nconst processorCache = new WeakMap<MarkdownConfig, ReturnType<typeof createProcessor>>()\n\nexport async function processMarkdown(\n raw: string,\n config?: MarkdownConfig,\n preExtracted?: { content: string; frontmatter: Record<string, unknown> },\n): Promise<MarkdownResult> {\n let frontmatter: Record<string, unknown>\n let content: string\n if (preExtracted) {\n frontmatter = preExtracted.frontmatter\n content = preExtracted.content\n } else {\n const parsed = matter(raw, { engines: { yaml: parseYaml } })\n frontmatter = parsed.data\n content = parsed.content\n }\n const resolvedConfig = config && Object.keys(config).length > 0 ? config : DEFAULT_MARKDOWN_CONFIG\n // Freeze to prevent mutation after caching — see processorCache JSDoc above.\n if (Object.isFrozen(resolvedConfig) === false) Object.freeze(resolvedConfig)\n let processor = processorCache.get(resolvedConfig)\n if (!processor) {\n processor = createProcessor(resolvedConfig)\n processorCache.set(resolvedConfig, processor)\n }\n try {\n const result = await processor.process(content)\n const headings = Array.isArray(result.data.headings) ? (result.data.headings as Heading[]) : []\n return { html: String(result), headings, frontmatter }\n } catch (err) {\n throw new Error(\n `Markdown processing failed: ${err instanceof Error ? err.message : String(err)}`,\n { cause: err },\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA+BA,MAAM,0BAA0C,EAAE;;AA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AO,QAAO,OAAO,eAAe;CAC5E,IAAI,YAAY,eAAe,IAAI,eAAe;AAClD,KAAI,CAAC,WAAW;AACd,cAAY,gBAAgB,eAAe;AAC3C,iBAAe,IAAI,gBAAgB,UAAU;;AAE/C,KAAI;EACF,MAAM,SAAS,MAAM,UAAU,QAAQ,QAAQ;EAC/C,MAAM,WAAW,MAAM,QAAQ,OAAO,KAAK,SAAS,GAAI,OAAO,KAAK,WAAyB,EAAE;AAC/F,SAAO;GAAE,MAAM,OAAO,OAAO;GAAE;GAAU;GAAa;UAC/C,KAAK;AACZ,QAAM,IAAI,MACR,+BAA+B,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,IAC/E,EAAE,OAAO,KAAK,CACf"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CoreMcpServerOptions, createCoreMcpServer, startCoreMcpServer } from "./server.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/mcp/shared.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Shared MCP server utilities.
|
|
6
|
+
*
|
|
7
|
+
* Common helpers used by both @pagesmith/core and @pagesmith/docs MCP servers.
|
|
8
|
+
*/
|
|
9
|
+
/** Read the package version from a package.json relative to the calling module. */
|
|
10
|
+
declare function getPackageVersion(moduleDir: string): string;
|
|
11
|
+
/** Resolve a doc file path relative to the package root. */
|
|
12
|
+
declare function resolvePackageDocPath(moduleDir: string, relativePath: string): string;
|
|
13
|
+
/** Load a file as an MCP text resource response. Throws if the file doesn't exist. */
|
|
14
|
+
declare function asTextResource(uri: string, path: string): {
|
|
15
|
+
contents: {
|
|
16
|
+
uri: string;
|
|
17
|
+
mimeType: string;
|
|
18
|
+
text: string;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { type CoreMcpServerOptions, asTextResource, createCoreMcpServer, getPackageVersion, resolvePackageDocPath, startCoreMcpServer };
|
|
23
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/mcp/shared.ts"],"mappings":";;;;;;;;;iBAUgB,iBAAA,CAAkB,SAAA;;iBAOlB,qBAAA,CAAsB,SAAA,UAAmB,YAAA;;iBAKzC,cAAA,CAAe,GAAA,UAAa,IAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { t as ContentLayer } from "../content-layer-CpHYUYNN.mjs";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
|
|
4
|
+
//#region src/mcp/server.d.ts
|
|
5
|
+
type CoreMcpServerOptions = {
|
|
6
|
+
layer: ContentLayer;
|
|
7
|
+
rootDir?: string;
|
|
8
|
+
};
|
|
9
|
+
declare function createCoreMcpServer(options: CoreMcpServerOptions): McpServer;
|
|
10
|
+
declare function startCoreMcpServer(options: CoreMcpServerOptions): Promise<void>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { CoreMcpServerOptions, createCoreMcpServer, startCoreMcpServer };
|
|
13
|
+
//# sourceMappingURL=server.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../../src/mcp/server.ts"],"mappings":";;;;KAQY,oBAAA;EACV,KAAA,EAAO,YAAA;EACP,OAAA;AAAA;AAAA,iBAkBc,mBAAA,CAAoB,OAAA,EAAS,oBAAA,GAAuB,SAAA;AAAA,iBA8S9C,kBAAA,CAAmB,OAAA,EAAS,oBAAA,GAAuB,OAAA"}
|
package/dist/runtime/index.mjs
CHANGED
package/dist/schemas/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as RawEntry, i as CollectionDef, n as ContentPlugin, t as ContentLayerConfig } from "../content-config-
|
|
2
|
-
import { i as MarkdownConfigSchema, n as HeadingSchema, r as MarkdownConfig, t as Heading } from "../heading-
|
|
3
|
-
import { a as ProjectFrontmatter, i as BlogFrontmatterSchema, n as BaseFrontmatterSchema, o as ProjectFrontmatterSchema, r as BlogFrontmatter, t as BaseFrontmatter } from "../index-
|
|
1
|
+
import { c as RawEntry, i as CollectionDef, n as ContentPlugin, t as ContentLayerConfig } from "../content-config-DJXUOcNG.mjs";
|
|
2
|
+
import { i as MarkdownConfigSchema, n as HeadingSchema, r as MarkdownConfig, t as Heading } from "../heading-Dhvzlay-.mjs";
|
|
3
|
+
import { a as ProjectFrontmatter, i as BlogFrontmatterSchema, n as BaseFrontmatterSchema, o as ProjectFrontmatterSchema, r as BlogFrontmatter, t as BaseFrontmatter } from "../index-C0QFHYwb.mjs";
|
|
4
4
|
export { BaseFrontmatter, BaseFrontmatterSchema, BlogFrontmatter, BlogFrontmatterSchema, CollectionDef, ContentLayerConfig, ContentPlugin, Heading, HeadingSchema, MarkdownConfig, MarkdownConfigSchema, ProjectFrontmatter, ProjectFrontmatterSchema, RawEntry };
|