This commit is contained in:
Your Name committed 2026-07-01 19:32:20 -04:00
1 parent be0ee265d5
commit 10131e08bf
11 files changed
+415 -88

No files matched your search

+9 -3
View File
@@ -9,6 +9,7 @@ type SeoMetadataProps = {
path: string; // e.g. '/shop', '/category/1', or ''
lang: string;
openGraph?: Metadata['openGraph'];
customLanguages?: Record<string, string>;
};
export function generateSeoMetadata({
@@ -17,14 +18,19 @@ export function generateSeoMetadata({
path,
lang,
openGraph,
customLanguages,
}: SeoMetadataProps): Metadata {
const cleanPath = path.startsWith('/') ? path : `/${path}`;
const pathPart = cleanPath === '/' ? '' : cleanPath;
const languages: Record<string, string> = {};
SUPPORTED_LOCALES.forEach((locale) => {
languages[locale] = `${baseUrl}/${locale}${pathPart}`;
});
if (customLanguages) {
Object.assign(languages, customLanguages);
} else {
SUPPORTED_LOCALES.forEach((locale) => {
languages[locale] = `${baseUrl}/${locale}${pathPart}`;
});
}
return {
title,
+22
View File
@@ -0,0 +1,22 @@
export function generateProductSlug(name: string, id: string | number): string {
if (!name) return `p${id}`;
const cleanName = name
.toLowerCase()
.trim()
.replace(/[\s_]+/g, '-') // Replace spaces and underscores with hyphens
.replace(/[^\w\u0E00-\u0E7F-]+/g, '') // Keep alphanumeric, Thai chars, and hyphens.
.replace(/-+/g, '-') // Remove consecutive hyphens
.replace(/^-+|-+$/g, ''); // Trim hyphens from start and end
return cleanName ? `${cleanName}-p${id}` : `p${id}`;
}
export function extractIdFromSlug(slug: string): string {
if (!slug) return '';
const match = slug.match(/-p(\d+)$|^p(\d+)$/);
if (match) {
return match[1] || match[2];
}
return slug; // Fallback if no match
}