@vercel/geistdocs 1.24.1 → 1.25.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/dist/cli/index.js +1 -1
- package/dist/internal/app-route-manifest.d.ts +19 -0
- package/dist/internal/app-route-manifest.d.ts.map +1 -0
- package/dist/internal/app-route-manifest.js +121 -0
- package/dist/internal/app-route-scanner.d.ts +9 -0
- package/dist/internal/app-route-scanner.d.ts.map +1 -0
- package/dist/internal/app-route-scanner.js +149 -0
- package/dist/internal/ui/button.d.ts +1 -1
- package/dist/next.d.ts +6 -0
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +52 -0
- package/dist/proxy.d.ts +2 -1
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +28 -5
- package/dist/routes/llms.d.ts +1 -1
- package/dist/routes/llms.d.ts.map +1 -1
- package/dist/routes/llms.js +1 -1
- package/docs/agents.md +2 -2
- package/docs/llms.txt +45 -13
- package/docs/manifest.json +2 -2
- package/docs/pages/configuration.md +8 -0
- package/docs/pages/md.md +8 -5
- package/docs/pages/migration.md +7 -5
- package/docs/pages/proxy.md +20 -1
- package/docs/sitemap.md +1 -1
- package/package.json +5 -1
- package/template/AGENTS.md +2 -0
- package/template/app/[lang]/llms.mdx/[[...slug]]/route.ts +0 -1
- package/template/content/docs/configuration.mdx +8 -0
- package/template/content/docs/md.mdx +8 -5
- package/template/content/docs/migration.mdx +7 -5
- package/template/content/docs/proxy.mdx +20 -1
- package/template/next.config.ts +3 -3
- package/template/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{program as T}from"commander";import{access as ce,copyFile as le}from"fs/promises";import{join as pe}from"path";import{cancel as de,intro as ge,isCancel as ue,log as fe,outro as me,spinner as he,text as we}from"@clack/prompts";import{spawn as te}from"child_process";import{readFileSync as se}from"fs";import{cp as ne,readFile as ae,rename as re,writeFile as ie}from"fs/promises";import{join as $}from"path";import{fileURLToPath as oe}from"url";var g="@vercel/geistdocs",m=(e,t=[],s={})=>new Promise((n,a)=>{let r=te(e,t,{stdio:"inherit",...s});r.on("error",a),r.on("close",i=>{if(i===0){n();return}a(new Error(`Command failed with exit code ${i}: ${[e,...t].join(" ")}`))})}),A=["dependencies","devDependencies","optionalDependencies","peerDependencies"],_=()=>JSON.parse(se(new URL("../../package.json",import.meta.url),"utf8")).version,P=async e=>{let t=$(e,"package.json"),s=await ae(t,"utf8");return JSON.parse(s)},x=async(e,t)=>{let s=$(e,"package.json");await ie(s,`${JSON.stringify(t,null,2)}
|
|
3
|
-
`,"utf8")},R=(e,t)=>{for(let s of A){let n=e[s];if(n&&t in n)return n[t]}},V=(e,t)=>!!R(e,t),b=(e,t,s)=>{let n=!1;for(let a of A){let r=e[a];r&&t in r&&(r[t]=s,n=!0)}return n},j=()=>oe(new URL("../../template",import.meta.url)),F=async e=>{await ne(j(),e,{recursive:!0});let t=$(e,".gitignore"),s=$(e,"_gitignore");try{await re(s,t)}catch{}};var ye=async e=>{await F(e)},Pe=async e=>{try{return await ce(e),!0}catch{return!1}},ve=async()=>{await Pe(".env.example")&&await le(".env.example",".env.local")},Te=async e=>{let t=await P(e),s=_();return b(t,g,s)?(await x(e,t),!0):!1},ke=async e=>{await m("pnpm",["install"],{cwd:e,env:process.env,stdio:"inherit"})},$e=async e=>{await m("git",["init"],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["add","."],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["commit","-m","\u2728 Initial commit"],{cwd:e,env:process.env,stdio:"inherit"})},xe=async()=>{let e=await we({message:"What is your project named?",placeholder:"my-app",validate(t){if(t.length===0)return"Please enter a project name."}});return ue(e)&&(de("Operation cancelled."),process.exit(0)),e.toString()},G=async e=>{try{ge("Let's start a Geistdocs project!");let t=process.cwd(),s=e.name||await xe(),n=he(),a=pe(t,s);n.start("Copying bundled template..."),await ye(s),n.message("Setting up environment variables..."),process.chdir(a),await ve(),n.message("Rewriting package dependency versions..."),await Te(a),n.message("Installing dependencies..."),await ke(a),e.disableGit||(n.message("Initializing Git repository..."),await $e(a)),n.stop("Project initialized successfully!"),me("Run `pnpm dev` to start the development server.")}catch(t){let s=t instanceof Error?t.message:`Failed to initialize project: ${t}`;fe.error(s),process.exit(1)}};import{readFileSync as be,writeFileSync as Fe}from"fs";import{mkdir as De,readFile as N,writeFile as Se}from"fs/promises";import{dirname as Ce,extname as Re,relative as M,resolve as S}from"path";import{intro as je,isCancel as Ee,log as h,multiselect as Ne,outro as D,spinner as Ue}from"@clack/prompts";import{glob as Oe}from"glob";import{Node as v,Project as Ie,SyntaxKind as Je}from"ts-morph";var Le="geistdocs.tsx",Ae="content/docs/**/*.mdx",U=".translation-cache.json",E=8,B=()=>({version:1,entries:{}}),_e=async e=>{let t=await N(e),{createHash:s}=await import("crypto");return s("sha256").update(t).digest("hex")},Ve=e=>{let t=S(process.cwd(),e);return be(t,"utf8")},z=e=>v.isObjectLiteralExpression(e)?e.getProperties().flatMap(t=>{if(v.isPropertyAssignment(t)){let s=t.getNameNode();if(v.isIdentifier(s)||v.isStringLiteral(s))return[s.getText().replaceAll(/['"]/g,"")]}return[]}).filter(Boolean):[],Ge=e=>{try{let t=new Ie({compilerOptions:{allowJs:!0,jsx:4,module:99,target:10},skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!0}),s=Ve(e),r=t.createSourceFile(e,s,{overwrite:!0}).getVariableDeclarations().find(l=>l.getName()==="translations")?.getInitializer();if(!r)return[];if(v.isObjectLiteralExpression(r))return z(r);let i=r.getFirstDescendantByKind(Je.ObjectLiteralExpression);return i?z(i):[]}catch(t){let s=t instanceof Error?t.message:`${t}`;return h.warn(`Failed to read locales from ${e}: ${s}`),[]}},Be=async()=>{let e=await Ne({message:"Which locales should be translated?",options:[{value:"cn",label:"Chinese (cn)"},{value:"jp",label:"Japanese (jp)"},{value:"es",label:"Spanish (es)"},{value:"fr",label:"French (fr)"},{value:"de",label:"German (de)"}],required:!0});return Ee(e)&&(D("Translation cancelled"),process.exit(0)),e},ze=async e=>(await Oe(e,{cwd:process.cwd(),absolute:!0,nodir:!0})).sort(),He=async()=>{let e=S(process.cwd(),U);try{let t=await N(e,"utf8"),s=JSON.parse(t);return s.version!==1||!s.entries?B():{version:1,entries:s.entries}}catch{return B()}},H=e=>{let t=S(process.cwd(),U),s=JSON.stringify(e,null,2);Fe(t,s,"utf8")},Me=async e=>{let t=await Promise.all(e.map(async s=>[s,await _e(s)]));return Object.fromEntries(t)},Ke=(e,t)=>{let s=Re(e);return`${e.slice(0,-s.length)}.${t}${s}`},K=(e,t)=>`${M(process.cwd(),e)}::${t}`,qe=(e,t,s,n,a=!1)=>{let r=[],i=0;for(let l of t){let c=s[l];for(let o of e){let d=Ke(l,o),u=K(l,o),f=n.entries[u];if(!a&&f?.hash===c){i+=1;continue}r.push({locale:o,sourceFile:l,sourceHash:c,targetFile:d})}}return{tasks:r,skippedCount:i}},Xe=async e=>{await De(Ce(e),{recursive:!0})},We=async(e,t,s)=>{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,locale:s})});if(!n.ok){let r=await n.text();throw new Error(`API request failed (${n.status}): ${r}`)}let a=await n.json();if(!a.translation)throw new Error("API response did not include a translation");return a.translation},Ye=async(e,t,s)=>{let n=await N(e.sourceFile,"utf8"),a=await We(t,n,e.locale);await Xe(e.targetFile),await Se(e.targetFile,a,"utf8"),s.entries[K(e.sourceFile,e.locale)]={hash:e.sourceHash,updatedAt:new Date().toISOString()}},q=async(e,t)=>{je("Translate MDX content");let s=e??Ae,n=t.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",a=Ge(t.config??Le),r=await ze(s);r.length===0&&(h.error(`No MDX files found matching pattern: ${s}`),D("Translation cancelled"),process.exit(1)),h.info(`Found ${r.length} MDX file(s) matching pattern`),a.length===0&&(a=await Be());let i=S(process.cwd(),U),l=await He();await H(l),h.info(`Using cache: ${i}`);let c=await Me(r),{tasks:o,skippedCount:d}=qe(a,r,c,l,t.force);if(o.length===0){h.success("All translations are up to date!"),D(`Skipped ${d} file(s) (unchanged)`);return}let u=[];for(let y=0;y<o.length;y+=E)u.push(o.slice(y,y+E));h.info(`Processing ${o.length} translation(s) in ${u.length} batch(es) of up to ${E}`),d>0&&h.info(`Skipped ${d} translation(s) (unchanged)`);let f=Ue();f.start("Translating content...");let k=0;for(let y of u)await Promise.all(y.map(async L=>{await Ye(L,n,l),k+=1,f.message(`Translated ${k}/${o.length}: ${M(process.cwd(),L.targetFile)}`)})),await H(l);f.stop("Translation complete!"),D(`Created/updated ${o.length} file(s)`)};import{access as Ze,copyFile as Qe,mkdir as Z,rm as J}from"fs/promises";import{dirname as et,join as w}from"path";import{intro as tt,log as p,outro as C,spinner as Q}from"@clack/prompts";import{glob as st}from"glob";var nt=["**/*"],at=["content/docs/**"],O=".geistdocs-tmp",rt=async(e,t)=>{let s=w(e,t);await J(s,{recursive:!0,force:!0}),await Z(s,{recursive:!0})},I=async e=>await J(e,{recursive:!0,force:!0}),X=async(e,t,s)=>(await st(e,{cwd:s,nodir:!0,dot:!0,ignore:[".git/**",...t]})).sort(),it=async e=>{try{return await Ze(e),!0}catch{return!1}},ot=async(e,t,s)=>{let n=w(t,e),a=w(s,e);return await it(n)?(await Qe(n,a),{success:!0}):{success:!1,error:`Source file not found: ${n}`}},ct=async(e,t)=>{let s=w(t,e);return await J(s,{force:!0}),{success:!0}},W=20,Y=async(e,t,s)=>{let n=[];for(let a=0;a<e.length;a+=s){let r=e.slice(a,a+s),i=await Promise.all(r.map(t));n.push(...i)}return n},lt=async(e,t,s,n,a)=>{let r={success:[],deleted:[],failed:[]},i=[...new Set(e.map(c=>et(w(n,c))))];a.message(`Creating ${i.length} directories...`),await Promise.all(i.map(c=>Z(c,{recursive:!0}))),a.message(`Updating ${e.length} files...`);let l=await Y(e,async c=>{let o=await ot(c,s,n);return{file:c,...o}},W);for(let{file:c,success:o,error:d}of l)o?r.success.push(c):r.failed.push({file:c,error:d??"Unknown error"});if(t.length>0){a.message(`Deleting ${t.length} files...`);let c=await Y(t,async o=>{try{return await ct(o,n),{file:o,success:!0}}catch(d){let u=d instanceof Error?d.message:`${d}`;return{file:o,success:!1,error:u}}},W);for(let o of c)o.success?r.deleted.push(o.file):r.failed.push({file:o.file,error:o.error})}return r},pt=e=>{if(e.success.length>0){p.success(`Successfully updated ${e.success.length} files:`);for(let t of e.success)p.info(` \u2713 ${t}`)}if(e.deleted.length>0){p.success(`Deleted ${e.deleted.length} files:`);for(let t of e.deleted)p.info(` \u{1F5D1} ${t}`)}if(e.failed.length>0){p.warn(`Failed to update ${e.failed.length} files:`);for(let{file:t,error:s}of e.failed)p.error(` \u2717 ${t}: ${s}`)}},dt=e=>e.includes("canary")?"canary":"latest",gt=async e=>{let t=await fetch(`https://registry.npmjs.org/${encodeURIComponent(g)}`);if(!t.ok)throw new Error(`Failed to resolve ${g}@${e}`);let n=(await t.json())["dist-tags"]?.[e];if(!n)throw new Error(`Could not find dist-tag ${e} for ${g}`);return n},ut=async e=>{let t=await P(e),s=R(t,g);if(!s)return{currentVersion:s,nextVersion:void 0,updated:!1};let n=dt(s),a=await gt(n);return s===a?{currentVersion:s,nextVersion:a,updateTag:n,updated:!1}:(b(t,g,a),await x(e,t),{currentVersion:s,nextVersion:a,updateTag:n,updated:!0})},ft=async(e,t,s)=>{let n=await P(e);if(!V(n,g))return!1;t&&t.length>0&&p.warn("Ignoring file patterns for a package-based site. This update will bump the package version instead."),s?.sync&&p.warn("Ignoring --sync for a package-based site. Runtime updates now come from the package version.");let{currentVersion:a,nextVersion:r,updateTag:i,updated:l}=await ut(e);if(!l)return p.success(a?`@vercel/geistdocs is already at ${r} (${i}).`:"No package version update was needed."),C("Package-based site is already up to date."),!0;p.info(`Bumping ${g} from ${a} to ${r} (${i})`);let c=Q();return c.start("Installing updated package version..."),await m("pnpm",["install"],{cwd:e}),c.stop("Package update complete!"),C("Please review and test the upgraded package version."),!0},mt=async(e,t,s,n,a)=>{let r=w(e,O),i=Q(),l=a?.sync?r:t;i.start("Preparing template snapshot..."),a?.sync&&(await rt(e,O),await F(r)),i.message("Scanning for files...");let c=await X(s,n,l),o=[];if(a?.sync){i.message("Comparing with local files...");let u=await X(s,n,e),f=new Set(c);o=u.filter(k=>!f.has(k))}if(i.stop(`Found ${c.length} files to update`),c.length===0&&o.length===0){p.warn("No files matched the patterns. Nothing to update."),a?.sync&&await I(r),C("Update cancelled.");return}p.info(`Patterns: ${s.length}`),p.info(`Files to update: ${c.length}`),a?.sync&&p.info(`Files to delete: ${o.length}`),i.start("Updating files...");let d=await lt(c,o,l,e,i);a?.sync&&(i.message("Cleaning up..."),await I(r)),i.stop("Update complete!"),pt(d),C("Please review and test the changes carefully.")},ee=async(e,t)=>{let s=process.cwd(),n=j(),a=e&&e.length>0?e:nt,r=e&&e.length>0?[]:at;try{if(tt("Let's update your Geistdocs project!"),await ft(s,e,t))return;p.info("Template source: bundled package snapshot"),e&&e.length>0&&p.info(`Updating specific files: ${e.join(", ")}`),t?.sync&&p.info("Sync mode enabled: will delete files removed from template"),await mt(s,n,a,r,t)}catch(i){let l=i instanceof Error?i.message:`${i}`;try{await I(w(s,O))}catch{}p.error(`Failed to update project: ${l}`),process.exit(1)}};T.name("geistdocs").description("CLI for Geistdocs projects").version("1.24.1","-v, --version","Output the current version");T.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").option("--disable-git","Disable git initialization").action(G);T.command("update [files...]").description("Update a Geistdocs project (optionally specify files/patterns to update)").option("--sync","Delete local files that no longer exist in the template").action(ee);T.command("translate [pattern]").description("Translate MDX file(s) to one or more locales (default: content/docs/**/*.mdx)").option("--config <path>","Path to config file to load locales from (defaults to geistdocs.tsx)").option("--url <url>","Custom translation API URL (defaults to GEISTDOCS_TRANSLATE_URL or https://geistdocs.com/translate)").option("--force","Force re-translation of all files, ignoring cache").action(q);T.parse(process.argv);
|
|
3
|
+
`,"utf8")},R=(e,t)=>{for(let s of A){let n=e[s];if(n&&t in n)return n[t]}},V=(e,t)=>!!R(e,t),b=(e,t,s)=>{let n=!1;for(let a of A){let r=e[a];r&&t in r&&(r[t]=s,n=!0)}return n},j=()=>oe(new URL("../../template",import.meta.url)),F=async e=>{await ne(j(),e,{recursive:!0});let t=$(e,".gitignore"),s=$(e,"_gitignore");try{await re(s,t)}catch{}};var ye=async e=>{await F(e)},Pe=async e=>{try{return await ce(e),!0}catch{return!1}},ve=async()=>{await Pe(".env.example")&&await le(".env.example",".env.local")},Te=async e=>{let t=await P(e),s=_();return b(t,g,s)?(await x(e,t),!0):!1},ke=async e=>{await m("pnpm",["install"],{cwd:e,env:process.env,stdio:"inherit"})},$e=async e=>{await m("git",["init"],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["add","."],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["commit","-m","\u2728 Initial commit"],{cwd:e,env:process.env,stdio:"inherit"})},xe=async()=>{let e=await we({message:"What is your project named?",placeholder:"my-app",validate(t){if(t.length===0)return"Please enter a project name."}});return ue(e)&&(de("Operation cancelled."),process.exit(0)),e.toString()},G=async e=>{try{ge("Let's start a Geistdocs project!");let t=process.cwd(),s=e.name||await xe(),n=he(),a=pe(t,s);n.start("Copying bundled template..."),await ye(s),n.message("Setting up environment variables..."),process.chdir(a),await ve(),n.message("Rewriting package dependency versions..."),await Te(a),n.message("Installing dependencies..."),await ke(a),e.disableGit||(n.message("Initializing Git repository..."),await $e(a)),n.stop("Project initialized successfully!"),me("Run `pnpm dev` to start the development server.")}catch(t){let s=t instanceof Error?t.message:`Failed to initialize project: ${t}`;fe.error(s),process.exit(1)}};import{readFileSync as be,writeFileSync as Fe}from"fs";import{mkdir as De,readFile as N,writeFile as Se}from"fs/promises";import{dirname as Ce,extname as Re,relative as M,resolve as S}from"path";import{intro as je,isCancel as Ee,log as h,multiselect as Ne,outro as D,spinner as Ue}from"@clack/prompts";import{glob as Oe}from"glob";import{Node as v,Project as Ie,SyntaxKind as Je}from"ts-morph";var Le="geistdocs.tsx",Ae="content/docs/**/*.mdx",U=".translation-cache.json",E=8,B=()=>({version:1,entries:{}}),_e=async e=>{let t=await N(e),{createHash:s}=await import("crypto");return s("sha256").update(t).digest("hex")},Ve=e=>{let t=S(process.cwd(),e);return be(t,"utf8")},z=e=>v.isObjectLiteralExpression(e)?e.getProperties().flatMap(t=>{if(v.isPropertyAssignment(t)){let s=t.getNameNode();if(v.isIdentifier(s)||v.isStringLiteral(s))return[s.getText().replaceAll(/['"]/g,"")]}return[]}).filter(Boolean):[],Ge=e=>{try{let t=new Ie({compilerOptions:{allowJs:!0,jsx:4,module:99,target:10},skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!0}),s=Ve(e),r=t.createSourceFile(e,s,{overwrite:!0}).getVariableDeclarations().find(l=>l.getName()==="translations")?.getInitializer();if(!r)return[];if(v.isObjectLiteralExpression(r))return z(r);let i=r.getFirstDescendantByKind(Je.ObjectLiteralExpression);return i?z(i):[]}catch(t){let s=t instanceof Error?t.message:`${t}`;return h.warn(`Failed to read locales from ${e}: ${s}`),[]}},Be=async()=>{let e=await Ne({message:"Which locales should be translated?",options:[{value:"cn",label:"Chinese (cn)"},{value:"jp",label:"Japanese (jp)"},{value:"es",label:"Spanish (es)"},{value:"fr",label:"French (fr)"},{value:"de",label:"German (de)"}],required:!0});return Ee(e)&&(D("Translation cancelled"),process.exit(0)),e},ze=async e=>(await Oe(e,{cwd:process.cwd(),absolute:!0,nodir:!0})).sort(),He=async()=>{let e=S(process.cwd(),U);try{let t=await N(e,"utf8"),s=JSON.parse(t);return s.version!==1||!s.entries?B():{version:1,entries:s.entries}}catch{return B()}},H=e=>{let t=S(process.cwd(),U),s=JSON.stringify(e,null,2);Fe(t,s,"utf8")},Me=async e=>{let t=await Promise.all(e.map(async s=>[s,await _e(s)]));return Object.fromEntries(t)},Ke=(e,t)=>{let s=Re(e);return`${e.slice(0,-s.length)}.${t}${s}`},K=(e,t)=>`${M(process.cwd(),e)}::${t}`,qe=(e,t,s,n,a=!1)=>{let r=[],i=0;for(let l of t){let c=s[l];for(let o of e){let d=Ke(l,o),u=K(l,o),f=n.entries[u];if(!a&&f?.hash===c){i+=1;continue}r.push({locale:o,sourceFile:l,sourceHash:c,targetFile:d})}}return{tasks:r,skippedCount:i}},Xe=async e=>{await De(Ce(e),{recursive:!0})},We=async(e,t,s)=>{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,locale:s})});if(!n.ok){let r=await n.text();throw new Error(`API request failed (${n.status}): ${r}`)}let a=await n.json();if(!a.translation)throw new Error("API response did not include a translation");return a.translation},Ye=async(e,t,s)=>{let n=await N(e.sourceFile,"utf8"),a=await We(t,n,e.locale);await Xe(e.targetFile),await Se(e.targetFile,a,"utf8"),s.entries[K(e.sourceFile,e.locale)]={hash:e.sourceHash,updatedAt:new Date().toISOString()}},q=async(e,t)=>{je("Translate MDX content");let s=e??Ae,n=t.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",a=Ge(t.config??Le),r=await ze(s);r.length===0&&(h.error(`No MDX files found matching pattern: ${s}`),D("Translation cancelled"),process.exit(1)),h.info(`Found ${r.length} MDX file(s) matching pattern`),a.length===0&&(a=await Be());let i=S(process.cwd(),U),l=await He();await H(l),h.info(`Using cache: ${i}`);let c=await Me(r),{tasks:o,skippedCount:d}=qe(a,r,c,l,t.force);if(o.length===0){h.success("All translations are up to date!"),D(`Skipped ${d} file(s) (unchanged)`);return}let u=[];for(let y=0;y<o.length;y+=E)u.push(o.slice(y,y+E));h.info(`Processing ${o.length} translation(s) in ${u.length} batch(es) of up to ${E}`),d>0&&h.info(`Skipped ${d} translation(s) (unchanged)`);let f=Ue();f.start("Translating content...");let k=0;for(let y of u)await Promise.all(y.map(async L=>{await Ye(L,n,l),k+=1,f.message(`Translated ${k}/${o.length}: ${M(process.cwd(),L.targetFile)}`)})),await H(l);f.stop("Translation complete!"),D(`Created/updated ${o.length} file(s)`)};import{access as Ze,copyFile as Qe,mkdir as Z,rm as J}from"fs/promises";import{dirname as et,join as w}from"path";import{intro as tt,log as p,outro as C,spinner as Q}from"@clack/prompts";import{glob as st}from"glob";var nt=["**/*"],at=["content/docs/**"],O=".geistdocs-tmp",rt=async(e,t)=>{let s=w(e,t);await J(s,{recursive:!0,force:!0}),await Z(s,{recursive:!0})},I=async e=>await J(e,{recursive:!0,force:!0}),X=async(e,t,s)=>(await st(e,{cwd:s,nodir:!0,dot:!0,ignore:[".git/**",...t]})).sort(),it=async e=>{try{return await Ze(e),!0}catch{return!1}},ot=async(e,t,s)=>{let n=w(t,e),a=w(s,e);return await it(n)?(await Qe(n,a),{success:!0}):{success:!1,error:`Source file not found: ${n}`}},ct=async(e,t)=>{let s=w(t,e);return await J(s,{force:!0}),{success:!0}},W=20,Y=async(e,t,s)=>{let n=[];for(let a=0;a<e.length;a+=s){let r=e.slice(a,a+s),i=await Promise.all(r.map(t));n.push(...i)}return n},lt=async(e,t,s,n,a)=>{let r={success:[],deleted:[],failed:[]},i=[...new Set(e.map(c=>et(w(n,c))))];a.message(`Creating ${i.length} directories...`),await Promise.all(i.map(c=>Z(c,{recursive:!0}))),a.message(`Updating ${e.length} files...`);let l=await Y(e,async c=>{let o=await ot(c,s,n);return{file:c,...o}},W);for(let{file:c,success:o,error:d}of l)o?r.success.push(c):r.failed.push({file:c,error:d??"Unknown error"});if(t.length>0){a.message(`Deleting ${t.length} files...`);let c=await Y(t,async o=>{try{return await ct(o,n),{file:o,success:!0}}catch(d){let u=d instanceof Error?d.message:`${d}`;return{file:o,success:!1,error:u}}},W);for(let o of c)o.success?r.deleted.push(o.file):r.failed.push({file:o.file,error:o.error})}return r},pt=e=>{if(e.success.length>0){p.success(`Successfully updated ${e.success.length} files:`);for(let t of e.success)p.info(` \u2713 ${t}`)}if(e.deleted.length>0){p.success(`Deleted ${e.deleted.length} files:`);for(let t of e.deleted)p.info(` \u{1F5D1} ${t}`)}if(e.failed.length>0){p.warn(`Failed to update ${e.failed.length} files:`);for(let{file:t,error:s}of e.failed)p.error(` \u2717 ${t}: ${s}`)}},dt=e=>e.includes("canary")?"canary":"latest",gt=async e=>{let t=await fetch(`https://registry.npmjs.org/${encodeURIComponent(g)}`);if(!t.ok)throw new Error(`Failed to resolve ${g}@${e}`);let n=(await t.json())["dist-tags"]?.[e];if(!n)throw new Error(`Could not find dist-tag ${e} for ${g}`);return n},ut=async e=>{let t=await P(e),s=R(t,g);if(!s)return{currentVersion:s,nextVersion:void 0,updated:!1};let n=dt(s),a=await gt(n);return s===a?{currentVersion:s,nextVersion:a,updateTag:n,updated:!1}:(b(t,g,a),await x(e,t),{currentVersion:s,nextVersion:a,updateTag:n,updated:!0})},ft=async(e,t,s)=>{let n=await P(e);if(!V(n,g))return!1;t&&t.length>0&&p.warn("Ignoring file patterns for a package-based site. This update will bump the package version instead."),s?.sync&&p.warn("Ignoring --sync for a package-based site. Runtime updates now come from the package version.");let{currentVersion:a,nextVersion:r,updateTag:i,updated:l}=await ut(e);if(!l)return p.success(a?`@vercel/geistdocs is already at ${r} (${i}).`:"No package version update was needed."),C("Package-based site is already up to date."),!0;p.info(`Bumping ${g} from ${a} to ${r} (${i})`);let c=Q();return c.start("Installing updated package version..."),await m("pnpm",["install"],{cwd:e}),c.stop("Package update complete!"),C("Please review and test the upgraded package version."),!0},mt=async(e,t,s,n,a)=>{let r=w(e,O),i=Q(),l=a?.sync?r:t;i.start("Preparing template snapshot..."),a?.sync&&(await rt(e,O),await F(r)),i.message("Scanning for files...");let c=await X(s,n,l),o=[];if(a?.sync){i.message("Comparing with local files...");let u=await X(s,n,e),f=new Set(c);o=u.filter(k=>!f.has(k))}if(i.stop(`Found ${c.length} files to update`),c.length===0&&o.length===0){p.warn("No files matched the patterns. Nothing to update."),a?.sync&&await I(r),C("Update cancelled.");return}p.info(`Patterns: ${s.length}`),p.info(`Files to update: ${c.length}`),a?.sync&&p.info(`Files to delete: ${o.length}`),i.start("Updating files...");let d=await lt(c,o,l,e,i);a?.sync&&(i.message("Cleaning up..."),await I(r)),i.stop("Update complete!"),pt(d),C("Please review and test the changes carefully.")},ee=async(e,t)=>{let s=process.cwd(),n=j(),a=e&&e.length>0?e:nt,r=e&&e.length>0?[]:at;try{if(tt("Let's update your Geistdocs project!"),await ft(s,e,t))return;p.info("Template source: bundled package snapshot"),e&&e.length>0&&p.info(`Updating specific files: ${e.join(", ")}`),t?.sync&&p.info("Sync mode enabled: will delete files removed from template"),await mt(s,n,a,r,t)}catch(i){let l=i instanceof Error?i.message:`${i}`;try{await I(w(s,O))}catch{}p.error(`Failed to update project: ${l}`),process.exit(1)}};T.name("geistdocs").description("CLI for Geistdocs projects").version("1.25.0","-v, --version","Output the current version");T.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").option("--disable-git","Disable git initialization").action(G);T.command("update [files...]").description("Update a Geistdocs project (optionally specify files/patterns to update)").option("--sync","Delete local files that no longer exist in the template").action(ee);T.command("translate [pattern]").description("Translate MDX file(s) to one or more locales (default: content/docs/**/*.mdx)").option("--config <path>","Path to config file to load locales from (defaults to geistdocs.tsx)").option("--url <url>","Custom translation API URL (defaults to GEISTDOCS_TRANSLATE_URL or https://geistdocs.com/translate)").option("--force","Force re-translation of all files, ignoring cache").action(q);T.parse(process.argv);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const APP_ROUTE_MANIFEST_VERSION: 1;
|
|
2
|
+
export declare const APP_ROUTE_MANIFEST_ENV = "GEISTDOCS_APP_ROUTE_MANIFEST";
|
|
3
|
+
export declare const APP_ROUTE_MANIFEST_DEFINE = "process.env.GEISTDOCS_APP_ROUTE_MANIFEST";
|
|
4
|
+
export type AppRouteSegment = ["static", string] | ["dynamic"] | ["catch-all"] | ["optional-catch-all"];
|
|
5
|
+
export interface AppRoutePattern {
|
|
6
|
+
localized: boolean;
|
|
7
|
+
segments: AppRouteSegment[];
|
|
8
|
+
}
|
|
9
|
+
export interface AppRouteManifest {
|
|
10
|
+
routes: AppRoutePattern[];
|
|
11
|
+
version: typeof APP_ROUTE_MANIFEST_VERSION;
|
|
12
|
+
}
|
|
13
|
+
export declare const createAppRoutePattern: (filesystemSegments: string[]) => AppRoutePattern | null;
|
|
14
|
+
export declare const parseAppRouteManifest: (value: string | undefined) => AppRouteManifest | null;
|
|
15
|
+
export declare const matchesAppRoute: (manifest: AppRouteManifest, context: {
|
|
16
|
+
localizedPathname: string;
|
|
17
|
+
pathname: string;
|
|
18
|
+
}) => boolean;
|
|
19
|
+
//# sourceMappingURL=app-route-manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-route-manifest.d.ts","sourceRoot":"","sources":["../../src/internal/app-route-manifest.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,0BAA0B,EAAG,CAAU,CAAC;AACrD,eAAO,MAAM,sBAAsB,iCAAiC,CAAC;AACrE,eAAO,MAAM,yBAAyB,6CACM,CAAC;AAE7C,MAAM,MAAM,eAAe,GACvB,CAAC,QAAQ,EAAE,MAAM,CAAC,GAClB,CAAC,SAAS,CAAC,GACX,CAAC,WAAW,CAAC,GACb,CAAC,oBAAoB,CAAC,CAAC;AAE3B,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,OAAO,EAAE,OAAO,0BAA0B,CAAC;CAC5C;AA0BD,eAAO,MAAM,qBAAqB,GAChC,oBAAoB,MAAM,EAAE,KAC3B,eAAe,GAAG,IAiBpB,CAAC;AAwCF,eAAO,MAAM,qBAAqB,GAChC,OAAO,MAAM,GAAG,SAAS,KACxB,gBAAgB,GAAG,IAuBrB,CAAC;AAmDF,eAAO,MAAM,eAAe,GAC1B,UAAU,gBAAgB,EAC1B,SAAS;IAAE,iBAAiB,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,YAOvD,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
const OPTIONAL_CATCH_ALL_PATTERN = /^\[\[\.\.\.[^\]]+\]\]$/;
|
|
2
|
+
const CATCH_ALL_PATTERN = /^\[\.\.\.[^\]]+\]$/;
|
|
3
|
+
const DYNAMIC_PATTERN = /^\[[^\]]+\]$/;
|
|
4
|
+
export const APP_ROUTE_MANIFEST_VERSION = 1;
|
|
5
|
+
export const APP_ROUTE_MANIFEST_ENV = "GEISTDOCS_APP_ROUTE_MANIFEST";
|
|
6
|
+
export const APP_ROUTE_MANIFEST_DEFINE = "process.env.GEISTDOCS_APP_ROUTE_MANIFEST";
|
|
7
|
+
const safeDecode = (value) => {
|
|
8
|
+
try {
|
|
9
|
+
return decodeURIComponent(value);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const parseSegment = (segment) => {
|
|
16
|
+
if (OPTIONAL_CATCH_ALL_PATTERN.test(segment)) {
|
|
17
|
+
return ["optional-catch-all"];
|
|
18
|
+
}
|
|
19
|
+
if (CATCH_ALL_PATTERN.test(segment)) {
|
|
20
|
+
return ["catch-all"];
|
|
21
|
+
}
|
|
22
|
+
if (DYNAMIC_PATTERN.test(segment)) {
|
|
23
|
+
return ["dynamic"];
|
|
24
|
+
}
|
|
25
|
+
return ["static", safeDecode(segment)];
|
|
26
|
+
};
|
|
27
|
+
export const createAppRoutePattern = (filesystemSegments) => {
|
|
28
|
+
const segments = [...filesystemSegments];
|
|
29
|
+
const localized = segments[0] === "[lang]";
|
|
30
|
+
if (localized) {
|
|
31
|
+
segments.shift();
|
|
32
|
+
}
|
|
33
|
+
const parsed = segments.map(parseSegment);
|
|
34
|
+
const catchAllIndex = parsed.findIndex(([type]) => type === "catch-all" || type === "optional-catch-all");
|
|
35
|
+
if (catchAllIndex !== -1 && catchAllIndex !== parsed.length - 1) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return { localized, segments: parsed };
|
|
39
|
+
};
|
|
40
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
41
|
+
const isAppRouteSegment = (value) => {
|
|
42
|
+
if (!Array.isArray(value)) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (value[0] === "static") {
|
|
46
|
+
return (value.length === 2 && typeof value[1] === "string" && value[1].length > 0);
|
|
47
|
+
}
|
|
48
|
+
return (value.length === 1 &&
|
|
49
|
+
(value[0] === "dynamic" ||
|
|
50
|
+
value[0] === "catch-all" ||
|
|
51
|
+
value[0] === "optional-catch-all"));
|
|
52
|
+
};
|
|
53
|
+
const isAppRoutePattern = (value) => {
|
|
54
|
+
if (!isRecord(value) ||
|
|
55
|
+
typeof value.localized !== "boolean" ||
|
|
56
|
+
!Array.isArray(value.segments) ||
|
|
57
|
+
!value.segments.every(isAppRouteSegment)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const catchAllIndex = value.segments.findIndex(([type]) => type === "catch-all" || type === "optional-catch-all");
|
|
61
|
+
return catchAllIndex === -1 || catchAllIndex === value.segments.length - 1;
|
|
62
|
+
};
|
|
63
|
+
export const parseAppRouteManifest = (value) => {
|
|
64
|
+
if (!value) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const parsed = JSON.parse(value);
|
|
69
|
+
if (!isRecord(parsed) ||
|
|
70
|
+
parsed.version !== APP_ROUTE_MANIFEST_VERSION ||
|
|
71
|
+
!Array.isArray(parsed.routes) ||
|
|
72
|
+
!parsed.routes.every(isAppRoutePattern)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
routes: parsed.routes,
|
|
77
|
+
version: APP_ROUTE_MANIFEST_VERSION,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const getPathSegments = (pathname) => {
|
|
85
|
+
if (!pathname.startsWith("/")) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const normalized = pathname.length > 1 && pathname.endsWith("/")
|
|
89
|
+
? pathname.slice(0, -1)
|
|
90
|
+
: pathname;
|
|
91
|
+
if (normalized === "/") {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
const segments = normalized.slice(1).split("/");
|
|
95
|
+
return segments.some((segment) => segment.length === 0)
|
|
96
|
+
? null
|
|
97
|
+
: segments.map(safeDecode);
|
|
98
|
+
};
|
|
99
|
+
const matchesPattern = (pattern, pathname) => {
|
|
100
|
+
const pathnameSegments = getPathSegments(pathname);
|
|
101
|
+
if (!pathnameSegments) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
let pathnameIndex = 0;
|
|
105
|
+
for (const [type, value] of pattern.segments) {
|
|
106
|
+
if (type === "catch-all") {
|
|
107
|
+
return pathnameIndex < pathnameSegments.length;
|
|
108
|
+
}
|
|
109
|
+
if (type === "optional-catch-all") {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
const pathnameSegment = pathnameSegments[pathnameIndex];
|
|
113
|
+
if (pathnameSegment === undefined ||
|
|
114
|
+
(type === "static" && pathnameSegment !== value)) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
pathnameIndex += 1;
|
|
118
|
+
}
|
|
119
|
+
return pathnameIndex === pathnameSegments.length;
|
|
120
|
+
};
|
|
121
|
+
export const matchesAppRoute = (manifest, context) => manifest.routes.some((route) => matchesPattern(route, route.localized ? context.localizedPathname : context.pathname));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type AppRouteManifest } from "./app-route-manifest.js";
|
|
2
|
+
export declare const scanAppRouteManifest: ({ pageExtensions, projectDir, }: {
|
|
3
|
+
pageExtensions?: readonly string[];
|
|
4
|
+
projectDir: string;
|
|
5
|
+
}) => AppRouteManifest | null;
|
|
6
|
+
export declare const mergeRewriteRoutes: (manifest: AppRouteManifest, rewrites: readonly {
|
|
7
|
+
source: string;
|
|
8
|
+
}[]) => AppRouteManifest | null;
|
|
9
|
+
//# sourceMappingURL=app-route-scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-route-scanner.d.ts","sourceRoot":"","sources":["../../src/internal/app-route-scanner.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,gBAAgB,EAGtB,MAAM,yBAAyB,CAAC;AA2JjC,eAAO,MAAM,oBAAoB,GAAI,iCAGlC;IACD,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;CACpB,KAAG,gBAAgB,GAAG,IAetB,CAAC;AA+BF,eAAO,MAAM,kBAAkB,GAC7B,UAAU,gBAAgB,EAC1B,UAAU,SAAS;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,KACtC,gBAAgB,GAAG,IAmBrB,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { APP_ROUTE_MANIFEST_VERSION, createAppRoutePattern, } from "./app-route-manifest.js";
|
|
4
|
+
const DEFAULT_PAGE_EXTENSIONS = ["md", "mdx", "js", "jsx", "ts", "tsx"];
|
|
5
|
+
const ROUTE_GROUP_PATTERN = /^\([^/]+\)$/;
|
|
6
|
+
const STATIC_REWRITE_SEGMENT_PATTERN = /^[\p{L}\p{N}._~%+-]+$/u;
|
|
7
|
+
const INTERCEPTION_MARKERS = ["(..)(..)", "(...)", "(..)", "(.)"];
|
|
8
|
+
const compareStrings = (left, right) => {
|
|
9
|
+
if (left < right) {
|
|
10
|
+
return -1;
|
|
11
|
+
}
|
|
12
|
+
return left > right ? 1 : 0;
|
|
13
|
+
};
|
|
14
|
+
const isDirectory = (path) => existsSync(path) && statSync(path).isDirectory();
|
|
15
|
+
const findAppDirectory = (projectDir) => {
|
|
16
|
+
const appDir = join(projectDir, "app");
|
|
17
|
+
if (isDirectory(appDir)) {
|
|
18
|
+
return appDir;
|
|
19
|
+
}
|
|
20
|
+
const sourceAppDir = join(projectDir, "src", "app");
|
|
21
|
+
return isDirectory(sourceAppDir) ? sourceAppDir : null;
|
|
22
|
+
};
|
|
23
|
+
const isRouteFile = (name, pageExtensions) => pageExtensions.some((extension) => name === `page.${extension}` || name === `route.${extension}`);
|
|
24
|
+
const isRouteHandlerFile = (name, pageExtensions) => pageExtensions.some((extension) => name === `route.${extension}`);
|
|
25
|
+
const getInterception = (segment) => {
|
|
26
|
+
const marker = INTERCEPTION_MARKERS.find((value) => segment.startsWith(value));
|
|
27
|
+
if (!marker) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const target = segment.slice(marker.length);
|
|
31
|
+
return target ? { marker, target } : null;
|
|
32
|
+
};
|
|
33
|
+
const getInterceptedParentLevels = (marker) => {
|
|
34
|
+
if (marker === "(..)(..)") {
|
|
35
|
+
return 2;
|
|
36
|
+
}
|
|
37
|
+
return marker === "(..)" ? 1 : 0;
|
|
38
|
+
};
|
|
39
|
+
const normalizeFilesystemSegments = (filesystemSegments) => {
|
|
40
|
+
const segments = filesystemSegments.filter((segment) => !(ROUTE_GROUP_PATTERN.test(segment) || segment.startsWith("@")));
|
|
41
|
+
const interceptionIndex = segments.findIndex((segment) => INTERCEPTION_MARKERS.some((marker) => segment.startsWith(marker)));
|
|
42
|
+
if (interceptionIndex === -1) {
|
|
43
|
+
return segments;
|
|
44
|
+
}
|
|
45
|
+
const interception = getInterception(segments[interceptionIndex]);
|
|
46
|
+
if (!interception) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const prefix = segments.slice(0, interceptionIndex);
|
|
50
|
+
let keptPrefix;
|
|
51
|
+
if (interception.marker === "(...)") {
|
|
52
|
+
keptPrefix = [];
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const levels = getInterceptedParentLevels(interception.marker);
|
|
56
|
+
if (levels > prefix.length) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
keptPrefix = prefix.slice(0, prefix.length - levels);
|
|
60
|
+
}
|
|
61
|
+
const remaining = segments.slice(interceptionIndex + 1);
|
|
62
|
+
if (remaining.some((segment) => INTERCEPTION_MARKERS.some((marker) => segment.startsWith(marker)))) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return [...keptPrefix, interception.target, ...remaining];
|
|
66
|
+
};
|
|
67
|
+
const isPackageNotFoundRoute = (fileName, pageExtensions, filesystemSegments) => {
|
|
68
|
+
if (!isRouteHandlerFile(fileName, pageExtensions)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
const segments = [...filesystemSegments];
|
|
72
|
+
if (segments[0] === "[lang]") {
|
|
73
|
+
segments.shift();
|
|
74
|
+
}
|
|
75
|
+
return segments.length === 1 && segments[0] === "[...not-found]";
|
|
76
|
+
};
|
|
77
|
+
const collectRoutePatterns = (directory, pageExtensions, filesystemSegments, patterns) => {
|
|
78
|
+
const entries = readdirSync(directory, { withFileTypes: true }).sort((left, right) => compareStrings(left.name, right.name));
|
|
79
|
+
for (const entry of entries) {
|
|
80
|
+
if (entry.isDirectory()) {
|
|
81
|
+
if (!entry.name.startsWith("_")) {
|
|
82
|
+
collectRoutePatterns(join(directory, entry.name), pageExtensions, [...filesystemSegments, entry.name], patterns);
|
|
83
|
+
}
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (!(entry.isFile() && isRouteFile(entry.name, pageExtensions))) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const normalized = normalizeFilesystemSegments(filesystemSegments);
|
|
90
|
+
const pattern = normalized &&
|
|
91
|
+
!isPackageNotFoundRoute(entry.name, pageExtensions, normalized)
|
|
92
|
+
? createAppRoutePattern(normalized)
|
|
93
|
+
: null;
|
|
94
|
+
if (pattern) {
|
|
95
|
+
patterns.set(JSON.stringify(pattern), pattern);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
export const scanAppRouteManifest = ({ pageExtensions = DEFAULT_PAGE_EXTENSIONS, projectDir, }) => {
|
|
100
|
+
const appDirectory = findAppDirectory(projectDir);
|
|
101
|
+
if (!appDirectory) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const patterns = new Map();
|
|
105
|
+
collectRoutePatterns(appDirectory, pageExtensions, [], patterns);
|
|
106
|
+
return {
|
|
107
|
+
routes: [...patterns.entries()]
|
|
108
|
+
.sort(([left], [right]) => compareStrings(left, right))
|
|
109
|
+
.map(([, pattern]) => pattern),
|
|
110
|
+
version: APP_ROUTE_MANIFEST_VERSION,
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
const createRewriteRoutePattern = (source) => {
|
|
114
|
+
if (!source.startsWith("/")) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
const normalized = source.length > 1 && source.endsWith("/") ? source.slice(0, -1) : source;
|
|
118
|
+
if (normalized === "/") {
|
|
119
|
+
return createAppRoutePattern([]);
|
|
120
|
+
}
|
|
121
|
+
const sourceSegments = normalized.slice(1).split("/");
|
|
122
|
+
const firstPatternIndex = sourceSegments.findIndex((segment) => !STATIC_REWRITE_SEGMENT_PATTERN.test(segment));
|
|
123
|
+
if (firstPatternIndex === -1) {
|
|
124
|
+
return createAppRoutePattern(sourceSegments);
|
|
125
|
+
}
|
|
126
|
+
if (firstPatternIndex === 0) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return createAppRoutePattern([
|
|
130
|
+
...sourceSegments.slice(0, firstPatternIndex),
|
|
131
|
+
"[[...rewrite]]",
|
|
132
|
+
]);
|
|
133
|
+
};
|
|
134
|
+
export const mergeRewriteRoutes = (manifest, rewrites) => {
|
|
135
|
+
const patterns = new Map(manifest.routes.map((pattern) => [JSON.stringify(pattern), pattern]));
|
|
136
|
+
for (const rewrite of rewrites) {
|
|
137
|
+
const pattern = createRewriteRoutePattern(rewrite.source);
|
|
138
|
+
if (!pattern) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
patterns.set(JSON.stringify(pattern), pattern);
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
routes: [...patterns.entries()]
|
|
145
|
+
.sort(([left], [right]) => compareStrings(left, right))
|
|
146
|
+
.map(([, pattern]) => pattern),
|
|
147
|
+
version: APP_ROUTE_MANIFEST_VERSION,
|
|
148
|
+
};
|
|
149
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type VariantProps } from "class-variance-authority";
|
|
2
2
|
import type { ComponentProps } from "react";
|
|
3
3
|
declare const buttonVariants: (props?: ({
|
|
4
|
-
variant?: "
|
|
4
|
+
variant?: "link" | "default" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
|
|
5
5
|
size?: "default" | "icon" | "sm" | "lg" | "icon-sm" | "icon-lg" | null | undefined;
|
|
6
6
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
7
7
|
type ButtonProps = ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
|
package/dist/next.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type CreateMDXOptions } from "fumadocs-mdx/next";
|
|
2
|
+
import type { NextConfig } from "next";
|
|
3
|
+
export type CreateGeistdocsOptions = CreateMDXOptions;
|
|
4
|
+
/** Compose Fumadocs MDX with Geistdocs App Router discovery. */
|
|
5
|
+
export declare const createGeistdocs: (options?: CreateGeistdocsOptions) => (nextConfig?: NextConfig | Promise<NextConfig>) => Promise<NextConfig>;
|
|
6
|
+
//# sourceMappingURL=next.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../src/next.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAa,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAUvC,MAAM,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AA6BtD,gEAAgE;AAChE,eAAO,MAAM,eAAe,GAAI,UAAS,sBAA2B,MAIhE,aAAY,UAAU,GAAG,OAAO,CAAC,UAAU,CAAM,KAChD,OAAO,CAAC,UAAU,CAiCtB,CAAC"}
|
package/dist/next.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createMDX } from "fumadocs-mdx/next";
|
|
2
|
+
import { APP_ROUTE_MANIFEST_DEFINE, APP_ROUTE_MANIFEST_ENV, } from "./internal/app-route-manifest.js";
|
|
3
|
+
import { mergeRewriteRoutes, scanAppRouteManifest, } from "./internal/app-route-scanner.js";
|
|
4
|
+
const hasOwn = (value, key) => value ? Object.hasOwn(value, key) : false;
|
|
5
|
+
const assertManifestKeyIsAvailable = (config) => {
|
|
6
|
+
if (hasOwn(config.env, APP_ROUTE_MANIFEST_ENV) ||
|
|
7
|
+
hasOwn(config.compiler?.define, APP_ROUTE_MANIFEST_DEFINE) ||
|
|
8
|
+
hasOwn(config.compiler?.defineServer, APP_ROUTE_MANIFEST_DEFINE)) {
|
|
9
|
+
throw new Error(`${APP_ROUTE_MANIFEST_ENV} is reserved for @vercel/geistdocs/next`);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const flattenRewrites = (rewrites) => Array.isArray(rewrites)
|
|
13
|
+
? rewrites
|
|
14
|
+
: [
|
|
15
|
+
...(rewrites.beforeFiles ?? []),
|
|
16
|
+
...(rewrites.afterFiles ?? []),
|
|
17
|
+
...(rewrites.fallback ?? []),
|
|
18
|
+
];
|
|
19
|
+
/** Compose Fumadocs MDX with Geistdocs App Router discovery. */
|
|
20
|
+
export const createGeistdocs = (options = {}) => {
|
|
21
|
+
const withMDX = createMDX(options);
|
|
22
|
+
return async (nextConfig = {}) => {
|
|
23
|
+
const config = withMDX(await nextConfig);
|
|
24
|
+
const resolvedRewrites = config.rewrites
|
|
25
|
+
? await config.rewrites()
|
|
26
|
+
: undefined;
|
|
27
|
+
const scannedManifest = scanAppRouteManifest({
|
|
28
|
+
pageExtensions: config.pageExtensions,
|
|
29
|
+
projectDir: process.cwd(),
|
|
30
|
+
});
|
|
31
|
+
const manifest = scannedManifest && resolvedRewrites
|
|
32
|
+
? mergeRewriteRoutes(scannedManifest, flattenRewrites(resolvedRewrites))
|
|
33
|
+
: scannedManifest;
|
|
34
|
+
const resolvedConfig = resolvedRewrites
|
|
35
|
+
? { ...config, rewrites: () => resolvedRewrites }
|
|
36
|
+
: config;
|
|
37
|
+
if (!manifest) {
|
|
38
|
+
return resolvedConfig;
|
|
39
|
+
}
|
|
40
|
+
assertManifestKeyIsAvailable(resolvedConfig);
|
|
41
|
+
return {
|
|
42
|
+
...resolvedConfig,
|
|
43
|
+
compiler: {
|
|
44
|
+
...resolvedConfig.compiler,
|
|
45
|
+
defineServer: {
|
|
46
|
+
...resolvedConfig.compiler?.defineServer,
|
|
47
|
+
[APP_ROUTE_MANIFEST_DEFINE]: JSON.stringify(manifest),
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
package/dist/proxy.d.ts
CHANGED
|
@@ -30,7 +30,8 @@ export interface CreateProxyOptions {
|
|
|
30
30
|
after?: GeistdocsProxyHook | GeistdocsProxyHook[];
|
|
31
31
|
before?: GeistdocsProxyHook | GeistdocsProxyHook[];
|
|
32
32
|
config: Pick<GeistdocsConfig, "agent" | "basePath" | "content" | "defaultLanguage" | "translations">;
|
|
33
|
-
|
|
33
|
+
/** Override automatic recovery for unmatched Markdown and detected-agent requests. */
|
|
34
|
+
markdownNotFound?: boolean | ((context: {
|
|
34
35
|
language: string;
|
|
35
36
|
pathname: string;
|
|
36
37
|
}) => boolean);
|
package/dist/proxy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,eAAe,EAGrB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,eAAe,EAGrB,MAAM,UAAU,CAAC;AAQlB,MAAM,MAAM,eAAe,GACvB,UAAU,GACV,iBAAiB,GACjB,WAAW,GACX,IAAI,CAAC;AAET,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,CAAC,EAAE,QAAQ,GAAG,mBAAmB,GAAG,eAAe,CAAC;IAC/D,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,cAAc,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,KAAK,eAAe,GAAG,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC;AAEnD,MAAM,MAAM,kBAAkB,GAAG,CAC/B,OAAO,EAAE,qBAAqB,KAC3B,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAAC;AAEhD,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,IAAI,MAAM,EAAE,CAAC;IACnB,EAAE,EACE,IAAI,MAAM,EAAE,GACZ,CAAC,CAAC,OAAO,EAAE;QACT,eAAe,EAAE,MAAM,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;KAClB,KAAK,IAAI,MAAM,EAAE,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,CAAC;IAClD,MAAM,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,CAAC;IACnD,MAAM,EAAE,IAAI,CACV,eAAe,EACf,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,iBAAiB,GAAG,cAAc,CACtE,CAAC;IACF,sFAAsF;IACtF,gBAAgB,CAAC,EACb,OAAO,GACP,CAAC,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,CAAC;IACnE,cAAc,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAC1C,oBAAoB,CAAC,EAAE,CACrB,KAAK,EAAE,yBAAyB,KAC7B,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC3B;AAoKD,eAAO,MAAM,WAAW,GAAI,oFAOzB,kBAAkB,MA6SL,SAAS,WAAW,EAAE,SAAS,cAAc,sBAoD5D,CAAC"}
|
package/dist/proxy.js
CHANGED
|
@@ -4,6 +4,7 @@ import { createI18nMiddleware } from "fumadocs-core/i18n/middleware";
|
|
|
4
4
|
import { isMarkdownPreferred } from "fumadocs-core/negotiation";
|
|
5
5
|
import { NextResponse, } from "next/server";
|
|
6
6
|
import { getPublicPath, normalizeBasePath, } from "./config";
|
|
7
|
+
import { matchesAppRoute, parseAppRouteManifest, } from "./internal/app-route-manifest";
|
|
7
8
|
import { renderNotFoundMarkdown } from "./internal/not-found";
|
|
8
9
|
import { localizeHref } from "./localize-href";
|
|
9
10
|
const MDX_EXTENSION_PATTERN = /\.mdx?$/;
|
|
@@ -25,6 +26,7 @@ const PACKAGE_ROUTE_PATHS = new Set([
|
|
|
25
26
|
"/rss.xml",
|
|
26
27
|
"/sitemap.md",
|
|
27
28
|
]);
|
|
29
|
+
const MARKDOWN_REQUEST_METHODS = new Set(["GET", "HEAD"]);
|
|
28
30
|
const TRAILING_SLASH_PATTERN = /\/$/;
|
|
29
31
|
const getLanguages = (config) => {
|
|
30
32
|
const defaultLanguage = config.defaultLanguage ?? "en";
|
|
@@ -120,11 +122,13 @@ const getLocalizedPathname = (pathname, languages, defaultLanguage) => {
|
|
|
120
122
|
};
|
|
121
123
|
};
|
|
122
124
|
export const createProxy = ({ after, before, config, markdownNotFound, markdownRoutes, trackMarkdownRequest, }) => {
|
|
125
|
+
const agentEnabled = config.agent !== undefined && config.agent.enabled !== false;
|
|
123
126
|
const contentRouteMappings = markdownRoutes ??
|
|
124
127
|
inferMarkdownRoutes(config) ?? [DEFAULT_MARKDOWN_ROUTE];
|
|
125
|
-
const routeMappings =
|
|
128
|
+
const routeMappings = agentEnabled
|
|
126
129
|
? [...contentRouteMappings, HOME_MARKDOWN_ROUTE]
|
|
127
130
|
: contentRouteMappings;
|
|
131
|
+
const appRouteManifest = parseAppRouteManifest(process.env.GEISTDOCS_APP_ROUTE_MANIFEST);
|
|
128
132
|
const { defaultLanguage, languages } = getLanguages(config);
|
|
129
133
|
const i18n = defineI18n({
|
|
130
134
|
defaultLanguage,
|
|
@@ -155,8 +159,23 @@ export const createProxy = ({ after, before, config, markdownNotFound, markdownR
|
|
|
155
159
|
}),
|
|
156
160
|
});
|
|
157
161
|
};
|
|
158
|
-
const shouldCreateMarkdownNotFound = (pathname, language) =>
|
|
159
|
-
markdownNotFound
|
|
162
|
+
const shouldCreateMarkdownNotFound = (pathname, language, requestPathname) => {
|
|
163
|
+
if (markdownNotFound === true) {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
if (markdownNotFound === false) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
if (typeof markdownNotFound === "function") {
|
|
170
|
+
return markdownNotFound({ language, pathname });
|
|
171
|
+
}
|
|
172
|
+
return Boolean(agentEnabled &&
|
|
173
|
+
appRouteManifest &&
|
|
174
|
+
!matchesAppRoute(appRouteManifest, {
|
|
175
|
+
localizedPathname: pathname,
|
|
176
|
+
pathname: requestPathname,
|
|
177
|
+
}));
|
|
178
|
+
};
|
|
160
179
|
const resolveMarkdownRewrite = (pathname, language) => {
|
|
161
180
|
for (const route of routeMappings) {
|
|
162
181
|
const path = getRoutePath(route, pathname);
|
|
@@ -230,6 +249,9 @@ export const createProxy = ({ after, before, config, markdownNotFound, markdownR
|
|
|
230
249
|
})
|
|
231
250
|
: null;
|
|
232
251
|
const handleMarkdownNegotiation = (request, context, pathname) => {
|
|
252
|
+
if (!MARKDOWN_REQUEST_METHODS.has(request.method)) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
233
255
|
const localized = getLocalizedPathname(pathname, languages, defaultLanguage);
|
|
234
256
|
if ((localized.hasLanguagePrefix && localized.language === defaultLanguage) ||
|
|
235
257
|
PACKAGE_ROUTE_PATHS.has(localized.pathname)) {
|
|
@@ -252,7 +274,7 @@ export const createProxy = ({ after, before, config, markdownNotFound, markdownR
|
|
|
252
274
|
}
|
|
253
275
|
return !RESOURCE_EXTENSION_PATTERN.test(localized.pathname) &&
|
|
254
276
|
(isMarkdownPreferred(request) || isAIAgent(request).detected) &&
|
|
255
|
-
shouldCreateMarkdownNotFound(localized.pathname, localized.language)
|
|
277
|
+
shouldCreateMarkdownNotFound(localized.pathname, localized.language, pathname)
|
|
256
278
|
? createMarkdownNotFound(pathname, localized.language)
|
|
257
279
|
: null;
|
|
258
280
|
};
|
|
@@ -296,7 +318,8 @@ export const createProxy = ({ after, before, config, markdownNotFound, markdownR
|
|
|
296
318
|
return afterResponse;
|
|
297
319
|
}
|
|
298
320
|
const response = await handleI18nRequest(request, context);
|
|
299
|
-
if (
|
|
321
|
+
if (MARKDOWN_REQUEST_METHODS.has(request.method) &&
|
|
322
|
+
resolveMarkdownRewrite(localized.pathname, localized.language)) {
|
|
300
323
|
applyMarkdownHeaders(response.headers);
|
|
301
324
|
}
|
|
302
325
|
return response;
|
package/dist/routes/llms.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare const createLlmsRoute: ({ filterPage, source, sources, transform,
|
|
|
32
32
|
export interface CreateDocsMarkdownRouteOptions {
|
|
33
33
|
config?: Pick<GeistdocsConfig, "basePath" | "defaultLanguage" | "translations">;
|
|
34
34
|
filterStaticParams?: (params: DocsMarkdownParams) => boolean;
|
|
35
|
-
/**
|
|
35
|
+
/** Customize the agent-readable Markdown response for missing pages, or disable it. */
|
|
36
36
|
notFound?: false | MarkdownNotFoundOptions;
|
|
37
37
|
source?: SourceBundle;
|
|
38
38
|
sources?: SourceBundle[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llms.d.ts","sourceRoot":"","sources":["../../src/routes/llms.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,cAAc,CAAC;AAStB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D,KAAK,YAAY,GAAG,qBAAqB,CAAC;AAC1C,KAAK,aAAa,GAAG,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAahF,UAAU,kBAAkB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,UAAU,wBAAwB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,YAAY,CAAC;CACtB;AAED,KAAK,iBAAiB,GAAG,CACvB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,wBAAwB,KAC9B,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AAE9B,UAAU,sBAAsB;IAC9B,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC;IACzE,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B;AAqOD,eAAO,MAAM,eAAe,GAAI,6CAK7B,sBAAsB;gBAIf,WAAW,cACL;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;;CAoCpD,CAAC;AAEF,MAAM,WAAW,8BAA8B;IAC7C,MAAM,CAAC,EAAE,IAAI,CACX,eAAe,EACf,UAAU,GAAG,iBAAiB,GAAG,cAAc,CAChD,CAAC;IACF,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC;IAC7D,
|
|
1
|
+
{"version":3,"file":"llms.d.ts","sourceRoot":"","sources":["../../src/routes/llms.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,cAAc,CAAC;AAStB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D,KAAK,YAAY,GAAG,qBAAqB,CAAC;AAC1C,KAAK,aAAa,GAAG,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAahF,UAAU,kBAAkB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,UAAU,wBAAwB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,YAAY,CAAC;CACtB;AAED,KAAK,iBAAiB,GAAG,CACvB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,wBAAwB,KAC9B,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AAE9B,UAAU,sBAAsB;IAC9B,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC;IACzE,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B;AAqOD,eAAO,MAAM,eAAe,GAAI,6CAK7B,sBAAsB;gBAIf,WAAW,cACL;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;;CAoCpD,CAAC;AAEF,MAAM,WAAW,8BAA8B;IAC7C,MAAM,CAAC,EAAE,IAAI,CACX,eAAe,EACf,UAAU,GAAG,iBAAiB,GAAG,cAAc,CAChD,CAAC;IACF,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC;IAC7D,uFAAuF;IACvF,QAAQ,CAAC,EAAE,KAAK,GAAG,uBAAuB,CAAC;IAC3C,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B;AAED,MAAM,WAAW,uBAAuB;IACtC,uDAAuD;IACvD,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE;QAC7B,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,aAAa,CAAC;QACpB,MAAM,EAAE,YAAY,CAAC;KACtB,KAAK,MAAM,CAAC;IACb;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,KAAK,MAAM,CAAC;IACzE,oDAAoD;IACpD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,MAAM,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;CAC1B;AAED,eAAO,MAAM,uBAAuB,GAAI,wFAOrC,8BAA8B;mBAkLpB,OAAO,cACJ;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAA;KAAE;yCA6CjE;QACD,MAAM,CAAC,EAAE,OAAO,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACrC;;CAgBF,CAAC"}
|
package/dist/routes/llms.js
CHANGED
|
@@ -156,7 +156,7 @@ export const createLlmsRoute = ({ filterPage, source, sources, transform, }) =>
|
|
|
156
156
|
revalidate: false,
|
|
157
157
|
};
|
|
158
158
|
};
|
|
159
|
-
export const createDocsMarkdownRoute = ({ config, filterStaticParams, notFound: notFoundOptions =
|
|
159
|
+
export const createDocsMarkdownRoute = ({ config, filterStaticParams, notFound: notFoundOptions = {}, source, sources, transform, }) => {
|
|
160
160
|
const routeSources = resolveSources(source, sources, "createDocsMarkdownRoute");
|
|
161
161
|
const routingConfig = config ?? routeSources[0].routingConfig ?? {};
|
|
162
162
|
const smartNotFoundOptions = notFoundOptions === false ? {} : notFoundOptions;
|
package/docs/agents.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Geistdocs Package Docs
|
|
2
2
|
|
|
3
|
-
These docs are bundled with `@vercel/geistdocs` 1.
|
|
3
|
+
These docs are bundled with `@vercel/geistdocs` 1.25.0 so agents can understand the installed package without web access.
|
|
4
4
|
They are generated from `apps/template/content/docs` during the package build.
|
|
5
5
|
|
|
6
6
|
## How to use these files
|
|
@@ -31,7 +31,7 @@ They are generated from `apps/template/content/docs` during the package build.
|
|
|
31
31
|
- [Syntax](pages/syntax.md): Supported MDX syntax including text formatting, code blocks, line highlighting, and Mermaid diagrams.
|
|
32
32
|
- [Geistdocs Provider](pages/provider.md): The root provider component that wraps your application to handle toast notifications, search, and analytics.
|
|
33
33
|
- [Versioned docs](pages/versioned-docs.md): Use createVersionedSources to configure stable, pre-release, or host-based documentation versions.
|
|
34
|
-
- [Proxy and markdown routes](pages/proxy.md): Configure createProxy with
|
|
34
|
+
- [Proxy and markdown routes](pages/proxy.md): Configure createProxy with generated route discovery, request hooks, markdown mappings, and a static Next.js matcher.
|
|
35
35
|
- [.md Extension](pages/md.md): Access any documentation page as raw Markdown by appending .md or .mdx to the URL for AI tool consumption.
|
|
36
36
|
- [Agent readiness](pages/agent-readiness.md): Generate /agents.md and /.well-known/mcp.json from Geistdocs config so agents can find docs, Markdown surfaces, API specs, and MCP endpoints.
|
|
37
37
|
- [Ask AI](pages/ask-ai.md): An AI-powered chat assistant with context-aware search, persistent history, and suggested prompts for your documentation.
|
package/docs/llms.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Geistdocs Package Documentation
|
|
2
2
|
|
|
3
|
-
These docs are bundled with `@vercel/geistdocs` 1.
|
|
3
|
+
These docs are bundled with `@vercel/geistdocs` 1.25.0.
|
|
4
4
|
They describe how to build package-backed Geistdocs sites and how to use the package APIs from generated project adapters.
|
|
5
5
|
|
|
6
6
|
## Documentation Index
|
|
@@ -14,7 +14,7 @@ They describe how to build package-backed Geistdocs sites and how to use the pac
|
|
|
14
14
|
- [Syntax](pages/syntax.md): Supported MDX syntax including text formatting, code blocks, line highlighting, and Mermaid diagrams.
|
|
15
15
|
- [Geistdocs Provider](pages/provider.md): The root provider component that wraps your application to handle toast notifications, search, and analytics.
|
|
16
16
|
- [Versioned docs](pages/versioned-docs.md): Use createVersionedSources to configure stable, pre-release, or host-based documentation versions.
|
|
17
|
-
- [Proxy and markdown routes](pages/proxy.md): Configure createProxy with
|
|
17
|
+
- [Proxy and markdown routes](pages/proxy.md): Configure createProxy with generated route discovery, request hooks, markdown mappings, and a static Next.js matcher.
|
|
18
18
|
- [.md Extension](pages/md.md): Access any documentation page as raw Markdown by appending .md or .mdx to the URL for AI tool consumption.
|
|
19
19
|
- [Agent readiness](pages/agent-readiness.md): Generate /agents.md and /.well-known/mcp.json from Geistdocs config so agents can find docs, Markdown surfaces, API specs, and MCP endpoints.
|
|
20
20
|
- [Ask AI](pages/ask-ai.md): An AI-powered chat assistant with context-aware search, persistent history, and suggested prompts for your documentation.
|
|
@@ -438,24 +438,26 @@ If you are starting from a generated Geistdocs project and moving content into i
|
|
|
438
438
|
pnpm dlx @vercel/geistdocs init --name my-docs
|
|
439
439
|
```
|
|
440
440
|
|
|
441
|
-
##
|
|
441
|
+
## Configure Next.js
|
|
442
442
|
|
|
443
|
-
Geistdocs
|
|
443
|
+
The Geistdocs Next.js integration composes Fumadocs MDX, enables automatic app-route discovery for agent-readable 404s, and preserves your Next.js configuration. Enable Cache Components in the same file:
|
|
444
444
|
|
|
445
445
|
```ts title="next.config.ts"
|
|
446
|
-
import {
|
|
446
|
+
import { createGeistdocs } from "@vercel/geistdocs/next";
|
|
447
447
|
import type { NextConfig } from "next";
|
|
448
448
|
|
|
449
|
-
const
|
|
449
|
+
const withGeistdocs = createGeistdocs();
|
|
450
450
|
|
|
451
451
|
const config: NextConfig = {
|
|
452
452
|
cacheComponents: true,
|
|
453
453
|
partialPrefetching: true,
|
|
454
454
|
};
|
|
455
455
|
|
|
456
|
-
export default
|
|
456
|
+
export default withGeistdocs(config);
|
|
457
457
|
```
|
|
458
458
|
|
|
459
|
+
Restart `next dev` after adding, deleting, or renaming an App Router page or route. Production builds always regenerate the route manifest.
|
|
460
|
+
|
|
459
461
|
Every root dynamic parameter needs at least one value from `generateStaticParams`. For a site with a `[lang]` root segment, return every configured language from the root layout:
|
|
460
462
|
|
|
461
463
|
```tsx title="app/[lang]/layout.tsx"
|
|
@@ -836,6 +838,7 @@ Configure Geistdocs through user-owned files in the generated project. Runtime f
|
|
|
836
838
|
| File | Purpose |
|
|
837
839
|
| --- | --- |
|
|
838
840
|
| `geistdocs.tsx` | Site-level settings, including logo, nav, GitHub repo, AI prompt, agent-readiness metadata, translations, and feature flags. |
|
|
841
|
+
| `next.config.ts` | Composes Fumadocs MDX, discovers App Router routes, and configures Next.js. |
|
|
839
842
|
| `source.config.ts` | Configures Fumadocs collections with the package-provided schema, Markdown plugins, and syntax theme. |
|
|
840
843
|
| `lib/geistdocs/config.tsx` | Converts `geistdocs.tsx` exports into the package config using `defineConfig`. |
|
|
841
844
|
| `source.config.ts` | Configures Fumadocs collections with package-safe schemas and Markdown processing. |
|
|
@@ -1025,11 +1028,18 @@ To serve docs from the site root, use `route: "/"` in `content` and `baseUrl: "/
|
|
|
1025
1028
|
When Next.js mounts the application below a path, set the same value in `next.config.ts` and Geistdocs config:
|
|
1026
1029
|
|
|
1027
1030
|
```ts title="next.config.ts"
|
|
1031
|
+
import { createGeistdocs } from "@vercel/geistdocs/next";
|
|
1032
|
+
import type { NextConfig } from "next";
|
|
1033
|
+
|
|
1034
|
+
const withGeistdocs = createGeistdocs();
|
|
1035
|
+
|
|
1028
1036
|
const config: NextConfig = {
|
|
1029
1037
|
basePath: "/docs",
|
|
1030
1038
|
cacheComponents: true,
|
|
1031
1039
|
partialPrefetching: true,
|
|
1032
1040
|
};
|
|
1041
|
+
|
|
1042
|
+
export default withGeistdocs(config);
|
|
1033
1043
|
```
|
|
1034
1044
|
|
|
1035
1045
|
```tsx title="geistdocs.tsx"
|
|
@@ -2012,7 +2022,7 @@ Each public route family needs a matching markdown route in `proxy.ts`. Read [Pr
|
|
|
2012
2022
|
title: Proxy and markdown routes
|
|
2013
2023
|
description: Add custom request logic while keeping Geistdocs markdown negotiation in the package
|
|
2014
2024
|
type: reference
|
|
2015
|
-
summary: Configure createProxy with
|
|
2025
|
+
summary: Configure createProxy with generated route discovery, request hooks, markdown mappings, and a static Next.js matcher.
|
|
2016
2026
|
url: /docs/proxy
|
|
2017
2027
|
source: apps/template/content/docs/proxy.mdx
|
|
2018
2028
|
prerequisites:
|
|
@@ -2189,6 +2199,25 @@ export const config = {
|
|
|
2189
2199
|
|
|
2190
2200
|
The package keeps `llms.txt`, `sitemap.md`, `agents.md`, MCP discovery, and RSS out of root page-Markdown negotiation. Continue to exclude site-specific application and API routes with the matcher or a `before` hook. A root Markdown page is exposed as `/index.md`, or `<basePath>/index.md` publicly.
|
|
2191
2201
|
|
|
2202
|
+
## Recover unmatched Markdown requests
|
|
2203
|
+
|
|
2204
|
+
`createGeistdocs` in `next.config.ts` generates a lightweight manifest from App Router pages and route handlers. When `agent` is enabled, `createProxy` uses this manifest to return a Markdown 404 only when a `GET` or `HEAD` request matches neither a Markdown mapping nor an application route.
|
|
2205
|
+
|
|
2206
|
+
The manifest contains route patterns, not page modules or content. Static, dynamic, catch-all, optional catch-all, grouped, and localized routes continue to Next.js. Root catch-all pages are treated as potentially valid, so the app remains responsible for their 404 behavior. The package's own `[...not-found]` route handler is excluded so it does not claim every path.
|
|
2207
|
+
|
|
2208
|
+
The integration also resolves `next.config.ts` rewrites. Static rewrite sources are matched exactly, while parameterized sources protect their safe static prefix. If a rewrite begins with a dynamic root segment, Geistdocs disables automatic recovery rather than risk returning a Markdown 404 for a real rewritten route.
|
|
2209
|
+
|
|
2210
|
+
No proxy option is required. Pass `markdownNotFound: false` only when the site needs to disable automatic recovery:
|
|
2211
|
+
|
|
2212
|
+
```ts title="proxy.ts"
|
|
2213
|
+
const proxy = createProxy({
|
|
2214
|
+
config: geistdocsConfig,
|
|
2215
|
+
markdownNotFound: false,
|
|
2216
|
+
});
|
|
2217
|
+
```
|
|
2218
|
+
|
|
2219
|
+
Existing sites that use `createMDX` directly do not receive a generated manifest and keep the previous opt-in behavior. Restart `next dev` after adding, deleting, or renaming a route; production builds always regenerate the manifest.
|
|
2220
|
+
|
|
2192
2221
|
## Hook context
|
|
2193
2222
|
|
|
2194
2223
|
Both `before` and `after` receive the same context:
|
|
@@ -2282,7 +2311,6 @@ import { geistdocsSource } from "@/lib/geistdocs/source";
|
|
|
2282
2311
|
|
|
2283
2312
|
export const { GET, generateStaticParams } =
|
|
2284
2313
|
createDocsMarkdownRoute({
|
|
2285
|
-
notFound: {},
|
|
2286
2314
|
sources: [geistdocsSource],
|
|
2287
2315
|
});
|
|
2288
2316
|
```
|
|
@@ -2306,7 +2334,7 @@ When a Markdown request does not match a page, Geistdocs returns an agent-readab
|
|
|
2306
2334
|
|
|
2307
2335
|
For example, a request for `/docs/env-vars` can suggest `/docs/environment-variables.md`. The response uses a short cache lifetime and returns a real `404` status. It also sends `X-Robots-Tag: noindex` and no canonical link because the requested page does not exist. Regular HTML requests keep the app's standard not-found behavior.
|
|
2308
2336
|
|
|
2309
|
-
|
|
2337
|
+
The suggestion response is enabled by default. Pass `notFound: { status: 410 }` for permanently removed pages, or `notFound: false` to use the standard Next.js not-found response. Legacy `status: 200` values are treated as `404` so missing pages always return a real error status.
|
|
2310
2338
|
|
|
2311
2339
|
If a custom `markdownRoutes` mapping changes the public path shape, set `notFound.getRequestedPath` to reconstruct the app-local public pathname. This also keeps page lookup and suggestions within the right source when a flattened route serves multiple sources:
|
|
2312
2340
|
|
|
@@ -2323,17 +2351,21 @@ Set `notFound.getPageMarkdownUrl` as well when suggested pages use a custom app-
|
|
|
2323
2351
|
|
|
2324
2352
|
### Unmatched application paths
|
|
2325
2353
|
|
|
2326
|
-
|
|
2354
|
+
When `agent` is enabled, `createGeistdocs` scans App Router pages and route handlers during `next dev` and `next build`. `createProxy` uses that generated manifest to distinguish valid application routes from unknown paths. Valid routes continue to the app's HTML or route-handler response. Unknown Markdown or detected-agent `GET` and `HEAD` requests receive a concise 404 with links to the docs, `sitemap.md`, and `llms.txt`.
|
|
2327
2355
|
|
|
2328
|
-
|
|
2356
|
+
Markdown mappings take precedence over generated app routes, so a route that has both HTML and Markdown continues to negotiate Markdown. Dynamic app routes are treated as potentially valid; the app remains responsible for returning its own 404 when a specific slug does not exist.
|
|
2357
|
+
|
|
2358
|
+
Pass `markdownNotFound: false` to disable automatic unmatched-path recovery:
|
|
2329
2359
|
|
|
2330
2360
|
```ts title="proxy.ts"
|
|
2331
2361
|
const proxy = createProxy({
|
|
2332
2362
|
config: geistdocsConfig,
|
|
2333
|
-
markdownNotFound:
|
|
2363
|
+
markdownNotFound: false,
|
|
2334
2364
|
});
|
|
2335
2365
|
```
|
|
2336
2366
|
|
|
2367
|
+
Sites that do not use `createGeistdocs` keep the previous opt-in behavior. Existing boolean and predicate forms remain supported for compatibility.
|
|
2368
|
+
|
|
2337
2369
|
`createNotFoundRoute` remains available for apps that prefer an explicit catch-all Route Handler with Geistdocs' minimal HTML response.
|
|
2338
2370
|
|
|
2339
2371
|
|
package/docs/manifest.json
CHANGED
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"description": "Add custom request logic while keeping Geistdocs markdown negotiation in the package",
|
|
94
94
|
"path": "pages/proxy.md",
|
|
95
95
|
"source": "apps/template/content/docs/proxy.mdx",
|
|
96
|
-
"summary": "Configure createProxy with
|
|
96
|
+
"summary": "Configure createProxy with generated route discovery, request hooks, markdown mappings, and a static Next.js matcher.",
|
|
97
97
|
"title": "Proxy and markdown routes",
|
|
98
98
|
"type": "reference",
|
|
99
99
|
"url": "/docs/proxy"
|
|
@@ -208,5 +208,5 @@
|
|
|
208
208
|
}
|
|
209
209
|
],
|
|
210
210
|
"source": "apps/template/content/docs",
|
|
211
|
-
"version": "1.
|
|
211
|
+
"version": "1.25.0"
|
|
212
212
|
}
|
|
@@ -27,6 +27,7 @@ Configure Geistdocs through user-owned files in the generated project. Runtime f
|
|
|
27
27
|
| File | Purpose |
|
|
28
28
|
| --- | --- |
|
|
29
29
|
| `geistdocs.tsx` | Site-level settings, including logo, nav, GitHub repo, AI prompt, agent-readiness metadata, translations, and feature flags. |
|
|
30
|
+
| `next.config.ts` | Composes Fumadocs MDX, discovers App Router routes, and configures Next.js. |
|
|
30
31
|
| `source.config.ts` | Configures Fumadocs collections with the package-provided schema, Markdown plugins, and syntax theme. |
|
|
31
32
|
| `lib/geistdocs/config.tsx` | Converts `geistdocs.tsx` exports into the package config using `defineConfig`. |
|
|
32
33
|
| `source.config.ts` | Configures Fumadocs collections with package-safe schemas and Markdown processing. |
|
|
@@ -216,11 +217,18 @@ To serve docs from the site root, use `route: "/"` in `content` and `baseUrl: "/
|
|
|
216
217
|
When Next.js mounts the application below a path, set the same value in `next.config.ts` and Geistdocs config:
|
|
217
218
|
|
|
218
219
|
```ts title="next.config.ts"
|
|
220
|
+
import { createGeistdocs } from "@vercel/geistdocs/next";
|
|
221
|
+
import type { NextConfig } from "next";
|
|
222
|
+
|
|
223
|
+
const withGeistdocs = createGeistdocs();
|
|
224
|
+
|
|
219
225
|
const config: NextConfig = {
|
|
220
226
|
basePath: "/docs",
|
|
221
227
|
cacheComponents: true,
|
|
222
228
|
partialPrefetching: true,
|
|
223
229
|
};
|
|
230
|
+
|
|
231
|
+
export default withGeistdocs(config);
|
|
224
232
|
```
|
|
225
233
|
|
|
226
234
|
```tsx title="geistdocs.tsx"
|
package/docs/pages/md.md
CHANGED
|
@@ -71,7 +71,6 @@ import { geistdocsSource } from "@/lib/geistdocs/source";
|
|
|
71
71
|
|
|
72
72
|
export const { GET, generateStaticParams } =
|
|
73
73
|
createDocsMarkdownRoute({
|
|
74
|
-
notFound: {},
|
|
75
74
|
sources: [geistdocsSource],
|
|
76
75
|
});
|
|
77
76
|
```
|
|
@@ -95,7 +94,7 @@ When a Markdown request does not match a page, Geistdocs returns an agent-readab
|
|
|
95
94
|
|
|
96
95
|
For example, a request for `/docs/env-vars` can suggest `/docs/environment-variables.md`. The response uses a short cache lifetime and returns a real `404` status. It also sends `X-Robots-Tag: noindex` and no canonical link because the requested page does not exist. Regular HTML requests keep the app's standard not-found behavior.
|
|
97
96
|
|
|
98
|
-
|
|
97
|
+
The suggestion response is enabled by default. Pass `notFound: { status: 410 }` for permanently removed pages, or `notFound: false` to use the standard Next.js not-found response. Legacy `status: 200` values are treated as `404` so missing pages always return a real error status.
|
|
99
98
|
|
|
100
99
|
If a custom `markdownRoutes` mapping changes the public path shape, set `notFound.getRequestedPath` to reconstruct the app-local public pathname. This also keeps page lookup and suggestions within the right source when a flattened route serves multiple sources:
|
|
101
100
|
|
|
@@ -112,15 +111,19 @@ Set `notFound.getPageMarkdownUrl` as well when suggested pages use a custom app-
|
|
|
112
111
|
|
|
113
112
|
### Unmatched application paths
|
|
114
113
|
|
|
115
|
-
|
|
114
|
+
When `agent` is enabled, `createGeistdocs` scans App Router pages and route handlers during `next dev` and `next build`. `createProxy` uses that generated manifest to distinguish valid application routes from unknown paths. Valid routes continue to the app's HTML or route-handler response. Unknown Markdown or detected-agent `GET` and `HEAD` requests receive a concise 404 with links to the docs, `sitemap.md`, and `llms.txt`.
|
|
116
115
|
|
|
117
|
-
|
|
116
|
+
Markdown mappings take precedence over generated app routes, so a route that has both HTML and Markdown continues to negotiate Markdown. Dynamic app routes are treated as potentially valid; the app remains responsible for returning its own 404 when a specific slug does not exist.
|
|
117
|
+
|
|
118
|
+
Pass `markdownNotFound: false` to disable automatic unmatched-path recovery:
|
|
118
119
|
|
|
119
120
|
```ts title="proxy.ts"
|
|
120
121
|
const proxy = createProxy({
|
|
121
122
|
config: geistdocsConfig,
|
|
122
|
-
markdownNotFound:
|
|
123
|
+
markdownNotFound: false,
|
|
123
124
|
});
|
|
124
125
|
```
|
|
125
126
|
|
|
127
|
+
Sites that do not use `createGeistdocs` keep the previous opt-in behavior. Existing boolean and predicate forms remain supported for compatibility.
|
|
128
|
+
|
|
126
129
|
`createNotFoundRoute` remains available for apps that prefer an explicit catch-all Route Handler with Geistdocs' minimal HTML response.
|
package/docs/pages/migration.md
CHANGED
|
@@ -58,24 +58,26 @@ If you are starting from a generated Geistdocs project and moving content into i
|
|
|
58
58
|
pnpm dlx @vercel/geistdocs init --name my-docs
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
##
|
|
61
|
+
## Configure Next.js
|
|
62
62
|
|
|
63
|
-
Geistdocs
|
|
63
|
+
The Geistdocs Next.js integration composes Fumadocs MDX, enables automatic app-route discovery for agent-readable 404s, and preserves your Next.js configuration. Enable Cache Components in the same file:
|
|
64
64
|
|
|
65
65
|
```ts title="next.config.ts"
|
|
66
|
-
import {
|
|
66
|
+
import { createGeistdocs } from "@vercel/geistdocs/next";
|
|
67
67
|
import type { NextConfig } from "next";
|
|
68
68
|
|
|
69
|
-
const
|
|
69
|
+
const withGeistdocs = createGeistdocs();
|
|
70
70
|
|
|
71
71
|
const config: NextConfig = {
|
|
72
72
|
cacheComponents: true,
|
|
73
73
|
partialPrefetching: true,
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
export default
|
|
76
|
+
export default withGeistdocs(config);
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
Restart `next dev` after adding, deleting, or renaming an App Router page or route. Production builds always regenerate the route manifest.
|
|
80
|
+
|
|
79
81
|
Every root dynamic parameter needs at least one value from `generateStaticParams`. For a site with a `[lang]` root segment, return every configured language from the root layout:
|
|
80
82
|
|
|
81
83
|
```tsx title="app/[lang]/layout.tsx"
|
package/docs/pages/proxy.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: Proxy and markdown routes
|
|
3
3
|
description: Add custom request logic while keeping Geistdocs markdown negotiation in the package
|
|
4
4
|
type: reference
|
|
5
|
-
summary: Configure createProxy with
|
|
5
|
+
summary: Configure createProxy with generated route discovery, request hooks, markdown mappings, and a static Next.js matcher.
|
|
6
6
|
url: /docs/proxy
|
|
7
7
|
source: apps/template/content/docs/proxy.mdx
|
|
8
8
|
prerequisites:
|
|
@@ -179,6 +179,25 @@ export const config = {
|
|
|
179
179
|
|
|
180
180
|
The package keeps `llms.txt`, `sitemap.md`, `agents.md`, MCP discovery, and RSS out of root page-Markdown negotiation. Continue to exclude site-specific application and API routes with the matcher or a `before` hook. A root Markdown page is exposed as `/index.md`, or `<basePath>/index.md` publicly.
|
|
181
181
|
|
|
182
|
+
## Recover unmatched Markdown requests
|
|
183
|
+
|
|
184
|
+
`createGeistdocs` in `next.config.ts` generates a lightweight manifest from App Router pages and route handlers. When `agent` is enabled, `createProxy` uses this manifest to return a Markdown 404 only when a `GET` or `HEAD` request matches neither a Markdown mapping nor an application route.
|
|
185
|
+
|
|
186
|
+
The manifest contains route patterns, not page modules or content. Static, dynamic, catch-all, optional catch-all, grouped, and localized routes continue to Next.js. Root catch-all pages are treated as potentially valid, so the app remains responsible for their 404 behavior. The package's own `[...not-found]` route handler is excluded so it does not claim every path.
|
|
187
|
+
|
|
188
|
+
The integration also resolves `next.config.ts` rewrites. Static rewrite sources are matched exactly, while parameterized sources protect their safe static prefix. If a rewrite begins with a dynamic root segment, Geistdocs disables automatic recovery rather than risk returning a Markdown 404 for a real rewritten route.
|
|
189
|
+
|
|
190
|
+
No proxy option is required. Pass `markdownNotFound: false` only when the site needs to disable automatic recovery:
|
|
191
|
+
|
|
192
|
+
```ts title="proxy.ts"
|
|
193
|
+
const proxy = createProxy({
|
|
194
|
+
config: geistdocsConfig,
|
|
195
|
+
markdownNotFound: false,
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Existing sites that use `createMDX` directly do not receive a generated manifest and keep the previous opt-in behavior. Restart `next dev` after adding, deleting, or renaming a route; production builds always regenerate the manifest.
|
|
200
|
+
|
|
182
201
|
## Hook context
|
|
183
202
|
|
|
184
203
|
Both `before` and `after` receive the same context:
|
package/docs/sitemap.md
CHANGED
|
@@ -12,7 +12,7 @@ Use it to choose focused page files from `docs/pages/` before reading the full `
|
|
|
12
12
|
- [Syntax](pages/syntax.md) | URL: /docs/syntax | Type: reference | Summary: Supported MDX syntax including text formatting, code blocks, line highlighting, and Mermaid diagrams.
|
|
13
13
|
- [Geistdocs Provider](pages/provider.md) | URL: /docs/provider | Type: reference | Summary: The root provider component that wraps your application to handle toast notifications, search, and analytics.
|
|
14
14
|
- [Versioned docs](pages/versioned-docs.md) | URL: /docs/versioned-docs | Type: guide | Summary: Use createVersionedSources to configure stable, pre-release, or host-based documentation versions.
|
|
15
|
-
- [Proxy and markdown routes](pages/proxy.md) | URL: /docs/proxy | Type: reference | Summary: Configure createProxy with
|
|
15
|
+
- [Proxy and markdown routes](pages/proxy.md) | URL: /docs/proxy | Type: reference | Summary: Configure createProxy with generated route discovery, request hooks, markdown mappings, and a static Next.js matcher.
|
|
16
16
|
- [.md Extension](pages/md.md) | URL: /docs/md | Type: conceptual | Summary: Access any documentation page as raw Markdown by appending .md or .mdx to the URL for AI tool consumption.
|
|
17
17
|
- [Agent readiness](pages/agent-readiness.md) | URL: /docs/agent-readiness | Type: guide | Summary: Generate /agents.md and /.well-known/mcp.json from Geistdocs config so agents can find docs, Markdown surfaces, API specs, and MCP endpoints.
|
|
18
18
|
- [Ask AI](pages/ask-ai.md) | URL: /docs/ask-ai | Type: conceptual | Summary: An AI-powered chat assistant with context-aware search, persistent history, and suggested prompts for your documentation.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/geistdocs",
|
|
3
3
|
"description": "Runtime and CLI for Geistdocs projects.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.25.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -110,6 +110,10 @@
|
|
|
110
110
|
"types": "./dist/proxy.d.ts",
|
|
111
111
|
"default": "./dist/proxy.js"
|
|
112
112
|
},
|
|
113
|
+
"./next": {
|
|
114
|
+
"types": "./dist/next.d.ts",
|
|
115
|
+
"default": "./dist/next.js"
|
|
116
|
+
},
|
|
113
117
|
"./mdx": {
|
|
114
118
|
"types": "./dist/mdx.d.ts",
|
|
115
119
|
"default": "./dist/mdx.js"
|
package/template/AGENTS.md
CHANGED
|
@@ -52,12 +52,14 @@ Use these instructions when an AI coding agent edits this project.
|
|
|
52
52
|
## Routing and proxy guidelines
|
|
53
53
|
|
|
54
54
|
- Keep App Router route files as thin adapters around package helpers such as `createDocsPage`, `createChatRoute`, `createLlmsRoute`, and `createProxy`.
|
|
55
|
+
- Keep `createGeistdocs` from `@vercel/geistdocs/next` as the `next.config.ts` wrapper. It composes Fumadocs MDX and generates the app-route manifest used by `createProxy`; do not replace it with `createMDX` directly.
|
|
55
56
|
- Keep `cacheComponents: true` and `partialPrefetching: true` in `next.config.ts`. Do not export `dynamic`, `revalidate`, or `fetchCache` from App Router pages or route handlers.
|
|
56
57
|
- Read `[lang]` from `next/root-params` in Server Components. Keep route context `params` in Route Handlers and Server Actions.
|
|
57
58
|
- Use `prefetch={true}` for app-owned links to fully static documentation pages so navigation does not stop at the generic route shell.
|
|
58
59
|
- Keep `export const config` in `proxy.ts` as a static object. Next.js must parse proxy matchers at build time.
|
|
59
60
|
- Use proxy matcher exclusions that only match `/api` and `/api/...`, such as `api(?:/|$)`. Do not exclude broad prefixes like `api`, because that also excludes routes such as `/api-reference`.
|
|
60
61
|
- Preserve markdown negotiation unless the task explicitly changes AI-readable output. Geistdocs serves `/agents.md`, `/llms.txt`, `/.well-known/mcp.json`, and per-page Markdown for `.md`, `.mdx`, `Accept: text/markdown`, and AI-agent requests.
|
|
62
|
+
- Restart `next dev` after adding, deleting, or renaming an App Router page or route so `createGeistdocs` regenerates its route manifest.
|
|
61
63
|
- When adding custom proxy behavior, prefer `before`, `after`, and `markdownRoutes` options on `createProxy` instead of replacing the proxy.
|
|
62
64
|
- Use explicit `markdownRoutes` for root-mounted docs or any site where homepage/app routes coexist with docs routes.
|
|
63
65
|
- Keep source URLs, navigation links, `getPageUrl`, and `markdownRoutes` app-local when `config.basePath` is set. Geistdocs derives public page-action and Markdown URLs separately.
|
|
@@ -25,6 +25,7 @@ Configure Geistdocs through user-owned files in the generated project. Runtime f
|
|
|
25
25
|
| File | Purpose |
|
|
26
26
|
| --- | --- |
|
|
27
27
|
| `geistdocs.tsx` | Site-level settings, including logo, nav, GitHub repo, AI prompt, agent-readiness metadata, translations, and feature flags. |
|
|
28
|
+
| `next.config.ts` | Composes Fumadocs MDX, discovers App Router routes, and configures Next.js. |
|
|
28
29
|
| `source.config.ts` | Configures Fumadocs collections with the package-provided schema, Markdown plugins, and syntax theme. |
|
|
29
30
|
| `lib/geistdocs/config.tsx` | Converts `geistdocs.tsx` exports into the package config using `defineConfig`. |
|
|
30
31
|
| `source.config.ts` | Configures Fumadocs collections with package-safe schemas and Markdown processing. |
|
|
@@ -214,11 +215,18 @@ To serve docs from the site root, use `route: "/"` in `content` and `baseUrl: "/
|
|
|
214
215
|
When Next.js mounts the application below a path, set the same value in `next.config.ts` and Geistdocs config:
|
|
215
216
|
|
|
216
217
|
```ts title="next.config.ts"
|
|
218
|
+
import { createGeistdocs } from "@vercel/geistdocs/next";
|
|
219
|
+
import type { NextConfig } from "next";
|
|
220
|
+
|
|
221
|
+
const withGeistdocs = createGeistdocs();
|
|
222
|
+
|
|
217
223
|
const config: NextConfig = {
|
|
218
224
|
basePath: "/docs",
|
|
219
225
|
cacheComponents: true,
|
|
220
226
|
partialPrefetching: true,
|
|
221
227
|
};
|
|
228
|
+
|
|
229
|
+
export default withGeistdocs(config);
|
|
222
230
|
```
|
|
223
231
|
|
|
224
232
|
```tsx title="geistdocs.tsx"
|
|
@@ -69,7 +69,6 @@ import { geistdocsSource } from "@/lib/geistdocs/source";
|
|
|
69
69
|
|
|
70
70
|
export const { GET, generateStaticParams } =
|
|
71
71
|
createDocsMarkdownRoute({
|
|
72
|
-
notFound: {},
|
|
73
72
|
sources: [geistdocsSource],
|
|
74
73
|
});
|
|
75
74
|
```
|
|
@@ -93,7 +92,7 @@ When a Markdown request does not match a page, Geistdocs returns an agent-readab
|
|
|
93
92
|
|
|
94
93
|
For example, a request for `/docs/env-vars` can suggest `/docs/environment-variables.md`. The response uses a short cache lifetime and returns a real `404` status. It also sends `X-Robots-Tag: noindex` and no canonical link because the requested page does not exist. Regular HTML requests keep the app's standard not-found behavior.
|
|
95
94
|
|
|
96
|
-
|
|
95
|
+
The suggestion response is enabled by default. Pass `notFound: { status: 410 }` for permanently removed pages, or `notFound: false` to use the standard Next.js not-found response. Legacy `status: 200` values are treated as `404` so missing pages always return a real error status.
|
|
97
96
|
|
|
98
97
|
If a custom `markdownRoutes` mapping changes the public path shape, set `notFound.getRequestedPath` to reconstruct the app-local public pathname. This also keeps page lookup and suggestions within the right source when a flattened route serves multiple sources:
|
|
99
98
|
|
|
@@ -110,15 +109,19 @@ Set `notFound.getPageMarkdownUrl` as well when suggested pages use a custom app-
|
|
|
110
109
|
|
|
111
110
|
### Unmatched application paths
|
|
112
111
|
|
|
113
|
-
|
|
112
|
+
When `agent` is enabled, `createGeistdocs` scans App Router pages and route handlers during `next dev` and `next build`. `createProxy` uses that generated manifest to distinguish valid application routes from unknown paths. Valid routes continue to the app's HTML or route-handler response. Unknown Markdown or detected-agent `GET` and `HEAD` requests receive a concise 404 with links to the docs, `sitemap.md`, and `llms.txt`.
|
|
114
113
|
|
|
115
|
-
|
|
114
|
+
Markdown mappings take precedence over generated app routes, so a route that has both HTML and Markdown continues to negotiate Markdown. Dynamic app routes are treated as potentially valid; the app remains responsible for returning its own 404 when a specific slug does not exist.
|
|
115
|
+
|
|
116
|
+
Pass `markdownNotFound: false` to disable automatic unmatched-path recovery:
|
|
116
117
|
|
|
117
118
|
```ts title="proxy.ts"
|
|
118
119
|
const proxy = createProxy({
|
|
119
120
|
config: geistdocsConfig,
|
|
120
|
-
markdownNotFound:
|
|
121
|
+
markdownNotFound: false,
|
|
121
122
|
});
|
|
122
123
|
```
|
|
123
124
|
|
|
125
|
+
Sites that do not use `createGeistdocs` keep the previous opt-in behavior. Existing boolean and predicate forms remain supported for compatibility.
|
|
126
|
+
|
|
124
127
|
`createNotFoundRoute` remains available for apps that prefer an explicit catch-all Route Handler with Geistdocs' minimal HTML response.
|
|
@@ -56,24 +56,26 @@ If you are starting from a generated Geistdocs project and moving content into i
|
|
|
56
56
|
pnpm dlx @vercel/geistdocs init --name my-docs
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
##
|
|
59
|
+
## Configure Next.js
|
|
60
60
|
|
|
61
|
-
Geistdocs
|
|
61
|
+
The Geistdocs Next.js integration composes Fumadocs MDX, enables automatic app-route discovery for agent-readable 404s, and preserves your Next.js configuration. Enable Cache Components in the same file:
|
|
62
62
|
|
|
63
63
|
```ts title="next.config.ts"
|
|
64
|
-
import {
|
|
64
|
+
import { createGeistdocs } from "@vercel/geistdocs/next";
|
|
65
65
|
import type { NextConfig } from "next";
|
|
66
66
|
|
|
67
|
-
const
|
|
67
|
+
const withGeistdocs = createGeistdocs();
|
|
68
68
|
|
|
69
69
|
const config: NextConfig = {
|
|
70
70
|
cacheComponents: true,
|
|
71
71
|
partialPrefetching: true,
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
export default
|
|
74
|
+
export default withGeistdocs(config);
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
Restart `next dev` after adding, deleting, or renaming an App Router page or route. Production builds always regenerate the route manifest.
|
|
78
|
+
|
|
77
79
|
Every root dynamic parameter needs at least one value from `generateStaticParams`. For a site with a `[lang]` root segment, return every configured language from the root layout:
|
|
78
80
|
|
|
79
81
|
```tsx title="app/[lang]/layout.tsx"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: Proxy and markdown routes
|
|
3
3
|
description: Add custom request logic while keeping Geistdocs markdown negotiation in the package
|
|
4
4
|
type: reference
|
|
5
|
-
summary: Configure createProxy with
|
|
5
|
+
summary: Configure createProxy with generated route discovery, request hooks, markdown mappings, and a static Next.js matcher.
|
|
6
6
|
prerequisites:
|
|
7
7
|
- /docs/configuration
|
|
8
8
|
related:
|
|
@@ -177,6 +177,25 @@ export const config = {
|
|
|
177
177
|
|
|
178
178
|
The package keeps `llms.txt`, `sitemap.md`, `agents.md`, MCP discovery, and RSS out of root page-Markdown negotiation. Continue to exclude site-specific application and API routes with the matcher or a `before` hook. A root Markdown page is exposed as `/index.md`, or `<basePath>/index.md` publicly.
|
|
179
179
|
|
|
180
|
+
## Recover unmatched Markdown requests
|
|
181
|
+
|
|
182
|
+
`createGeistdocs` in `next.config.ts` generates a lightweight manifest from App Router pages and route handlers. When `agent` is enabled, `createProxy` uses this manifest to return a Markdown 404 only when a `GET` or `HEAD` request matches neither a Markdown mapping nor an application route.
|
|
183
|
+
|
|
184
|
+
The manifest contains route patterns, not page modules or content. Static, dynamic, catch-all, optional catch-all, grouped, and localized routes continue to Next.js. Root catch-all pages are treated as potentially valid, so the app remains responsible for their 404 behavior. The package's own `[...not-found]` route handler is excluded so it does not claim every path.
|
|
185
|
+
|
|
186
|
+
The integration also resolves `next.config.ts` rewrites. Static rewrite sources are matched exactly, while parameterized sources protect their safe static prefix. If a rewrite begins with a dynamic root segment, Geistdocs disables automatic recovery rather than risk returning a Markdown 404 for a real rewritten route.
|
|
187
|
+
|
|
188
|
+
No proxy option is required. Pass `markdownNotFound: false` only when the site needs to disable automatic recovery:
|
|
189
|
+
|
|
190
|
+
```ts title="proxy.ts"
|
|
191
|
+
const proxy = createProxy({
|
|
192
|
+
config: geistdocsConfig,
|
|
193
|
+
markdownNotFound: false,
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Existing sites that use `createMDX` directly do not receive a generated manifest and keep the previous opt-in behavior. Restart `next dev` after adding, deleting, or renaming a route; production builds always regenerate the manifest.
|
|
198
|
+
|
|
180
199
|
## Hook context
|
|
181
200
|
|
|
182
201
|
Both `before` and `after` receive the same context:
|
package/template/next.config.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { createGeistdocs } from "@vercel/geistdocs/next";
|
|
4
4
|
import type { NextConfig } from "next";
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const withGeistdocs = createGeistdocs();
|
|
7
7
|
|
|
8
8
|
// In this monorepo, compile @vercel/geistdocs from its workspace source so edits
|
|
9
9
|
// to the package hot-reload in the running dev server (no rebuild/restart).
|
|
@@ -41,4 +41,4 @@ const config: NextConfig = {
|
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
export default
|
|
44
|
+
export default withGeistdocs(config);
|
package/template/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@streamdown/code": "^1.0.1",
|
|
19
19
|
"@vercel/agent-readability": "^0.6.0",
|
|
20
20
|
"@vercel/analytics": "^1.6.1",
|
|
21
|
-
"@vercel/geistdocs": "1.
|
|
21
|
+
"@vercel/geistdocs": "1.25.0",
|
|
22
22
|
"@vercel/speed-insights": "^1.3.1",
|
|
23
23
|
"ai": "^6.0.132",
|
|
24
24
|
"class-variance-authority": "^0.7.1",
|