import y from"path";import{REDOCLY_ROUTE_RBAC as a,REDOCLY_TEAMS_RBAC as b}from"@redocly/config";import{deepMerge as h}from"../../../utils/object/deep-merge.js";import{buildWildcardRedirectsTree as R}from"../../utils/redirects/build-wildcard-redirects-tree.js";import{formatCustomScripts as m,formatCustomLinks as C}from"./format-custom-tags.js";import{applyL10nToRbacConfig as S,resolveDirectoryHashes as D}from"../../utils/rbac.js";import{copySeoAssets as P}from"./copy-seo-assets.js";import{normalizeRedirectSources as T}from"./normalize-redirect-sources.js";import{applyL10nToRedirects as v}from"./apply-l10n-to-redirects.js";import{DEFAULT_LOADERS as A}from"./loaders/index.js";import{resolveSearchFacets as L}from"./resolve-search-facets.js";import{telemetryTraceStep as O}from"../../../cli/telemetry/helpers/trace-step.js";async function U(){return{id:"Config Parser",loaders:A,async processContent(t,{getConfig:n,fs:i}){await O("build.plugin.config_parser",async o=>{const{contentDir:e,setGlobalConfig:s,setGlobalData:f}=t,r=await n(),c={outdir:t.outdir,contentDir:e},p=m(r.scripts?.head,c),g=C(r.links,c),u=m(r.scripts?.body,c),d=h(r,{headScriptTags:p,linkTags:g,postBodyScriptTags:u});o?.setAttribute("config",JSON.stringify(d));const l=r.redirects?T(r.redirects):{};s({...d,requiresLogin:!!r.requiresLogin,rbac:S(i,r.rbac||{}),directoryPaths:await D(i,r.rbac),seo:r.seo&&P(r.seo,c.contentDir,c.outdir),redirects:v(l,r.l10n),wildcardRedirectsTree:R(l)}),L(r.search?.filters?.facets||[],t.getSearchFacets,t.setSearchFacets),f({removeAttribution:!!r.removeAttribution})})},async afterRoutesCreated(t){const n=t.getGlobalConfig("rbac"),i=t.getGlobalConfig("directoryPaths");if(!(!n||Object.keys(n).length===0))for(const o of t.getAllRoutes()){if(o.versions&&i)for(const e of o.versions){const s=i[e.folderId],r=s==="."||s==="/"?"":s;e[a]={slug:e.link,fsPath:y.posix.join(r,"@"+e.version,"index.md")}}o[a]||o[b]||(o[a]={slug:o.slug,fsPath:o.fsPath})}}}}export{U as configParserPlugin};
