29 lines
893 B
TypeScript
29 lines
893 B
TypeScript
import {siteConfig} from "../config.ts";
|
|
import astroConfig from "../../astro.config.mjs"
|
|
|
|
export function pathsEqual(path1: string, path2: string) {
|
|
const normalizedPath1 = path1.replace(/^\/|\/$/g, '').toLowerCase();
|
|
const normalizedPath2 = path2.replace(/^\/|\/$/g, '').toLowerCase();
|
|
return normalizedPath1 === normalizedPath2;
|
|
}
|
|
|
|
function joinUrl(...parts: string[]): string {
|
|
const joined = parts.join('/');
|
|
return joined.replace(/([^:]\/)\/+/g, '$1');
|
|
}
|
|
|
|
export function getPostUrlBySlug(slug: string): string | null {
|
|
if (!slug)
|
|
return null;
|
|
return `/posts/${slug}`;
|
|
}
|
|
|
|
export function getCategoryUrl(category: string): string | null {
|
|
if (!category)
|
|
return null;
|
|
return `/archive/category/${category}`;
|
|
}
|
|
|
|
export function getFullUrl(path: string): string {
|
|
return joinUrl(astroConfig.site || "", astroConfig.base || "", path);
|
|
} |