2023-09-26 14:27:38 +08:00
|
|
|
export function pathsEqual(path1: string, path2: string) {
|
2024-01-21 12:54:41 +08:00
|
|
|
const normalizedPath1 = path1.replace(/^\/|\/$/g, '').toLowerCase()
|
|
|
|
|
const normalizedPath2 = path2.replace(/^\/|\/$/g, '').toLowerCase()
|
|
|
|
|
return normalizedPath1 === normalizedPath2
|
2023-09-26 14:27:38 +08:00
|
|
|
}
|
2023-10-11 22:29:23 +08:00
|
|
|
|
2023-11-03 14:10:54 +08:00
|
|
|
function joinUrl(...parts: string[]): string {
|
2024-01-21 12:54:41 +08:00
|
|
|
const joined = parts.join('/')
|
|
|
|
|
return joined.replace(/([^:]\/)\/+/g, '$1')
|
2023-11-03 14:10:54 +08:00
|
|
|
}
|
|
|
|
|
|
2023-10-11 22:29:23 +08:00
|
|
|
export function getPostUrlBySlug(slug: string): string | null {
|
2024-01-21 12:54:41 +08:00
|
|
|
if (!slug) return null
|
|
|
|
|
return `/posts/${slug}`
|
2023-10-11 22:29:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getCategoryUrl(category: string): string | null {
|
2024-01-21 12:54:41 +08:00
|
|
|
if (!category) return null
|
|
|
|
|
return `/archive/category/${category}`
|
2023-10-11 22:29:23 +08:00
|
|
|
}
|
2023-12-28 14:37:18 +08:00
|
|
|
|
|
|
|
|
export function getDir(path: string): string {
|
|
|
|
|
const lastSlashIndex = path.lastIndexOf('/')
|
|
|
|
|
if (lastSlashIndex < 0) {
|
|
|
|
|
return '/'
|
|
|
|
|
}
|
|
|
|
|
return path.substring(0, lastSlashIndex + 1)
|
|
|
|
|
}
|