18 lines
458 B
TypeScript
18 lines
458 B
TypeScript
export function normalizeSiteBase(value = '/') {
|
|
const trimmed = value.trim()
|
|
if (!trimmed || trimmed === '/')
|
|
return '/'
|
|
|
|
return `/${trimmed.replace(/^\/+|\/+$/g, '')}/`
|
|
}
|
|
|
|
export function joinBase(base: string, ...parts: string[]) {
|
|
const normalized = normalizeSiteBase(base)
|
|
const suffix = parts
|
|
.map(part => part.replace(/^\/+|\/+$/g, ''))
|
|
.filter(Boolean)
|
|
.join('/')
|
|
|
|
return suffix ? `${normalized}${suffix}/` : normalized
|
|
}
|