import g from"node:path";import{REDOCLY_TEAMS_RBAC as h}from"@redocly/config";import{staticDataLoader as P}from"./page-data-loaders/static-data-loader.js";import{findFrontmatterSlugs as w,getSidebarSharedDataId as S,resolveFrontmatterSlugs as b}from"../utils.js";import{slash as y}from"../../../shared/utils.js";import{reactFrontmatterLoader as v}from"./react-frontmatter-loader.js";import{registerPageProps as D}from"../register-page-props.js";async function _(){return{loaders:{"react-frontmatter":v},id:"react-pages",requiredEntitlements:["reactPages"],processContent:async(a,r)=>{const{fs:o,cache:m}=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(y(t),g.resolve(o.cwd,l));await D(c,o,a);const{data:e}=await m.load(t,"react-frontmatter"),u=await w(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(f,d)=>({props:await P({frontmatter:e,relativePath:t},r,d)})})});for(const[n,{to:f,type:d}]of Object.entries(e?.redirects||{}))a.addRedirect(n,{to:f||s[0],type:d||301})}}}}export{_ as customPagesPlugin};
