import g from"node:path";import{REDOCLY_TEAMS_RBAC as h}from"@redocly/config";import{slash as w}from"../../../utils/path/slash.js";import{staticDataLoader as y}from"./page-data-loaders/static-data-loader.js";import{findFrontmatterSlugs as P,getSidebarSharedDataId as S,resolveFrontmatterSlugs as b}from"../utils.js";import{reactFrontmatterLoader as v}from"./react-frontmatter-loader.js";import{registerPageProps as D}from"../register-page-props.js";import{telemetryTraceStep as R}from"../../../cli/telemetry/helpers/trace-step.js";async function A(){return{loaders:{"react-frontmatter":v},id:"react-pages",requiredEntitlements:["reactPages"],processContent:async(a,r)=>{await R("build.plugin.pages",async()=>{const{fs:o,cache:f}=r;for(const c of await o.scan(/\.page\.tsx?$/)){const{relativePath:t,realRelativePath:l}=c;if(await r.isPathIgnored(t))continue;const p=a.createTemplate(w(t),g.resolve(o.cwd,l));await D(c,o,a);const{data:e}=await f.load(t,"react-frontmatter"),u=await P(t,"react-frontmatter",e,r),s=b(u,t);let i=null;e?.sidebar&&(i=await S(e.sidebar,t,r.fs)),(s.length?s.reverse():[void 0]).forEach(n=>{a.addRoute({slug:n,templateId:p,fsPath:t,sharedData:i?[{id:i,key:"sidebar"}]:void 0,[h]:e?.rbac,getNavText:async()=>e?.seo?.title,getStaticData:async(m,d)=>({props:await y({frontmatter:e,relativePath:t},r,d)})})});for(const[n,{to:m,type:d}]of Object.entries(e?.redirects||{}))a.addRedirect(n,{to:m||s[0],type:d||301})}})}}}export{A as customPagesPlugin};
