import p from"path";import{REDOCLY_ROUTE_RBAC as a,REDOCLY_TEAMS_RBAC as u}from"@redocly/config";import{deepMerge as h}from"../../../shared/jsUtils.js";import{formatCustomScripts as f,formatCustomLinks as y}from"./format-custom-tags.js";import{applyL10nToRbacConfig as C,resolveDirectoryHashes as b}from"../../utils/rbac.js";import{copySeoAssets as R}from"./copy-seo-assets.js";import{normalizeRedirectSources as D}from"./normalize-redirect-sources.js";import{DEFAULT_LOADERS as P}from"./loaders/index.js";import{resolveSearchFacets as v}from"./resolve-search-facets.js";async function G(){return{id:"Config Parser",loaders:P,async processContent(t,{getConfig:n,fs:i}){const{contentDir:r,setGlobalConfig:s,setGlobalData:c}=t,o=await n(),e={outdir:t.outdir,contentDir:r},m=f(o.scripts?.head,e),l=y(o.links,e),g=f(o.scripts?.body,e),d=h(o,{headScriptTags:m,linkTags:l,postBodyScriptTags:g});s({...d,requiresLogin:!!o.requiresLogin,rbac:C(i,o.rbac||{}),directoryPaths:await b(i,o.rbac),seo:o.seo&&R(o.seo,e.contentDir,e.outdir),redirects:o.redirects&&D(o.redirects)}),v(o.search?.filters?.facets||[],t.getSearchFacets,t.setSearchFacets),c({removeAttribution:!!o.removeAttribution})},async afterRoutesCreated(t){const n=t.getGlobalConfig("rbac"),i=t.getGlobalConfig("directoryPaths");if(!(!n||Object.keys(n).length===0))for(const r of t.getAllRoutes()){if(r.versions&&i)for(const s of r.versions){const c=i[s.folderId],e=c==="."||c==="/"?"":c;s[a]={slug:s.link,fsPath:p.posix.join(e,"@"+s.version,"index.md")}}r[a]||r[u]||(r[a]={slug:r.slug,fsPath:r.fsPath})}}}}export{G as configParserPlugin};
