ReviewOS

also looking at this

stacks/bunpress

fix: preserve deployment paths in local search results

#91
Merged chris wants to merge codex/search-base-path into main
5 files +81 -23
packages/bunpress/src/site-url.tsmodified+23-0
Changes to packages/bunpress/src/site-url.ts
@@ -17,3 +17,26 @@ import type { BunPressConfig } from './types'
1717export function siteUrl(config: BunPressConfig): string {
1818 return (config.sitemap?.baseUrl || config.url || '').replace(/\/$/, '')
1919}
20
21/** Shared deployment prefix for rendered pages and generated navigation data. */
22export 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}