x
This commit is contained in:
1 parent
f7aa4d099f
commit
ab3e53c4da
33 files changed
+290
-69
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { Metadata } from 'next';
|
||||
import { SUPPORTED_LOCALES } from './locales';
|
||||
|
||||
const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000';
|
||||
|
||||
type SeoMetadataProps = {
|
||||
title: string;
|
||||
description: string;
|
||||
path: string; // e.g. '/shop', '/category/1', or ''
|
||||
lang: string;
|
||||
openGraph?: Metadata['openGraph'];
|
||||
};
|
||||
|
||||
export function generateSeoMetadata({
|
||||
title,
|
||||
description,
|
||||
path,
|
||||
lang,
|
||||
openGraph,
|
||||
}: 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}`;
|
||||
});
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
alternates: {
|
||||
canonical: `${baseUrl}/${lang}${pathPart}`,
|
||||
languages,
|
||||
},
|
||||
openGraph,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user