UNPKG

vitepress-plugin-llms

Version:

📜 A VitePress plugin for generating LLM-friendly documentation

31 lines (29 loc) • 1.14 kB
// Built with bunup (https://bunup.dev) // src/utils/shared/index.ts function cleanUrl(path) { let cleanedPath = path.split("?")[0].split("#")[0]; if (cleanedPath.length > 1 && cleanedPath.endsWith("/")) { cleanedPath = cleanedPath.slice(0, -1); } const removeHtmlExtension = (pathSegment) => { const lastSlashIndex = pathSegment.lastIndexOf("/"); const lastDotIndex = pathSegment.lastIndexOf("."); if (lastDotIndex > lastSlashIndex && lastDotIndex !== -1 && pathSegment.endsWith(".html")) { return pathSegment.substring(0, lastDotIndex); } return pathSegment; }; const protocolMatch = cleanedPath.match(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//); if (protocolMatch) { const protocolEndIndex = protocolMatch[0].length; const pathStartIndex = cleanedPath.indexOf("/", protocolEndIndex); if (pathStartIndex === -1) { return cleanedPath; } const domainPart = cleanedPath.substring(0, pathStartIndex); const pathPart = cleanedPath.substring(pathStartIndex); return domainPart + removeHtmlExtension(pathPart); } return removeHtmlExtension(cleanedPath); } export { cleanUrl };