also looking at this
fix: preserve deployment paths in local search results
#91
5 files
+81
-23
| @@ -29,7 +29,9 @@ import { clearTemplateCache, render } from './template-loader' | ||
| 29 | 29 | import { messagePreviewCSS, renderMessagePreview } from './message-previews' |
| 30 | 30 | import { getThemeCSS } from './themes' |
| 31 | 31 | import { buildTocHierarchy, defaultTocConfig, extractHeadings, filterHeadings, generateInlineTocHtml, generateSlug, markdownHeadingText, reserveUniqueSlug } from './toc' |
| 32 | import { siteUrl } from './site-url' | |
| 32 | import { getConfiguredBasePath, siteUrl } from './site-url' | |
| 33 | ||
| 34 | export { getConfiguredBasePath } from './site-url' | |
| 33 | 35 | import { decodeHtmlEntities, escapeHtmlAttribute } from './html-entities' |
| 34 | 36 | |
| 35 | 37 | export { decodeHtmlEntities } from './html-entities' |
| @@ -901,28 +903,6 @@ function generateNavScreen(config: BunPressConfig, currentPath: string = ''): st | ||
| 901 | 903 | </div>` |
| 902 | 904 | } |
| 903 | 905 | |
| 904 | export function getConfiguredBasePath(config: BunPressConfig): string { | |
| 905 | if (config.basePath) { | |
| 906 | const normalized = config.basePath.trim().replace(/\/+$/, '') | |
| 907 | if (!normalized || normalized === '/') | |
| 908 | return '' | |
| 909 | return normalized.startsWith('/') ? normalized : `/${normalized}` | |
| 910 | } | |
| 911 | ||
| 912 | const baseUrl = siteUrl(config) | |
| 913 | if (!baseUrl) { | |
| 914 | return '' | |
| 915 | } | |
| 916 | ||
| 917 | try { | |
| 918 | const pathname = new URL(baseUrl).pathname.replace(/\/+$/, '') | |
| 919 | return pathname === '/' ? '' : pathname | |
| 920 | } | |
| 921 | catch { | |
| 922 | return '' | |
| 923 | } | |
| 924 | } | |
| 925 | ||
| 926 | 906 | export function stripConfiguredBasePath(config: BunPressConfig, pathname: string): string { |
| 927 | 907 | const basePath = getConfiguredBasePath(config) |
| 928 | 908 | if (!basePath) |