import f from"path";import{combineUrls as p}from"@redocly/theme/core/utils";import{VERSION_SEPARATOR as S}from"../../../constants/common.js";import{removeTrailingSlash as d}from"../../../../utils/url/remove-trailing-slash.js";import{slash as b}from"../../../../utils/path/slash.js";import{logger as c}from"../../../tools/notifiers/logger.js";import{getDefaultVersionByPath as v}from"./versions-config-loader.js";import{GithubSlugger as D,slug as E}from"../../../utils/index.js";import{parseBaseName as F}from"../../utils.js";const I=new Set([".jpg",".jpeg",".png",".gif",".webp",".svg",".ico",".avif",".mp3",".wav",".ogg",".m4a",".mp4",".avi",".mov",".webm",".pdf",".doc",".docx",".zip",".rar",".gz",".ttf",".woff",".woff2"]),A=async(i,{fs:e,cache:s})=>{const g=c.startTiming(),o=(await s.load("versions-config","versions-config")).data,t=new Map,n=new Map,r=new Set,l=new D;n.set(".","/"),n.set("/","/");const u=e.scan().sort((a,m)=>m.relativePath.localeCompare(a.relativePath));for(const{relativePath:a}of u){if(I.has(f.posix.extname(a)))continue;const{data:m}=await s.load(a,"is-ignored");if(m)continue;const h=b(a).replace(new RegExp("^(@i18n|@l10n)\\/"),""),w=v(a,o);N(h,{defaultVersion:w,fileSlugs:t,dirSlugs:n,allFileSlugsList:r,githubSlugger:l})}return c.verboseTime(g,"Calculated slugs. Number of file paths processed: "+u.length),{fileSlugs:t,dirSlugs:n}};function N(i,e){const s=e.fileSlugs.get(i);if(s)return s;let g=f.posix.dirname(i);const o=z(g,e)||"",{baseName:t,isIndexFile:n}=F(i),r=e.dirSlugs.has(f.posix.join(g,t));let l;if(!n&&r){const u=E(p(o,t));e.allFileSlugsList.has(u)||(l=u)}l||(l=n&&e.dirSlugs.get(g)||e.githubSlugger.slug(p(o,t))),l=d(l),e.fileSlugs.set(i,l),e.allFileSlugsList.add(l)}function z(i,e){if(e.dirSlugs.has(i))return e.dirSlugs.get(i);const s=d(f.posix.normalize(i)).split("/");let g="/",o="";for(const t of s){o=f.posix.join(o,t);const n=T(t,e.defaultVersion);let r=e.dirSlugs.get(o)||e.githubSlugger.slug(p("/",g,n));r.endsWith("/")||(r=r+"/"),e.dirSlugs.set(o,r),g=r}return e.dirSlugs.get(i)}function T(i,e){if(!i.startsWith(S))return i;const s=i.substring(S.length);return s===e?"":s}export{I as IGNORED_EXTS,A as contentSlugsLoader};
