@vercel/geistdocs 2.15.2 → 2.15.3-canary.633944d

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 CHANGED
@@ -4,4 +4,4 @@ import{Option as Rn,program as A}from"commander";import{access as Ke,copyFile as
4
4
  `);throw new AggregateError(i,`Mixedbread search sync did not complete:
5
5
  ${a}`)}return r},Ft=async({client:e,file:t,pollIntervalMs:n,pollTimeoutMs:r,sleep:i})=>{let s=t,o=Date.now()+r;for(;s.status==="pending"||s.status==="in_progress";){if(Date.now()>=o)throw new Error(`Mixedbread timed out while indexing file ${t.id}.`);await i(n),s=await e.retrieveStoreFile(t.id)}if(s.status!=="completed")throw new Error(`Mixedbread failed to index file ${t.id} (${s.status}).`);return s},Dt=async({client:e,desired:t,pollIntervalMs:n,pollTimeoutMs:r,sleep:i})=>{let s=await e.uploadFile({content:t.document.content,filename:`${U(t.document.id).slice(0,32)}.md`}),o;try{o=await e.createStoreFile({externalId:t.externalId,fileId:s,metadata:{...t.metadata,[g.rawFileId]:s}})}catch(a){try{await e.deleteFile(s)}catch(d){throw new AggregateError([a,d],`Mixedbread failed to attach and clean up raw file ${s}.`)}throw a}return Ft({client:e,file:o,pollIntervalMs:n,pollTimeoutMs:r,sleep:i})},Ie=async({client:e,concurrency:t=St,manifest:n,pollIntervalMs:r=_t,pollTimeoutMs:i=Tt,revision:s,revisionAncestors:o=[],revisionTimestamp:a,sleep:d=Rt})=>{let c=_e(n);if(c.provider!=="mixedbread")return{deleted:0,skipped:c.documents.length,uploaded:0};let u=c.siteId?.trim();if(!u)throw new Error("Mixedbread retrieval requires a non-empty siteId in geistdocs.tsx.");if(c.documents.length===0)throw new Error("The Geistdocs search export is empty. Refusing to remove indexed documents.");let l=c.documents.map(p=>At(p,u,s,o,a)),m=new Map(l.map(p=>[p.document.id,p])),h=(await be(e)).flatMap(p=>{let y=q(p.metadata);return y?.siteId===u?[{file:p,metadata:y}]:[]}),x=new Map,P=new Set;for(let p of h){W(p.metadata,s,a)&&P.add(p.metadata.documentId);let y=m.get(p.metadata.documentId);y&&p.metadata.contentHash===y.hash&&p.file.status==="completed"&&!x.has(p.metadata.documentId)&&x.set(p.metadata.documentId,p)}let _=l.filter(p=>!(x.has(p.document.id)||P.has(p.document.id)));await Ee(_,t,p=>Dt({client:e,desired:p,pollIntervalMs:r,pollTimeoutMs:i,sleep:d}));let b=(await be(e)).flatMap(p=>{let y=q(p.metadata);return y?.siteId===u?[{file:p,metadata:y}]:[]}),D=new Set(b.filter(({metadata:p})=>W(p,s,a)).map(({metadata:p})=>p.documentId)),ie=new Set;for(let p of l){if(D.has(p.document.id))continue;let ae=b.filter(({file:V,metadata:k})=>V.status==="completed"&&k.documentId===p.document.id&&k.contentHash===p.hash).sort((V,k)=>V.file.id.localeCompare(k.file.id))[0];ae&&ie.add(ae.file.id)}let oe=b.filter(({file:p,metadata:y})=>p.status!=="pending"&&p.status!=="in_progress"&&!W(y,s,a)&&Mt({currentRevision:s,currentRevisionAncestors:o,currentRevisionTimestamp:a,desired:m.get(y.documentId),metadata:y})&&!ie.has(p.id));return await Ee(oe,t,async({file:p,metadata:y})=>{await e.deleteFile(y.rawFileId??p.id),await e.deleteStoreFile(p.id)}),{deleted:oe.length,skipped:l.length-_.length,uploaded:_.length}};var Ot=50,$t=e=>`vercel integration add mixedbread --name docs-${e||"your-site-id"} --environment production`,ve=(e,t)=>kt("git",t,{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim(),Nt=e=>{let t=process.env.VERCEL_GIT_COMMIT_SHA?.trim(),n=[];try{n=ve(e,["rev-list",`--max-count=${Ot+1}`,t||"HEAD"]).split(`
6
6
  `).filter(Boolean)}catch{n=[]}let r=t||n[0],i;for(let s of Array.from(new Set([r,"HEAD"].filter(Boolean))))try{let o=Number(ve(e,["show","-s","--format=%ct",s]));if(Number.isFinite(o)){i=o;break}}catch{}return{revision:r,revisionAncestors:n.filter(s=>s!==r),revisionTimestamp:i}},Pe=async({allowNonProduction:e=!1,dir:t=".next"}={})=>{let n=process.cwd();Ct.loadEnvConfig(n,!1);let r=process.env.MXBAI_API_KEY?.trim(),i=process.env.MXBAI_STORE_ID?.trim();if(process.env.VERCEL_ENV!=="production"&&!e){console.log("Geistdocs search sync skipped: this is not a production Vercel build.");return}if(!!r!=!!i)throw new Error("Mixedbread is partially configured. Set both MXBAI_API_KEY and MXBAI_STORE_ID.");let s;try{s=await Te({cwd:n,outputDirectory:t})}catch(a){if(!(r||i)){console.log("Geistdocs search sync skipped: no Mixedbread credentials or static search export were found.");return}throw a}if(s.provider!=="mixedbread"){console.log("Geistdocs search sync skipped: Ask AI uses local retrieval.");return}if(!(r&&i))throw new Error(["Mixedbread retrieval is enabled, but MXBAI_API_KEY or MXBAI_STORE_ID is missing.","From the root of this site's repository, linked to the correct Vercel project, run:",$t(s.siteId)].join(`
7
- `));let o=await Ie({client:we({apiBaseUrl:process.env.MXBAI_BASE_URL,apiKey:r,storeId:i}),manifest:s,...Nt(n)});console.log(`Geistdocs search sync complete: ${o.uploaded} uploaded, ${o.deleted} deleted, ${o.skipped} unchanged.`)};import{readFileSync as Gt,writeFileSync as Ut}from"fs";import{mkdir as Lt,readFile as Z,writeFile as jt}from"fs/promises";import{dirname as Bt,extname as Vt,relative as Fe,resolve as j}from"path";import{intro as Jt,isCancel as Ht,log as I,multiselect as Xt,outro as L,spinner as Kt}from"@clack/prompts";import{glob as Yt}from"glob";import{Node as F,Project as qt,SyntaxKind as zt}from"ts-morph";var Wt="geistdocs.tsx",Qt="content/docs/**/*.mdx",ee=".translation-cache.json",Q=8,Ae=()=>({version:1,entries:{}}),Zt=async e=>{let t=await Z(e),{createHash:n}=await import("crypto");return n("sha256").update(t).digest("hex")},en=e=>{let t=j(process.cwd(),e);return Gt(t,"utf8")},Me=e=>F.isObjectLiteralExpression(e)?e.getProperties().flatMap(t=>{if(F.isPropertyAssignment(t)){let n=t.getNameNode();if(F.isIdentifier(n)||F.isStringLiteral(n))return[n.getText().replaceAll(/['"]/g,"")]}return[]}).filter(Boolean):[],tn=e=>{try{let t=new qt({compilerOptions:{allowJs:!0,jsx:4,module:99,target:10},skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!0}),n=en(e),s=t.createSourceFile(e,n,{overwrite:!0}).getVariableDeclarations().find(a=>a.getName()==="translations")?.getInitializer();if(!s)return[];if(F.isObjectLiteralExpression(s))return Me(s);let o=s.getFirstDescendantByKind(zt.ObjectLiteralExpression);return o?Me(o):[]}catch(t){let n=t instanceof Error?t.message:`${t}`;return I.warn(`Failed to read locales from ${e}: ${n}`),[]}},nn=async()=>{let e=await Xt({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 Ht(e)&&(L("Translation cancelled"),process.exit(0)),e},rn=async e=>(await Yt(e,{cwd:process.cwd(),absolute:!0,nodir:!0})).sort(),sn=async()=>{let e=j(process.cwd(),ee);try{let t=await Z(e,"utf8"),n=JSON.parse(t);return n.version!==1||!n.entries?Ae():{version:1,entries:n.entries}}catch{return Ae()}},Re=e=>{let t=j(process.cwd(),ee),n=JSON.stringify(e,null,2);Ut(t,n,"utf8")},on=async e=>{let t=await Promise.all(e.map(async n=>[n,await Zt(n)]));return Object.fromEntries(t)},an=(e,t)=>{let n=Vt(e);return`${e.slice(0,-n.length)}.${t}${n}`},De=(e,t)=>`${Fe(process.cwd(),e)}::${t}`,cn=(e,t,n,r,i=!1)=>{let s=[],o=0;for(let a of t){let d=n[a];for(let c of e){let u=an(a,c),l=De(a,c),m=r.entries[l];if(!i&&m?.hash===d){o+=1;continue}s.push({locale:c,sourceFile:a,sourceHash:d,targetFile:u})}}return{tasks:s,skippedCount:o}},dn=async e=>{await Lt(Bt(e),{recursive:!0})},ln=async(e,t,n)=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,locale:n})});if(!r.ok){let s=await r.text();throw new Error(`API request failed (${r.status}): ${s}`)}let i=await r.json();if(!i.translation)throw new Error("API response did not include a translation");return i.translation},pn=async(e,t,n)=>{let r=await Z(e.sourceFile,"utf8"),i=await ln(t,r,e.locale);await dn(e.targetFile),await jt(e.targetFile,i,"utf8"),n.entries[De(e.sourceFile,e.locale)]={hash:e.sourceHash,updatedAt:new Date().toISOString()}},ke=async(e,t)=>{Jt("Translate MDX content");let n=e??Qt,r=t.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",i=tn(t.config??Wt),s=await rn(n);s.length===0&&(I.error(`No MDX files found matching pattern: ${n}`),L("Translation cancelled"),process.exit(1)),I.info(`Found ${s.length} MDX file(s) matching pattern`),i.length===0&&(i=await nn());let o=j(process.cwd(),ee),a=await sn();await Re(a),I.info(`Using cache: ${o}`);let d=await on(s),{tasks:c,skippedCount:u}=cn(i,s,d,a,t.force);if(c.length===0){I.success("All translations are up to date!"),L(`Skipped ${u} file(s) (unchanged)`);return}let l=[];for(let h=0;h<c.length;h+=Q)l.push(c.slice(h,h+Q));I.info(`Processing ${c.length} translation(s) in ${l.length} batch(es) of up to ${Q}`),u>0&&I.info(`Skipped ${u} translation(s) (unchanged)`);let m=Kt();m.start("Translating content...");let f=0;for(let h of l)await Promise.all(h.map(async x=>{await pn(x,r,a),f+=1,m.message(`Translated ${f}/${c.length}: ${Fe(process.cwd(),x.targetFile)}`)})),await Re(a);m.stop("Translation complete!"),L(`Created/updated ${c.length} file(s)`)};import{access as un,copyFile as gn,mkdir as Ne,rm as re}from"fs/promises";import{dirname as mn,join as v}from"path";import{intro as fn,log as w,outro as B,spinner as Ge}from"@clack/prompts";import{glob as hn}from"glob";var wn=["**/*"],yn=["content/docs/**"],te=".geistdocs-tmp",xn=async(e,t)=>{let n=v(e,t);await re(n,{recursive:!0,force:!0}),await Ne(n,{recursive:!0})},ne=async e=>await re(e,{recursive:!0,force:!0}),Ce=async(e,t,n)=>(await hn(e,{cwd:n,nodir:!0,dot:!0,ignore:[".git/**",...t]})).sort(),bn=async e=>{try{return await un(e),!0}catch{return!1}},En=async(e,t,n)=>{let r=v(t,e),i=v(n,e);return await bn(r)?(await gn(r,i),{success:!0}):{success:!1,error:`Source file not found: ${r}`}},Sn=async(e,t)=>{let n=v(t,e);return await re(n,{force:!0}),{success:!0}},Oe=20,$e=async(e,t,n)=>{let r=[];for(let i=0;i<e.length;i+=n){let s=e.slice(i,i+n),o=await Promise.all(s.map(t));r.push(...o)}return r},_n=async(e,t,n,r,i)=>{let s={success:[],deleted:[],failed:[]},o=[...new Set(e.map(d=>mn(v(r,d))))];i.message(`Creating ${o.length} directories...`),await Promise.all(o.map(d=>Ne(d,{recursive:!0}))),i.message(`Updating ${e.length} files...`);let a=await $e(e,async d=>{let c=await En(d,n,r);return{file:d,...c}},Oe);for(let{file:d,success:c,error:u}of a)c?s.success.push(d):s.failed.push({file:d,error:u??"Unknown error"});if(t.length>0){i.message(`Deleting ${t.length} files...`);let d=await $e(t,async c=>{try{return await Sn(c,r),{file:c,success:!0}}catch(u){let l=u instanceof Error?u.message:`${u}`;return{file:c,success:!1,error:l}}},Oe);for(let c of d)c.success?s.deleted.push(c.file):s.failed.push({file:c.file,error:c.error})}return s},Tn=e=>{if(e.success.length>0){w.success(`Successfully updated ${e.success.length} files:`);for(let t of e.success)w.info(` \u2713 ${t}`)}if(e.deleted.length>0){w.success(`Deleted ${e.deleted.length} files:`);for(let t of e.deleted)w.info(` \u{1F5D1} ${t}`)}if(e.failed.length>0){w.warn(`Failed to update ${e.failed.length} files:`);for(let{file:t,error:n}of e.failed)w.error(` \u2717 ${t}: ${n}`)}},In=e=>e.includes("canary")?"canary":"latest",vn=async e=>{let t=await fetch(`https://registry.npmjs.org/${encodeURIComponent(S)}`);if(!t.ok)throw new Error(`Failed to resolve ${S}@${e}`);let r=(await t.json())["dist-tags"]?.[e];if(!r)throw new Error(`Could not find dist-tag ${e} for ${S}`);return r},Pn=async e=>{let t=await M(e),n=J(t,S);if(!n)return{currentVersion:n,nextVersion:void 0,updated:!1};let r=In(n),i=await vn(r);return n===i?{currentVersion:n,nextVersion:i,updateTag:r,updated:!1}:($(t,S,i),await O(e,t),{currentVersion:n,nextVersion:i,updateTag:r,updated:!0})},An=async(e,t,n)=>{let r=await M(e);if(!le(r,S))return!1;t&&t.length>0&&w.warn("Ignoring file patterns for a package-based site. This update will bump the package version instead."),n?.sync&&w.warn("Ignoring --sync for a package-based site. Runtime updates now come from the package version.");let{currentVersion:i,nextVersion:s,updateTag:o,updated:a}=await Pn(e);if(!a)return w.success(i?`@vercel/geistdocs is already at ${s} (${o}).`:"No package version update was needed."),B("Package-based site is already up to date."),!0;w.info(`Bumping ${S} from ${i} to ${s} (${o})`);let d=Ge();return d.start("Installing updated package version..."),await T("pnpm",["install"],{cwd:e}),d.stop("Package update complete!"),B("Please review and test the upgraded package version."),!0},Mn=async(e,t,n,r,i)=>{let s=v(e,te),o=Ge(),a=i?.sync?s:t;o.start("Preparing template snapshot..."),i?.sync&&(await xn(e,te),await N(s)),o.message("Scanning for files...");let d=await Ce(n,r,a),c=[];if(i?.sync){o.message("Comparing with local files...");let l=await Ce(n,r,e),m=new Set(d);c=l.filter(f=>!m.has(f))}if(o.stop(`Found ${d.length} files to update`),d.length===0&&c.length===0){w.warn("No files matched the patterns. Nothing to update."),i?.sync&&await ne(s),B("Update cancelled.");return}w.info(`Patterns: ${n.length}`),w.info(`Files to update: ${d.length}`),i?.sync&&w.info(`Files to delete: ${c.length}`),o.start("Updating files...");let u=await _n(d,c,a,e,o);i?.sync&&(o.message("Cleaning up..."),await ne(s)),o.stop("Update complete!"),Tn(u),B("Please review and test the changes carefully.")},Ue=async(e,t)=>{let n=process.cwd(),r=H(),i=e&&e.length>0?e:wn,s=e&&e.length>0?[]:yn;try{if(fn("Let's update your Geistdocs project!"),await An(n,e,t))return;w.info("Template source: bundled package snapshot"),e&&e.length>0&&w.info(`Updating specific files: ${e.join(", ")}`),t?.sync&&w.info("Sync mode enabled: will delete files removed from template"),await Mn(n,r,i,s,t)}catch(o){let a=o instanceof Error?o.message:`${o}`;try{await ne(v(n,te))}catch{}w.error(`Failed to update project: ${a}`),process.exit(1)}};A.name("geistdocs").description("CLI for Geistdocs projects").version("2.15.2","-v, --version","Output the current version");A.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").addOption(new Rn("--brand <brand>","Navbar brand").choices(["vercel","labs"]).default("vercel")).option("--disable-git","Disable git initialization").action(he);A.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(Ue);A.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(ke);var Fn=A.command("search").description("Manage the external search index used by Ask AI");Fn.command("sync").description("Sync the latest static docs export to Mixedbread").option("--dir <path>","Next.js output directory",".next").option("--allow-non-production","Run outside a production Vercel build").action(Pe);await A.parseAsync(process.argv).catch(e=>{console.error(e instanceof Error?e.message:e),process.exitCode=1});
7
+ `));let o=await Ie({client:we({apiBaseUrl:process.env.MXBAI_BASE_URL,apiKey:r,storeId:i}),manifest:s,...Nt(n)});console.log(`Geistdocs search sync complete: ${o.uploaded} uploaded, ${o.deleted} deleted, ${o.skipped} unchanged.`)};import{readFileSync as Gt,writeFileSync as Ut}from"fs";import{mkdir as Lt,readFile as Z,writeFile as jt}from"fs/promises";import{dirname as Bt,extname as Vt,relative as Fe,resolve as j}from"path";import{intro as Jt,isCancel as Ht,log as I,multiselect as Xt,outro as L,spinner as Kt}from"@clack/prompts";import{glob as Yt}from"glob";import{Node as F,Project as qt,SyntaxKind as zt}from"ts-morph";var Wt="geistdocs.tsx",Qt="content/docs/**/*.mdx",ee=".translation-cache.json",Q=8,Ae=()=>({version:1,entries:{}}),Zt=async e=>{let t=await Z(e),{createHash:n}=await import("crypto");return n("sha256").update(t).digest("hex")},en=e=>{let t=j(process.cwd(),e);return Gt(t,"utf8")},Me=e=>F.isObjectLiteralExpression(e)?e.getProperties().flatMap(t=>{if(F.isPropertyAssignment(t)){let n=t.getNameNode();if(F.isIdentifier(n)||F.isStringLiteral(n))return[n.getText().replaceAll(/['"]/g,"")]}return[]}).filter(Boolean):[],tn=e=>{try{let t=new qt({compilerOptions:{allowJs:!0,jsx:4,module:99,target:10},skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!0}),n=en(e),s=t.createSourceFile(e,n,{overwrite:!0}).getVariableDeclarations().find(a=>a.getName()==="translations")?.getInitializer();if(!s)return[];if(F.isObjectLiteralExpression(s))return Me(s);let o=s.getFirstDescendantByKind(zt.ObjectLiteralExpression);return o?Me(o):[]}catch(t){let n=t instanceof Error?t.message:`${t}`;return I.warn(`Failed to read locales from ${e}: ${n}`),[]}},nn=async()=>{let e=await Xt({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 Ht(e)&&(L("Translation cancelled"),process.exit(0)),e},rn=async e=>(await Yt(e,{cwd:process.cwd(),absolute:!0,nodir:!0})).sort(),sn=async()=>{let e=j(process.cwd(),ee);try{let t=await Z(e,"utf8"),n=JSON.parse(t);return n.version!==1||!n.entries?Ae():{version:1,entries:n.entries}}catch{return Ae()}},Re=e=>{let t=j(process.cwd(),ee),n=JSON.stringify(e,null,2);Ut(t,n,"utf8")},on=async e=>{let t=await Promise.all(e.map(async n=>[n,await Zt(n)]));return Object.fromEntries(t)},an=(e,t)=>{let n=Vt(e);return`${e.slice(0,-n.length)}.${t}${n}`},De=(e,t)=>`${Fe(process.cwd(),e)}::${t}`,cn=(e,t,n,r,i=!1)=>{let s=[],o=0;for(let a of t){let d=n[a];for(let c of e){let u=an(a,c),l=De(a,c),m=r.entries[l];if(!i&&m?.hash===d){o+=1;continue}s.push({locale:c,sourceFile:a,sourceHash:d,targetFile:u})}}return{tasks:s,skippedCount:o}},dn=async e=>{await Lt(Bt(e),{recursive:!0})},ln=async(e,t,n)=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,locale:n})});if(!r.ok){let s=await r.text();throw new Error(`API request failed (${r.status}): ${s}`)}let i=await r.json();if(!i.translation)throw new Error("API response did not include a translation");return i.translation},pn=async(e,t,n)=>{let r=await Z(e.sourceFile,"utf8"),i=await ln(t,r,e.locale);await dn(e.targetFile),await jt(e.targetFile,i,"utf8"),n.entries[De(e.sourceFile,e.locale)]={hash:e.sourceHash,updatedAt:new Date().toISOString()}},ke=async(e,t)=>{Jt("Translate MDX content");let n=e??Qt,r=t.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",i=tn(t.config??Wt),s=await rn(n);s.length===0&&(I.error(`No MDX files found matching pattern: ${n}`),L("Translation cancelled"),process.exit(1)),I.info(`Found ${s.length} MDX file(s) matching pattern`),i.length===0&&(i=await nn());let o=j(process.cwd(),ee),a=await sn();await Re(a),I.info(`Using cache: ${o}`);let d=await on(s),{tasks:c,skippedCount:u}=cn(i,s,d,a,t.force);if(c.length===0){I.success("All translations are up to date!"),L(`Skipped ${u} file(s) (unchanged)`);return}let l=[];for(let h=0;h<c.length;h+=Q)l.push(c.slice(h,h+Q));I.info(`Processing ${c.length} translation(s) in ${l.length} batch(es) of up to ${Q}`),u>0&&I.info(`Skipped ${u} translation(s) (unchanged)`);let m=Kt();m.start("Translating content...");let f=0;for(let h of l)await Promise.all(h.map(async x=>{await pn(x,r,a),f+=1,m.message(`Translated ${f}/${c.length}: ${Fe(process.cwd(),x.targetFile)}`)})),await Re(a);m.stop("Translation complete!"),L(`Created/updated ${c.length} file(s)`)};import{access as un,copyFile as gn,mkdir as Ne,rm as re}from"fs/promises";import{dirname as mn,join as v}from"path";import{intro as fn,log as w,outro as B,spinner as Ge}from"@clack/prompts";import{glob as hn}from"glob";var wn=["**/*"],yn=["content/docs/**"],te=".geistdocs-tmp",xn=async(e,t)=>{let n=v(e,t);await re(n,{recursive:!0,force:!0}),await Ne(n,{recursive:!0})},ne=async e=>await re(e,{recursive:!0,force:!0}),Ce=async(e,t,n)=>(await hn(e,{cwd:n,nodir:!0,dot:!0,ignore:[".git/**",...t]})).sort(),bn=async e=>{try{return await un(e),!0}catch{return!1}},En=async(e,t,n)=>{let r=v(t,e),i=v(n,e);return await bn(r)?(await gn(r,i),{success:!0}):{success:!1,error:`Source file not found: ${r}`}},Sn=async(e,t)=>{let n=v(t,e);return await re(n,{force:!0}),{success:!0}},Oe=20,$e=async(e,t,n)=>{let r=[];for(let i=0;i<e.length;i+=n){let s=e.slice(i,i+n),o=await Promise.all(s.map(t));r.push(...o)}return r},_n=async(e,t,n,r,i)=>{let s={success:[],deleted:[],failed:[]},o=[...new Set(e.map(d=>mn(v(r,d))))];i.message(`Creating ${o.length} directories...`),await Promise.all(o.map(d=>Ne(d,{recursive:!0}))),i.message(`Updating ${e.length} files...`);let a=await $e(e,async d=>{let c=await En(d,n,r);return{file:d,...c}},Oe);for(let{file:d,success:c,error:u}of a)c?s.success.push(d):s.failed.push({file:d,error:u??"Unknown error"});if(t.length>0){i.message(`Deleting ${t.length} files...`);let d=await $e(t,async c=>{try{return await Sn(c,r),{file:c,success:!0}}catch(u){let l=u instanceof Error?u.message:`${u}`;return{file:c,success:!1,error:l}}},Oe);for(let c of d)c.success?s.deleted.push(c.file):s.failed.push({file:c.file,error:c.error})}return s},Tn=e=>{if(e.success.length>0){w.success(`Successfully updated ${e.success.length} files:`);for(let t of e.success)w.info(` \u2713 ${t}`)}if(e.deleted.length>0){w.success(`Deleted ${e.deleted.length} files:`);for(let t of e.deleted)w.info(` \u{1F5D1} ${t}`)}if(e.failed.length>0){w.warn(`Failed to update ${e.failed.length} files:`);for(let{file:t,error:n}of e.failed)w.error(` \u2717 ${t}: ${n}`)}},In=e=>e.includes("canary")?"canary":"latest",vn=async e=>{let t=await fetch(`https://registry.npmjs.org/${encodeURIComponent(S)}`);if(!t.ok)throw new Error(`Failed to resolve ${S}@${e}`);let r=(await t.json())["dist-tags"]?.[e];if(!r)throw new Error(`Could not find dist-tag ${e} for ${S}`);return r},Pn=async e=>{let t=await M(e),n=J(t,S);if(!n)return{currentVersion:n,nextVersion:void 0,updated:!1};let r=In(n),i=await vn(r);return n===i?{currentVersion:n,nextVersion:i,updateTag:r,updated:!1}:($(t,S,i),await O(e,t),{currentVersion:n,nextVersion:i,updateTag:r,updated:!0})},An=async(e,t,n)=>{let r=await M(e);if(!le(r,S))return!1;t&&t.length>0&&w.warn("Ignoring file patterns for a package-based site. This update will bump the package version instead."),n?.sync&&w.warn("Ignoring --sync for a package-based site. Runtime updates now come from the package version.");let{currentVersion:i,nextVersion:s,updateTag:o,updated:a}=await Pn(e);if(!a)return w.success(i?`@vercel/geistdocs is already at ${s} (${o}).`:"No package version update was needed."),B("Package-based site is already up to date."),!0;w.info(`Bumping ${S} from ${i} to ${s} (${o})`);let d=Ge();return d.start("Installing updated package version..."),await T("pnpm",["install"],{cwd:e}),d.stop("Package update complete!"),B("Please review and test the upgraded package version."),!0},Mn=async(e,t,n,r,i)=>{let s=v(e,te),o=Ge(),a=i?.sync?s:t;o.start("Preparing template snapshot..."),i?.sync&&(await xn(e,te),await N(s)),o.message("Scanning for files...");let d=await Ce(n,r,a),c=[];if(i?.sync){o.message("Comparing with local files...");let l=await Ce(n,r,e),m=new Set(d);c=l.filter(f=>!m.has(f))}if(o.stop(`Found ${d.length} files to update`),d.length===0&&c.length===0){w.warn("No files matched the patterns. Nothing to update."),i?.sync&&await ne(s),B("Update cancelled.");return}w.info(`Patterns: ${n.length}`),w.info(`Files to update: ${d.length}`),i?.sync&&w.info(`Files to delete: ${c.length}`),o.start("Updating files...");let u=await _n(d,c,a,e,o);i?.sync&&(o.message("Cleaning up..."),await ne(s)),o.stop("Update complete!"),Tn(u),B("Please review and test the changes carefully.")},Ue=async(e,t)=>{let n=process.cwd(),r=H(),i=e&&e.length>0?e:wn,s=e&&e.length>0?[]:yn;try{if(fn("Let's update your Geistdocs project!"),await An(n,e,t))return;w.info("Template source: bundled package snapshot"),e&&e.length>0&&w.info(`Updating specific files: ${e.join(", ")}`),t?.sync&&w.info("Sync mode enabled: will delete files removed from template"),await Mn(n,r,i,s,t)}catch(o){let a=o instanceof Error?o.message:`${o}`;try{await ne(v(n,te))}catch{}w.error(`Failed to update project: ${a}`),process.exit(1)}};A.name("geistdocs").description("CLI for Geistdocs projects").version("2.15.3-canary.633944d","-v, --version","Output the current version");A.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").addOption(new Rn("--brand <brand>","Navbar brand").choices(["vercel","labs"]).default("vercel")).option("--disable-git","Disable git initialization").action(he);A.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(Ue);A.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(ke);var Fn=A.command("search").description("Manage the external search index used by Ask AI");Fn.command("sync").description("Sync the latest static docs export to Mixedbread").option("--dir <path>","Next.js output directory",".next").option("--allow-non-production","Run outside a production Vercel build").action(Pe);await A.parseAsync(process.argv).catch(e=>{console.error(e instanceof Error?e.message:e),process.exitCode=1});
package/dist/next.d.ts CHANGED
@@ -1,6 +1,14 @@
1
1
  import { type CreateMDXOptions } from "fumadocs-mdx/next";
2
2
  import type { NextConfig } from "next";
3
- export type CreateGeistdocsOptions = CreateMDXOptions;
3
+ export type CreateGeistdocsOptions = CreateMDXOptions & {
4
+ /**
5
+ * Experimental: absolute path of a webpack loader that replaces
6
+ * `fumadocs-mdx/loader-mdx` for `.md`/`.mdx` files under Turbopack, such as
7
+ * the native loader in `@vercel/fumadocs-mdx-rs`. Defaults to the
8
+ * `GEISTDOCS_MDX_LOADER` environment variable.
9
+ */
10
+ experimentalMdxLoader?: string;
11
+ };
4
12
  /** Compose Fumadocs MDX with Geistdocs App Router discovery. */
5
13
  export declare const createGeistdocs: (options?: CreateGeistdocsOptions) => (nextConfig?: NextConfig | Promise<NextConfig>) => Promise<NextConfig>;
6
14
  //# sourceMappingURL=next.d.ts.map
@@ -1 +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"}
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,GAAG;IACtD;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAuDF,gEAAgE;AAChE,eAAO,MAAM,eAAe,GAAI,UAAS,sBAA2B,MAMhE,aAAY,UAAU,GAAG,OAAO,CAAC,UAAU,CAAM,KAChD,OAAO,CAAC,UAAU,CAoCtB,CAAC"}
package/dist/next.js CHANGED
@@ -1,6 +1,24 @@
1
1
  import { createMDX } from "fumadocs-mdx/next";
2
2
  import { APP_ROUTE_MANIFEST_DEFINE, APP_ROUTE_MANIFEST_ENV, } from "./internal/app-route-manifest.js";
3
3
  import { mergeRewriteRoutes, scanAppRouteManifest, } from "./internal/app-route-scanner.js";
4
+ const FUMADOCS_MDX_LOADER = "fumadocs-mdx/loader-mdx";
5
+ /** Point Turbopack's MDX rules at a replacement loader. */
6
+ const replaceMdxLoader = (config, loader) => {
7
+ const rules = config.turbopack?.rules;
8
+ if (!rules) {
9
+ return config;
10
+ }
11
+ const replaced = Object.fromEntries(Object.entries(rules).map(([pattern, rule]) => {
12
+ if (!(rule && typeof rule === "object" && "loaders" in rule && rule.loaders)) {
13
+ return [pattern, rule];
14
+ }
15
+ const loaders = rule.loaders.map((entry) => typeof entry === "object" && entry.loader === FUMADOCS_MDX_LOADER
16
+ ? { ...entry, loader }
17
+ : entry);
18
+ return [pattern, { ...rule, loaders }];
19
+ }));
20
+ return { ...config, turbopack: { ...config.turbopack, rules: replaced } };
21
+ };
4
22
  const hasOwn = (value, key) => value ? Object.hasOwn(value, key) : false;
5
23
  const assertManifestKeyIsAvailable = (config) => {
6
24
  if (hasOwn(config.env, APP_ROUTE_MANIFEST_ENV) ||
@@ -18,9 +36,14 @@ const flattenRewrites = (rewrites) => Array.isArray(rewrites)
18
36
  ];
19
37
  /** Compose Fumadocs MDX with Geistdocs App Router discovery. */
20
38
  export const createGeistdocs = (options = {}) => {
21
- const withMDX = createMDX(options);
39
+ const { experimentalMdxLoader, ...mdxOptions } = options;
40
+ const withMDX = createMDX(mdxOptions);
41
+ const mdxLoader = experimentalMdxLoader ?? process.env.GEISTDOCS_MDX_LOADER;
22
42
  return async (nextConfig = {}) => {
23
- const config = withMDX(await nextConfig);
43
+ const withFumadocs = withMDX(await nextConfig);
44
+ const config = mdxLoader
45
+ ? replaceMdxLoader(withFumadocs, mdxLoader)
46
+ : withFumadocs;
24
47
  const resolvedRewrites = config.rewrites
25
48
  ? await config.rewrites()
26
49
  : undefined;
@@ -3,6 +3,15 @@ import type { Pluggable } from "unified";
3
3
  import { z } from "zod";
4
4
  type FumadocsConfigInput = NonNullable<Parameters<typeof defineFumadocsConfig>[0]>;
5
5
  export interface GeistdocsSourceConfigOptions {
6
+ /**
7
+ * Code block highlighter. `highlights` tokenizes with @pierre/highlights'
8
+ * Wasm lexers, keeping Shiki's HTML output and Fumadocs' code block
9
+ * transformers. `shiki` uses Shiki's TextMate grammars, for languages
10
+ * Highlights doesn't support or custom grammars.
11
+ *
12
+ * @defaultValue "highlights"
13
+ */
14
+ highlighter?: "shiki" | "highlights";
6
15
  mdxOptions?: DefaultMDXOptions;
7
16
  plugins?: FumadocsConfigInput["plugins"];
8
17
  }
@@ -81,7 +90,7 @@ export declare const geistdocsMetaSchema: z.ZodObject<{
81
90
  * Fumadocs, which places it among its defaults; a function receives those
82
91
  * defaults and returns the final list.
83
92
  */
84
- export declare const resolveGeistdocsRehypePlugins: (consumerPlugins: DefaultMDXOptions["rehypePlugins"]) => NonNullable<DefaultMDXOptions["rehypePlugins"]>;
93
+ export declare const resolveGeistdocsRehypePlugins: (consumerPlugins: DefaultMDXOptions["rehypePlugins"], leadingPlugins?: Pluggable[]) => NonNullable<DefaultMDXOptions["rehypePlugins"]>;
85
94
  export declare const defineGeistdocsSourceConfig: (config?: GeistdocsSourceConfigOptions) => import("fumadocs-mdx/config").GlobalConfig;
86
95
  export {};
87
96
  //# sourceMappingURL=source-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"source-config.d.ts","sourceRoot":"","sources":["../src/source-config.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,iBAAiB,EACtB,YAAY,IAAI,oBAAoB,EAGrC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,KAAK,mBAAmB,GAAG,WAAW,CACpC,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAC3C,CAAC;AAEF,MAAM,WAAW,4BAA4B;IAC3C,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,OAAO,CAAC,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;CAC1C;AAQD;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,GACxC,UAAU,SAAS,EAAE,EACrB,kBAAiB,SAAS,EAAO,KAChC,SAAS,EAgBX,CAAC;AAEF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;CAsG3B,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwCrC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;iBAAa,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,GACxC,iBAAiB,iBAAiB,CAAC,eAAe,CAAC,KAClD,WAAW,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAKhD,CAAC;AAEF,eAAO,MAAM,2BAA2B,GACtC,SAAQ,4BAAiC,+CA2B1C,CAAC"}
1
+ {"version":3,"file":"source-config.d.ts","sourceRoot":"","sources":["../src/source-config.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,iBAAiB,EACtB,YAAY,IAAI,oBAAoB,EAGrC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,KAAK,mBAAmB,GAAG,WAAW,CACpC,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAC3C,CAAC;AAEF,MAAM,WAAW,4BAA4B;IAC3C;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IACrC,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,OAAO,CAAC,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;CAC1C;AAQD;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,GACxC,UAAU,SAAS,EAAE,EACrB,kBAAiB,SAAS,EAAO,KAChC,SAAS,EAgBX,CAAC;AAEF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;CAsG3B,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwCrC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;iBAAa,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,GACxC,iBAAiB,iBAAiB,CAAC,eAAe,CAAC,EACnD,iBAAgB,SAAS,EAAO,KAC/B,WAAW,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAShD,CAAC;AAEF,eAAO,MAAM,2BAA2B,GACtC,SAAQ,4BAAiC,+CAiC1C,CAAC"}
@@ -2,6 +2,7 @@ import { remarkHeading, remarkMdxMermaid, remarkSteps, remarkStructure, } from "
2
2
  import { defineConfig as defineFumadocsConfig, frontmatterSchema, metaSchema, } from "fumadocs-mdx/config";
3
3
  import lastModified from "fumadocs-mdx/plugins/last-modified";
4
4
  import { z } from "zod";
5
+ import { rehypeCodeHighlights } from "../rehype-code-highlights.js";
5
6
  import { rehypeTaskListLabels } from "../rehype-task-list-labels.js";
6
7
  import { remarkDetails } from "../remark-details.js";
7
8
  import { getLastModified } from "./internal/last-modified.js";
@@ -169,28 +170,37 @@ export const geistdocsMetaSchema = metaSchema;
169
170
  * Fumadocs, which places it among its defaults; a function receives those
170
171
  * defaults and returns the final list.
171
172
  */
172
- export const resolveGeistdocsRehypePlugins = (consumerPlugins) => {
173
+ export const resolveGeistdocsRehypePlugins = (consumerPlugins, leadingPlugins = []) => {
173
174
  if (typeof consumerPlugins === "function") {
174
- return (defaults) => [...consumerPlugins(defaults), rehypeTaskListLabels];
175
+ return (defaults) => [
176
+ ...leadingPlugins,
177
+ ...consumerPlugins(defaults),
178
+ rehypeTaskListLabels,
179
+ ];
175
180
  }
176
- return [...(consumerPlugins ?? []), rehypeTaskListLabels];
181
+ return [...leadingPlugins, ...(consumerPlugins ?? []), rehypeTaskListLabels];
177
182
  };
178
183
  export const defineGeistdocsSourceConfig = (config = {}) => {
179
184
  const existingRemarkPlugins = Array.isArray(config.mdxOptions?.remarkPlugins)
180
185
  ? config.mdxOptions.remarkPlugins
181
186
  : [];
182
187
  const existingPlugins = Array.isArray(config.plugins) ? config.plugins : [];
188
+ const { highlighter = "highlights", ...fumadocsConfig } = config;
189
+ const rehypeCodeOptions = {
190
+ ...config.mdxOptions?.rehypeCodeOptions,
191
+ themes: { light: geistShikiTheme },
192
+ defaultColor: "light",
193
+ };
194
+ // `highlights` swaps Shiki's tokenizer for @pierre/highlights; `shiki`
195
+ // keeps Fumadocs' rehypeCode.
196
+ const useHighlights = highlighter === "highlights";
183
197
  return defineFumadocsConfig({
184
- ...config,
198
+ ...fumadocsConfig,
185
199
  mdxOptions: {
186
200
  ...config.mdxOptions,
187
201
  remarkPlugins: (defaults) => resolveGeistdocsRemarkPlugins(defaults, existingRemarkPlugins),
188
- rehypePlugins: resolveGeistdocsRehypePlugins(config.mdxOptions?.rehypePlugins),
189
- rehypeCodeOptions: {
190
- ...config.mdxOptions?.rehypeCodeOptions,
191
- themes: { light: geistShikiTheme },
192
- defaultColor: "light",
193
- },
202
+ rehypePlugins: resolveGeistdocsRehypePlugins(config.mdxOptions?.rehypePlugins, useHighlights ? [[rehypeCodeHighlights, rehypeCodeOptions]] : []),
203
+ rehypeCodeOptions: useHighlights ? false : rehypeCodeOptions,
194
204
  },
195
205
  plugins: [
196
206
  lastModified({ versionControl: getLastModified }),
package/docs/agents.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Geistdocs Package Docs
2
2
 
3
- These docs are bundled with `@vercel/geistdocs` 2.15.2 so agents can understand the installed package without web access.
3
+ These docs are bundled with `@vercel/geistdocs` 2.15.3-canary.633944d 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
package/docs/llms.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  # Geistdocs Package Documentation
2
2
 
3
- These docs are bundled with `@vercel/geistdocs` 2.15.2.
3
+ These docs are bundled with `@vercel/geistdocs` 2.15.3-canary.633944d.
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
@@ -1424,6 +1424,14 @@ export const docs = defineDocs({
1424
1424
  export default defineGeistdocsSourceConfig();
1425
1425
  ```
1426
1426
 
1427
+ ### Code highlighter
1428
+
1429
+ Code blocks are tokenized by [Highlights](https://diffs.com/highlights), which uses hand-written WebAssembly lexers, and rendered with the same HTML as Shiki: Geist colors, titles, icons, tabs, and `[!code ...]` notation all work. Languages without a built-in Highlights lexer render as plain text. To use Shiki's TextMate grammars instead, for example for an unsupported language, pass `highlighter: "shiki"`:
1430
+
1431
+ ```ts title="source.config.ts"
1432
+ export default defineGeistdocsSourceConfig({ highlighter: "shiki" });
1433
+ ```
1434
+
1427
1435
  To serve docs from the site root, use `route: "/"` in `content` and `baseUrl: "/"` in `createSource`. Root-mounted docs need explicit `markdownRoutes`; Geistdocs does not infer a broad `/*path` mapping because it can capture homepages and non-docs app routes.
1428
1436
 
1429
1437
  ## Page URLs
@@ -467,5 +467,5 @@
467
467
  }
468
468
  ],
469
469
  "source": "apps/template/content/docs",
470
- "version": "2.15.2"
470
+ "version": "2.15.3-canary.633944d"
471
471
  }
@@ -285,6 +285,14 @@ export const docs = defineDocs({
285
285
  export default defineGeistdocsSourceConfig();
286
286
  ```
287
287
 
288
+ ### Code highlighter
289
+
290
+ Code blocks are tokenized by [Highlights](https://diffs.com/highlights), which uses hand-written WebAssembly lexers, and rendered with the same HTML as Shiki: Geist colors, titles, icons, tabs, and `[!code ...]` notation all work. Languages without a built-in Highlights lexer render as plain text. To use Shiki's TextMate grammars instead, for example for an unsupported language, pass `highlighter: "shiki"`:
291
+
292
+ ```ts title="source.config.ts"
293
+ export default defineGeistdocsSourceConfig({ highlighter: "shiki" });
294
+ ```
295
+
288
296
  To serve docs from the site root, use `route: "/"` in `content` and `baseUrl: "/"` in `createSource`. Root-mounted docs need explicit `markdownRoutes`; Geistdocs does not infer a broad `/*path` mapping because it can capture homepages and non-docs app routes.
289
297
 
290
298
  ## Page URLs
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2022 Titus Wormer <tituswormer@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ // CommonJS entry for Turbopack/webpack, like fumadocs-mdx's own shim.
3
+ module.exports = function loader(source) {
4
+ const callback = this.async();
5
+ import("./loader-mdx.mjs").then(
6
+ (mod) => mod.run.call(this, source, callback),
7
+ callback
8
+ );
9
+ };
@@ -0,0 +1,216 @@
1
+ // Webpack/Turbopack loader for MDX, backed by the native fumadocs-mdx-rs
2
+ // compiler. Mirrors fumadocs-mdx's `createMdxLoader`: config, collection,
3
+ // frontmatter validation, and doc plugins stay in JS (they're user code);
4
+ // parsing, transforms, highlighting, and codegen run natively. Files that
5
+ // use something the native pipeline doesn't cover go to fumadocs-mdx.
6
+ import { createRequire } from "node:module";
7
+ import path from "node:path";
8
+ import { pathToFileURL } from "node:url";
9
+
10
+ // fumadocs-mdx 14.0.4 internals (not in its public exports).
11
+ const fumadocsDist = path.dirname(
12
+ new URL(import.meta.resolve("fumadocs-mdx")).pathname
13
+ );
14
+ const internal = (chunk) =>
15
+ import(pathToFileURL(path.join(fumadocsDist, chunk)).href);
16
+ const { fumaMatter } = await internal("chunk-VWJKRQZR.js");
17
+ const { getCore } = await internal("chunk-CGGDM5F3.js");
18
+ const { createStandaloneConfigLoader } = await internal("chunk-NKIL543T.js");
19
+
20
+ const require = createRequire(import.meta.url);
21
+ const native = require(
22
+ process.env.FUMADOCS_MDX_RS_BINARY ?? "./native-binding.cjs"
23
+ );
24
+
25
+ let configLoader;
26
+ let jsLoader;
27
+ const compatibility = new Map();
28
+
29
+ // The plugin list the native pipeline implements: Geistdocs' defaults with
30
+ // Highlights (`defineGeistdocsSourceConfig()`), in fumadocs-mdx's order.
31
+ const NATIVE_REMARK = [
32
+ ["remarkGfm"],
33
+ ["remarkSteps"],
34
+ ["remarkHeading", { generateToc: false }],
35
+ ["remarkImage", { useImport: true }],
36
+ ["remarkCodeTab"],
37
+ ["remarkNpm"],
38
+ ["remarkMdxMermaid"],
39
+ ["remarkDetails"],
40
+ ["remarkStructure", { exportAs: "structuredData" }],
41
+ ];
42
+ const NATIVE_REHYPE = [
43
+ ["rehypeCodeHighlights"],
44
+ ["rehypeTaskListLabels"],
45
+ ["rehypeToc"],
46
+ ];
47
+ const NATIVE_OPTION_KEYS = new Set([
48
+ "remarkPlugins",
49
+ "rehypePlugins",
50
+ "outputFormat",
51
+ ]);
52
+
53
+ const samePlugins = (actual, expected) =>
54
+ actual.length === expected.length &&
55
+ actual.every((entry, index) => {
56
+ const [plugin, options] = Array.isArray(entry) ? entry : [entry];
57
+ const [name, expectedOptions] = expected[index];
58
+ if (plugin?.name !== name) {
59
+ return false;
60
+ }
61
+ if (name === "rehypeCodeHighlights") {
62
+ // Geistdocs forces the theme; any other option changes the output.
63
+ return Object.keys(options ?? {}).every(
64
+ (key) => key === "themes" || key === "defaultColor"
65
+ );
66
+ }
67
+ return (
68
+ JSON.stringify(options ?? {}) === JSON.stringify(expectedOptions ?? {})
69
+ );
70
+ });
71
+
72
+ /** Why a collection's MDX options need the JS pipeline, if they do. */
73
+ async function incompatibility(config, collection) {
74
+ const key = collection?.name ?? "global";
75
+ if (!compatibility.has(key)) {
76
+ const options = await config.getMDXOptions(collection, "bundler");
77
+ let reason = null;
78
+ const extraKeys = Object.keys(options).filter(
79
+ (k) => !NATIVE_OPTION_KEYS.has(k)
80
+ );
81
+ if (extraKeys.length > 0) {
82
+ reason = `MDX options: ${extraKeys.join(", ")}`;
83
+ } else if (!samePlugins(options.remarkPlugins ?? [], NATIVE_REMARK)) {
84
+ reason = "custom remark plugins";
85
+ } else if (!samePlugins(options.rehypePlugins ?? [], NATIVE_REHYPE)) {
86
+ reason = "custom rehype plugins or Shiki";
87
+ }
88
+ compatibility.set(key, reason);
89
+ }
90
+ return compatibility.get(key);
91
+ }
92
+
93
+ /** The doc collection behind a `doc` or `docs` collection. */
94
+ const docCollectionOf = (collection) => {
95
+ if (collection?.type === "doc") {
96
+ return collection;
97
+ }
98
+ if (collection?.type === "docs") {
99
+ return collection.docs;
100
+ }
101
+ };
102
+
103
+ async function fallback({ source, development, query, compiler, filePath }) {
104
+ jsLoader ??= (await internal("chunk-USWQVJWR.js")).createMdxLoader(
105
+ configLoader
106
+ );
107
+ const out = await jsLoader.load({
108
+ getSource: () => source,
109
+ development,
110
+ query,
111
+ compiler,
112
+ filePath,
113
+ });
114
+ return out.code;
115
+ }
116
+
117
+ const literal = (value) => {
118
+ if (value instanceof Date) {
119
+ return `new Date(${JSON.stringify(value.toISOString())})`;
120
+ }
121
+ if (value === undefined) {
122
+ return "undefined";
123
+ }
124
+ return JSON.stringify(value);
125
+ };
126
+
127
+ export async function load({
128
+ source,
129
+ filePath,
130
+ query,
131
+ development,
132
+ compiler,
133
+ options,
134
+ }) {
135
+ configLoader ??= createStandaloneConfigLoader({
136
+ core: getCore(options),
137
+ buildConfig: false,
138
+ mode: development ? "dev" : "production",
139
+ });
140
+ const core = configLoader.core;
141
+ const config = await configLoader.getConfig();
142
+ const matter = fumaMatter(source);
143
+ const collection = query.collection
144
+ ? config.getCollection(query.collection)
145
+ : undefined;
146
+ const docCollection = docCollectionOf(collection);
147
+ if (docCollection) {
148
+ matter.data = await core.transformFrontmatter(
149
+ { collection: docCollection, filePath, source },
150
+ matter.data
151
+ );
152
+ }
153
+ if (query.only === "frontmatter") {
154
+ return `export const frontmatter = ${JSON.stringify(matter.data)}`;
155
+ }
156
+
157
+ if (await incompatibility(config, docCollection)) {
158
+ return fallback({ source, development, query, compiler, filePath });
159
+ }
160
+
161
+ const result = native.compile(
162
+ matter.content,
163
+ JSON.stringify(matter.data ?? {}),
164
+ {
165
+ filePath,
166
+ includeProcessedMarkdown:
167
+ docCollection?.postprocess?.includeProcessedMarkdown === true,
168
+ development,
169
+ }
170
+ );
171
+ if (result.fallback) {
172
+ return fallback({ source, development, query, compiler, filePath });
173
+ }
174
+
175
+ // Doc plugins (e.g. last-modified) contribute extra exports.
176
+ let code = result.code;
177
+ if (docCollection) {
178
+ const file = await core.transformVFile(
179
+ { collection: docCollection, filePath, source },
180
+ { data: {}, path: filePath, value: source }
181
+ );
182
+ for (const { name, value } of file.data["mdx-export"] ?? []) {
183
+ code += `\nexport let ${name} = ${literal(value)};`;
184
+ }
185
+ }
186
+ return code;
187
+ }
188
+
189
+ /** Webpack loader entry. */
190
+ export default function loader(source) {
191
+ return run.call(this, source, this.async());
192
+ }
193
+
194
+ /** Loader body with an explicit callback (used by the CJS shim). */
195
+ export async function run(source, callback) {
196
+ const options = this.getOptions();
197
+ this.cacheable(true);
198
+ this.addDependency(options.absoluteCompiledConfigPath);
199
+ try {
200
+ const query = Object.fromEntries(
201
+ new URLSearchParams(this.resourceQuery.slice(1))
202
+ );
203
+ const code = await load({
204
+ source,
205
+ filePath: this.resourcePath,
206
+ query,
207
+ development: this.mode === "development",
208
+ compiler: this,
209
+ options,
210
+ });
211
+ callback(undefined, code);
212
+ } catch (error) {
213
+ error.message = `${path.relative(this.context, this.resourcePath)}: ${error.message}`;
214
+ callback(error);
215
+ }
216
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ const { existsSync } = require("node:fs");
4
+ const path = require("node:path");
5
+
6
+ const local = path.join(__dirname, "fumadocs-mdx-rs.node");
7
+ const platform = `${process.platform}-${process.arch}${process.platform === "linux" ? "-gnu" : ""}`;
8
+ const bundled = path.join(__dirname, "binaries", `${platform}.node`);
9
+
10
+ if (existsSync(local)) {
11
+ module.exports = require(local);
12
+ } else {
13
+ if (
14
+ !existsSync(bundled) ||
15
+ (process.platform === "linux" &&
16
+ !process.report.getReport().header.glibcVersionRuntime)
17
+ ) {
18
+ throw new Error(
19
+ `This Geistdocs native MDX canary has no binary for ${platform}. ` +
20
+ "Supported: macOS arm64 and Linux x64 (glibc). " +
21
+ "Remove experimentalMdxLoader to use the JS compiler."
22
+ );
23
+ }
24
+ module.exports = require(bundled);
25
+ }
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": "2.15.2",
4
+ "version": "2.15.3-canary.633944d",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -27,6 +27,8 @@
27
27
  "cli.js",
28
28
  "dist",
29
29
  "docs",
30
+ "rehype-code-highlights.d.ts",
31
+ "rehype-code-highlights.js",
30
32
  "rehype-task-list-labels.d.ts",
31
33
  "rehype-task-list-labels.js",
32
34
  "remark-details.d.ts",
@@ -37,7 +39,8 @@
37
39
  "shared-theme.css",
38
40
  "styles.css",
39
41
  "theme.css",
40
- "LICENSE"
42
+ "LICENSE",
43
+ "native-mdx"
41
44
  ],
42
45
  "exports": {
43
46
  "./changelog": {
@@ -299,7 +302,12 @@
299
302
  },
300
303
  "./styles.css": "./styles.css",
301
304
  "./theme.css": "./theme.css",
302
- "./package.json": "./package.json"
305
+ "./package.json": "./package.json",
306
+ "./native-mdx": "./native-mdx/loader-mdx.cjs"
307
+ },
308
+ "scripts": {
309
+ "build": "rm -rf dist docs template && node ./scripts/bundle-template.mjs && node ./scripts/bundle-docs.mjs && tsc -p tsconfig.runtime.json && tsup --config tsup.config.cli.ts",
310
+ "dev": "tsc -p tsconfig.runtime.json --watch --preserveWatchOutput"
303
311
  },
304
312
  "dependencies": {
305
313
  "@ai-sdk/react": "^3.0.134",
@@ -307,6 +315,8 @@
307
315
  "@modelcontextprotocol/server": "^2.0.0",
308
316
  "@next/env": "16.3.3",
309
317
  "@orama/tokenizers": "^3.1.16",
318
+ "@pierre/highlights": "0.5.1",
319
+ "@shikijs/rehype": "3.19.0",
310
320
  "@streamdown/cjk": "^1.0.1",
311
321
  "@types/mdx": "^2.0.13",
312
322
  "@types/react": "^19.2.7",
@@ -335,6 +345,7 @@
335
345
  "remark-mdx": "^3.1.1",
336
346
  "remark-parse": "^11.0.0",
337
347
  "remark-stringify": "^11.0.0",
348
+ "shiki": "3.19.0",
338
349
  "sonner": "^2.0.8",
339
350
  "streamdown": "^2.1.0",
340
351
  "tailwind-merge": "^3.4.0",
@@ -364,9 +375,5 @@
364
375
  "react-dom": "^19.2.3",
365
376
  "tsup": "^8.5.1",
366
377
  "typescript": "^5.9.3"
367
- },
368
- "scripts": {
369
- "build": "rm -rf dist docs template && node ./scripts/bundle-template.mjs && node ./scripts/bundle-docs.mjs && tsc -p tsconfig.runtime.json && tsup --config tsup.config.cli.ts",
370
- "dev": "tsc -p tsconfig.runtime.json --watch --preserveWatchOutput"
371
378
  }
372
- }
379
+ }
@@ -0,0 +1,13 @@
1
+ import type { RehypeCodeOptions } from "fumadocs-core/mdx-plugins";
2
+ import type { Root } from "hast";
3
+
4
+ /** Zed-format Geist theme for @pierre/highlights, using Geist's Shiki CSS variables. */
5
+ export declare const geistHighlightsTheme: Record<string, unknown>;
6
+
7
+ /**
8
+ * Experimental drop-in for Fumadocs' `rehypeCode` that tokenizes with
9
+ * @pierre/highlights while keeping Shiki's HAST output and transformers.
10
+ */
11
+ export declare const rehypeCodeHighlights: (
12
+ options?: Partial<RehypeCodeOptions>
13
+ ) => (tree: Root, file: unknown) => Promise<void>;
@@ -0,0 +1,230 @@
1
+ import { codeToTokens, isSupportedLanguage } from "@pierre/highlights";
2
+ import rehypeShikiFromHighlighter from "@shikijs/rehype/core";
3
+ import {
4
+ rehypeCodeDefaultOptions,
5
+ transformerIcon,
6
+ transformerTab,
7
+ } from "fumadocs-core/mdx-plugins";
8
+ import { tokensToHast, transformerDecorations } from "shiki/core";
9
+
10
+ // Experimental: highlights code blocks with @pierre/highlights (hand-written
11
+ // Wasm lexers) instead of Shiki's TextMate grammars, while keeping Shiki's
12
+ // HAST output and transformer pipeline so Fumadocs' code block features
13
+ // (titles, icons, tabs, line notation, diffs, focus) keep working.
14
+
15
+ const v = (name) => `token-${name}`;
16
+
17
+ // Maps Highlights' Zed token names onto the same CSS variables the Geist
18
+ // Shiki theme uses (see `geistShikiTheme`), so the existing palette applies.
19
+ // With a `cssVariables` palette, colors are variable suffixes: `token-keyword`
20
+ // renders as `var(--shiki-token-keyword)`.
21
+ export const geistHighlightsTheme = {
22
+ name: "geist",
23
+ appearance: "light",
24
+ cssVariables: {
25
+ prefix: "--shiki-",
26
+ defaults: { "color-text": "inherit", "color-background": "transparent" },
27
+ },
28
+ style: {
29
+ "editor.foreground": "color-text",
30
+ "editor.background": "color-background",
31
+ syntax: {
32
+ comment: v("comment"),
33
+ "comment.doc": v("comment"),
34
+ "keyword.jsdoc": v("comment"),
35
+ "type.jsdoc": v("comment"),
36
+ "variable.jsdoc": v("comment"),
37
+ constant: v("constant"),
38
+ "constant.builtin": v("constant"),
39
+ boolean: v("constant"),
40
+ number: v("constant"),
41
+ enum: v("constant"),
42
+ "variable.special": v("constant"),
43
+ function: v("function"),
44
+ "function.definition": v("function"),
45
+ "function.method": v("function"),
46
+ constructor: v("function"),
47
+ type: v("function"),
48
+ "type.class": v("function"),
49
+ tag: v("function"),
50
+ "tag.jsx": v("function"),
51
+ "tag.component.jsx": v("function"),
52
+ "tag.doctype": v("function"),
53
+ title: v("function"),
54
+ namespace: v("function"),
55
+ selector: v("function"),
56
+ "selector.class": v("function"),
57
+ "selector.id": v("function"),
58
+ "selector.pseudo": v("function"),
59
+ attribute: v("constant"),
60
+ "attribute.jsx": v("constant"),
61
+ "variable.parameter": v("parameter"),
62
+ property: v("parameter"),
63
+ "property.json_key": v("parameter"),
64
+ label: v("parameter"),
65
+ "text.jsx": v("parameter"),
66
+ "punctuation.list_marker": v("parameter"),
67
+ keyword: v("keyword"),
68
+ "keyword.control": v("keyword"),
69
+ "keyword.declaration": v("keyword"),
70
+ "keyword.import": v("keyword"),
71
+ "keyword.operator": v("keyword"),
72
+ operator: v("keyword"),
73
+ preproc: v("keyword"),
74
+ string: v("string"),
75
+ "string.escape": v("string"),
76
+ "string.special": v("string"),
77
+ "string.special.symbol": v("string"),
78
+ "text.literal": v("string"),
79
+ "string.regex": v("string-expression"),
80
+ punctuation: v("punctuation"),
81
+ "punctuation.bracket": v("punctuation"),
82
+ "punctuation.delimiter": v("punctuation"),
83
+ "punctuation.special": v("keyword"),
84
+ "punctuation.markup": v("punctuation"),
85
+ "punctuation.bracket.html": v("parameter"),
86
+ "punctuation.bracket.jsx": v("parameter"),
87
+ "punctuation.delimiter.html": v("parameter"),
88
+ "punctuation.delimiter.jsx": v("parameter"),
89
+ link_uri: v("link"),
90
+ link_text: v("parameter"),
91
+ },
92
+ },
93
+ };
94
+
95
+ // Fenced-code names that Highlights doesn't know but Shiki users write.
96
+ const LANG_ALIASES = {
97
+ plaintext: "plain",
98
+ txt: "plain",
99
+ "": "plain",
100
+ };
101
+
102
+ const resolveLang = (lang) => {
103
+ const name = LANG_ALIASES[lang] ?? lang ?? "plain";
104
+ return isSupportedLanguage(name) ? name : "plain";
105
+ };
106
+
107
+ const TRAILING_NEWLINE = /\n$/;
108
+
109
+ const ENFORCE_ORDER = { pre: 0, undefined: 1, post: 2 };
110
+
111
+ const getTransformers = (options) => [
112
+ ...[...(options.transformers ?? [])].sort(
113
+ (a, b) => ENFORCE_ORDER[a.enforce] - ENFORCE_ORDER[b.enforce]
114
+ ),
115
+ transformerDecorations(),
116
+ ];
117
+
118
+ const UNSTYLED = "var(--shiki-foreground)";
119
+
120
+ const tokenize = (code, options) => {
121
+ const result = codeToTokens(code, {
122
+ lang: resolveLang(options.lang),
123
+ themes: { light: geistHighlightsTheme },
124
+ defaultColor: "light",
125
+ cssVariablePrefix: "--shiki-",
126
+ });
127
+ // Highlights colors unstyled runs with `var(--shiki-foreground)`; Shiki uses
128
+ // the theme foreground, which Geist defines as `--shiki-color-text`.
129
+ for (const line of result.tokens) {
130
+ for (const token of line) {
131
+ if (token.htmlStyle?.color === UNSTYLED) {
132
+ token.htmlStyle = { ...token.htmlStyle, color: result.fg };
133
+ }
134
+ }
135
+ }
136
+ return {
137
+ tokens: result.tokens,
138
+ fg: result.fg,
139
+ bg: result.bg,
140
+ themeName: "shiki-themes geist",
141
+ };
142
+ };
143
+
144
+ /**
145
+ * A minimal Shiki highlighter: enough of the API for `@shikijs/rehype/core`.
146
+ * Mirrors Shiki's `codeToHast` (preprocess → tokens → token transformers →
147
+ * `tokensToHast`), swapping the tokenizer for Highlights.
148
+ */
149
+ export const highlightsShikiAdapter = {
150
+ getLoadedLanguages: () => [],
151
+ loadLanguage: async () => undefined,
152
+ codeToTokens: (code, options) => tokenize(code, options),
153
+ codeToHast(code, options) {
154
+ const transformers = getTransformers(options);
155
+ const context = {
156
+ meta: {},
157
+ options,
158
+ codeToHast: (c, o) => highlightsShikiAdapter.codeToHast(c, o),
159
+ codeToTokens: (c, o) => tokenize(c, o),
160
+ };
161
+
162
+ let input = code;
163
+ for (const transformer of transformers) {
164
+ input = transformer.preprocess?.call(context, input, options) || input;
165
+ }
166
+
167
+ let { tokens, fg, bg, themeName } = tokenize(input, options);
168
+ const contextSource = {
169
+ ...context,
170
+ get source() {
171
+ return input;
172
+ },
173
+ };
174
+ for (const transformer of transformers) {
175
+ tokens = transformer.tokens?.call(contextSource, tokens) || tokens;
176
+ }
177
+
178
+ return tokensToHast(
179
+ tokens,
180
+ {
181
+ ...options,
182
+ fg,
183
+ bg,
184
+ themeName,
185
+ transformers: options.transformers,
186
+ },
187
+ contextSource
188
+ );
189
+ },
190
+ };
191
+
192
+ /** Drop-in for Fumadocs' `rehypeCode`, backed by @pierre/highlights. */
193
+ export const rehypeCodeHighlights = (userOptions = {}) => {
194
+ const options = { ...rehypeCodeDefaultOptions, ...userOptions };
195
+ const transformers = [...(options.transformers ?? [])];
196
+
197
+ // Same preprocessing as Fumadocs' rehypeCode.
198
+ transformers.unshift({
199
+ name: "rehype-code:pre-process",
200
+ preprocess(code, { meta }) {
201
+ if (meta && "__parsed_raw" in meta) {
202
+ meta.__raw = meta.__parsed_raw;
203
+ // biome-ignore lint/performance/noDelete: matches Fumadocs.
204
+ delete meta.__parsed_raw;
205
+ }
206
+ if (meta && options.filterMetaString) {
207
+ meta.__raw = options.filterMetaString(meta.__raw ?? "");
208
+ }
209
+ return code.replace(TRAILING_NEWLINE, "");
210
+ },
211
+ });
212
+ if (options.icon !== false) {
213
+ transformers.push(transformerIcon(options.icon));
214
+ }
215
+ if (options.tab !== false) {
216
+ transformers.push(transformerTab());
217
+ }
218
+
219
+ // `lazy` routes every language through `loadLanguage`, which is a no-op:
220
+ // Highlights bundles its lexers and unknown languages fall back to plain.
221
+ const transformer = rehypeShikiFromHighlighter(highlightsShikiAdapter, {
222
+ ...options,
223
+ lazy: true,
224
+ transformers,
225
+ });
226
+
227
+ return async (tree, file) => {
228
+ await transformer(tree, file, () => undefined);
229
+ };
230
+ };
package/source-config.js CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  } from "fumadocs-mdx/config";
16
16
  import lastModified from "fumadocs-mdx/plugins/last-modified";
17
17
  import { z } from "zod";
18
+ import { rehypeCodeHighlights } from "./rehype-code-highlights.js";
18
19
  import { rehypeTaskListLabels } from "./rehype-task-list-labels.js";
19
20
  import { remarkDetails } from "./remark-details.js";
20
21
 
@@ -276,11 +277,18 @@ export const resolveGeistdocsRemarkPlugins = (
276
277
  // Mirrors src/source-config.ts. Geistdocs rehype plugins run after the
277
278
  // consumer's: an array is handed to Fumadocs, which places it among its
278
279
  // defaults; a function receives those defaults and returns the final list.
279
- export const resolveGeistdocsRehypePlugins = (consumerPlugins) => {
280
+ export const resolveGeistdocsRehypePlugins = (
281
+ consumerPlugins,
282
+ leadingPlugins = []
283
+ ) => {
280
284
  if (typeof consumerPlugins === "function") {
281
- return (defaults) => [...consumerPlugins(defaults), rehypeTaskListLabels];
285
+ return (defaults) => [
286
+ ...leadingPlugins,
287
+ ...consumerPlugins(defaults),
288
+ rehypeTaskListLabels,
289
+ ];
282
290
  }
283
- return [...(consumerPlugins ?? []), rehypeTaskListLabels];
291
+ return [...leadingPlugins, ...(consumerPlugins ?? []), rehypeTaskListLabels];
284
292
  };
285
293
 
286
294
  export const defineGeistdocsSourceConfig = (config = {}) => {
@@ -288,21 +296,27 @@ export const defineGeistdocsSourceConfig = (config = {}) => {
288
296
  ? config.mdxOptions.remarkPlugins
289
297
  : [];
290
298
  const existingPlugins = Array.isArray(config.plugins) ? config.plugins : [];
299
+ const { highlighter = "highlights", ...fumadocsConfig } = config;
300
+ const rehypeCodeOptions = {
301
+ ...config.mdxOptions?.rehypeCodeOptions,
302
+ themes: { light: geistShikiTheme },
303
+ defaultColor: "light",
304
+ };
305
+ // `highlights` swaps Shiki's tokenizer for @pierre/highlights; `shiki`
306
+ // keeps Fumadocs' rehypeCode.
307
+ const useHighlights = highlighter === "highlights";
291
308
 
292
309
  return defineFumadocsConfig({
293
- ...config,
310
+ ...fumadocsConfig,
294
311
  mdxOptions: {
295
312
  ...config.mdxOptions,
296
313
  remarkPlugins: (defaults) =>
297
314
  resolveGeistdocsRemarkPlugins(defaults, existingRemarkPlugins),
298
315
  rehypePlugins: resolveGeistdocsRehypePlugins(
299
- config.mdxOptions?.rehypePlugins
316
+ config.mdxOptions?.rehypePlugins,
317
+ useHighlights ? [[rehypeCodeHighlights, rehypeCodeOptions]] : []
300
318
  ),
301
- rehypeCodeOptions: {
302
- ...config.mdxOptions?.rehypeCodeOptions,
303
- themes: { light: geistShikiTheme },
304
- defaultColor: "light",
305
- },
319
+ rehypeCodeOptions: useHighlights ? false : rehypeCodeOptions,
306
320
  },
307
321
  plugins: [
308
322
  lastModified({ versionControl: getLastModified }),
@@ -1,4 +1,4 @@
1
- import { ImageResponse } from "next/og";
1
+ import { createOpenGraphImage } from "@/lib/geistdocs/og";
2
2
 
3
3
  export const alt = "Geistdocs documentation platform";
4
4
  export const contentType = "image/png";
@@ -8,33 +8,9 @@ export const size = {
8
8
  };
9
9
 
10
10
  const OpenGraphImage = () =>
11
- new ImageResponse(
12
- <div
13
- style={{
14
- alignItems: "center",
15
- background: "#000",
16
- color: "#fff",
17
- display: "flex",
18
- height: "100%",
19
- justifyContent: "center",
20
- width: "100%",
21
- }}
22
- >
23
- <div
24
- style={{
25
- display: "flex",
26
- flexDirection: "column",
27
- gap: 24,
28
- maxWidth: 920,
29
- }}
30
- >
31
- <div style={{ fontSize: 76, fontWeight: 600 }}>Geistdocs</div>
32
- <div style={{ color: "#a1a1a1", fontSize: 36, lineHeight: 1.25 }}>
33
- Package-backed documentation sites for people and agents
34
- </div>
35
- </div>
36
- </div>,
37
- size
11
+ createOpenGraphImage(
12
+ "Geistdocs",
13
+ "Package-backed documentation sites for people and agents"
38
14
  );
39
15
 
40
16
  export default OpenGraphImage;
@@ -1,7 +1,6 @@
1
- import { readFile } from "node:fs/promises";
2
- import { join } from "node:path";
3
- import { ImageResponse } from "next/og";
4
1
  import type { NextRequest } from "next/server";
2
+ import { config } from "@/lib/geistdocs/config";
3
+ import { createOpenGraphImage } from "@/lib/geistdocs/og";
5
4
  import { getPageImage, source } from "@/lib/geistdocs/source";
6
5
 
7
6
  export const GET = async (
@@ -15,71 +14,9 @@ export const GET = async (
15
14
  return new Response("Not found", { status: 404 });
16
15
  }
17
16
 
18
- const { title, description } = page.data;
19
-
20
- const regularFont = await readFile(
21
- join(process.cwd(), "app/[lang]/og/[...slug]/geist-sans-regular.ttf")
22
- );
23
-
24
- const semiboldFont = await readFile(
25
- join(process.cwd(), "app/[lang]/og/[...slug]/geist-sans-semibold.ttf")
26
- );
27
-
28
- const backgroundImage = await readFile(
29
- join(process.cwd(), "app/[lang]/og/[...slug]/background.png")
30
- );
31
-
32
- const backgroundImageData = backgroundImage.buffer.slice(
33
- backgroundImage.byteOffset,
34
- backgroundImage.byteOffset + backgroundImage.byteLength
35
- );
36
-
37
- return new ImageResponse(
38
- <div style={{ fontFamily: "Geist" }} tw="flex h-full w-full bg-black">
39
- {/** biome-ignore lint/performance/noImgElement: "Required for Satori" */}
40
- <img
41
- alt="Vercel OpenGraph Background"
42
- height={628}
43
- src={backgroundImageData as never}
44
- width={1200}
45
- />
46
- <div tw="flex flex-col absolute h-full w-[750px] justify-center left-[50px] pr-[50px] pt-[116px] pb-[86px]">
47
- <div
48
- style={{
49
- textWrap: "balance",
50
- }}
51
- tw="text-5xl font-medium text-white tracking-tight flex leading-[1.1] mb-4"
52
- >
53
- {title}
54
- </div>
55
- <div
56
- style={{
57
- color: "#8B8B8B",
58
- lineHeight: "44px",
59
- textWrap: "balance",
60
- }}
61
- tw="text-[32px]"
62
- >
63
- {description}
64
- </div>
65
- </div>
66
- </div>,
67
- {
68
- width: 1200,
69
- height: 628,
70
- fonts: [
71
- {
72
- name: "Geist",
73
- data: regularFont,
74
- weight: 400,
75
- },
76
- {
77
- name: "Geist",
78
- data: semiboldFont,
79
- weight: 500,
80
- },
81
- ],
82
- }
17
+ return createOpenGraphImage(
18
+ page.data.title ?? config.title,
19
+ page.data.description
83
20
  );
84
21
  };
85
22
 
@@ -283,6 +283,14 @@ export const docs = defineDocs({
283
283
  export default defineGeistdocsSourceConfig();
284
284
  ```
285
285
 
286
+ ### Code highlighter
287
+
288
+ Code blocks are tokenized by [Highlights](https://diffs.com/highlights), which uses hand-written WebAssembly lexers, and rendered with the same HTML as Shiki: Geist colors, titles, icons, tabs, and `[!code ...]` notation all work. Languages without a built-in Highlights lexer render as plain text. To use Shiki's TextMate grammars instead, for example for an unsupported language, pass `highlighter: "shiki"`:
289
+
290
+ ```ts title="source.config.ts"
291
+ export default defineGeistdocsSourceConfig({ highlighter: "shiki" });
292
+ ```
293
+
286
294
  To serve docs from the site root, use `route: "/"` in `content` and `baseUrl: "/"` in `createSource`. Root-mounted docs need explicit `markdownRoutes`; Geistdocs does not infer a broad `/*path` mapping because it can capture homepages and non-docs app routes.
287
295
 
288
296
  ## Page URLs
@@ -0,0 +1,95 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { LogoIconVercelSvg } from "@vercel/geistdocs/assets/logos";
4
+ import { ImageResponse } from "next/og";
5
+ import { renderToReadableStream } from "react-dom/server.edge";
6
+
7
+ const regularFont = readFile(
8
+ join(process.cwd(), "lib/geistdocs/geist-sans-regular.ttf")
9
+ );
10
+ const monoFont = readFile(
11
+ join(process.cwd(), "lib/geistdocs/geist-mono-regular.ttf")
12
+ );
13
+
14
+ export const createOpenGraphImage = async (
15
+ title: string,
16
+ subheading?: string
17
+ ) => {
18
+ // Satori cannot resolve the memoized base component used by Geist icons.
19
+ const logo = await new Response(
20
+ await renderToReadableStream(<LogoIconVercelSvg size={60} />)
21
+ ).text();
22
+
23
+ return new ImageResponse(
24
+ <div
25
+ style={{
26
+ backgroundColor: "#000",
27
+ color: "#fff",
28
+ display: "flex",
29
+ fontFamily: "Geist",
30
+ height: "100%",
31
+ width: "100%",
32
+ }}
33
+ >
34
+ <div style={{ display: "flex", left: 64, position: "absolute", top: 56 }}>
35
+ {/** biome-ignore lint/performance/noImgElement: Required for Satori. */}
36
+ <img
37
+ alt="Vercel"
38
+ height={60}
39
+ src={`data:image/svg+xml;base64,${Buffer.from(logo.replaceAll("currentColor", "#fff")).toString("base64")}`}
40
+ width={60}
41
+ />
42
+ </div>
43
+ <div
44
+ style={{
45
+ display: "flex",
46
+ flexDirection: "column",
47
+ gap: 24,
48
+ left: 64,
49
+ position: "absolute",
50
+ top: 220,
51
+ width: 810,
52
+ }}
53
+ >
54
+ <div
55
+ style={{
56
+ display: "block",
57
+ fontSize: 80,
58
+ fontWeight: 400,
59
+ letterSpacing: "-0.05em",
60
+ ...(subheading ? { lineClamp: 3 } : {}),
61
+ lineHeight: 0.95,
62
+ textWrap: subheading ? "wrap" : "balance",
63
+ width: "100%",
64
+ }}
65
+ >
66
+ {title}
67
+ </div>
68
+ {subheading ? (
69
+ <div
70
+ style={{
71
+ color: "#a1a1a1",
72
+ display: "block",
73
+ fontFamily: "Geist Mono",
74
+ fontSize: 32,
75
+ lineClamp: 2,
76
+ lineHeight: 1.25,
77
+ textWrap: "wrap",
78
+ width: "100%",
79
+ }}
80
+ >
81
+ {subheading}
82
+ </div>
83
+ ) : null}
84
+ </div>
85
+ </div>,
86
+ {
87
+ width: 1200,
88
+ height: 630,
89
+ fonts: [
90
+ { name: "Geist", data: await regularFont, weight: 400 },
91
+ { name: "Geist Mono", data: await monoFont, weight: 400 },
92
+ ],
93
+ }
94
+ );
95
+ };
@@ -17,7 +17,7 @@
17
17
  "@streamdown/code": "^1.0.1",
18
18
  "@vercel/agent-readability": "^0.7.0",
19
19
  "@vercel/analytics": "^1.6.1",
20
- "@vercel/geistdocs": "2.15.2",
20
+ "@vercel/geistdocs": "2.15.3-canary.633944d",
21
21
  "@vercel/speed-insights": "^1.3.1",
22
22
  "ai": "^6.0.132",
23
23
  "clsx": "^2.1.1",