This commit is contained in:
2026-01-17 01:50:54 +01:00
parent c12b32ed5e
commit c8f61257c9
62 changed files with 1297 additions and 1028 deletions

View File

@@ -19,7 +19,14 @@ export interface ProductMdx {
export async function getProductBySlug(slug: string, locale: string): Promise<ProductMdx | null> {
const productsDir = path.join(process.cwd(), 'data', 'products', locale);
const filePath = path.join(productsDir, `${slug}.mdx`);
// Try exact slug first
let filePath = path.join(productsDir, `${slug}.mdx`);
if (!fs.existsSync(filePath)) {
// Try with -2 suffix (common in the dumped files)
filePath = path.join(productsDir, `${slug}-2.mdx`);
}
if (!fs.existsSync(filePath)) {
return null;
@@ -42,3 +49,9 @@ export async function getAllProductSlugs(locale: string): Promise<string[]> {
const files = fs.readdirSync(productsDir);
return files.filter(file => file.endsWith('.mdx')).map(file => file.replace(/\.mdx$/, ''));
}
export async function getAllProducts(locale: string): Promise<ProductMdx[]> {
const slugs = await getAllProductSlugs(locale);
const products = await Promise.all(slugs.map(slug => getProductBySlug(slug, locale)));
return products.filter((p): p is ProductMdx => p !== null);
}