also looking at this
fix: preserve deployment paths in local search results
#91
5 files
+81
-23
| @@ -17,3 +17,26 @@ import type { BunPressConfig } from './types' | ||
| 17 | 17 | export function siteUrl(config: BunPressConfig): string { |
| 18 | 18 | return (config.sitemap?.baseUrl || config.url || '').replace(/\/$/, '') |
| 19 | 19 | } |
| 20 | ||
| 21 | /** Shared deployment prefix for rendered pages and generated navigation data. */ | |
| 22 | export function getConfiguredBasePath(config: BunPressConfig): string { | |
| 23 | if (config.basePath) { | |
| 24 | const normalized = config.basePath.trim().replace(/\/+$/, '') | |
| 25 | if (!normalized || normalized === '/') | |
| 26 | return '' | |
| 27 | return normalized.startsWith('/') ? normalized : `/${normalized}` | |
| 28 | } | |
| 29 | ||
| 30 | const baseUrl = siteUrl(config) | |
| 31 | if (!baseUrl) { | |
| 32 | return '' | |
| 33 | } | |
| 34 | ||
| 35 | try { | |
| 36 | const pathname = new URL(baseUrl).pathname.replace(/\/+$/, '') | |
| 37 | return pathname === '/' ? '' : pathname | |
| 38 | } | |
| 39 | catch { | |
| 40 | return '' | |
| 41 | } | |
| 42 | } | |