filter products
All checks were successful
Build & Deploy KLZ Cables / build-and-deploy (push) Successful in 3m52s
All checks were successful
Build & Deploy KLZ Cables / build-and-deploy (push) Successful in 3m52s
This commit is contained in:
26
lib/mdx.ts
26
lib/mdx.ts
@@ -31,6 +31,8 @@ export async function getProductBySlug(slug: string, locale: string): Promise<Pr
|
|||||||
filePath = path.join(productsDir, `${fileSlug}-2.mdx`);
|
filePath = path.join(productsDir, `${fileSlug}-2.mdx`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let product: ProductMdx | null = null;
|
||||||
|
|
||||||
if (!fs.existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
// Fallback to English if locale is not 'en'
|
// Fallback to English if locale is not 'en'
|
||||||
if (locale !== 'en') {
|
if (locale !== 'en') {
|
||||||
@@ -43,7 +45,7 @@ export async function getProductBySlug(slug: string, locale: string): Promise<Pr
|
|||||||
if (fs.existsSync(enFilePath)) {
|
if (fs.existsSync(enFilePath)) {
|
||||||
const fileContent = fs.readFileSync(enFilePath, 'utf8');
|
const fileContent = fs.readFileSync(enFilePath, 'utf8');
|
||||||
const { data, content } = matter(fileContent);
|
const { data, content } = matter(fileContent);
|
||||||
return {
|
product = {
|
||||||
slug: fileSlug,
|
slug: fileSlug,
|
||||||
frontmatter: {
|
frontmatter: {
|
||||||
...data,
|
...data,
|
||||||
@@ -53,17 +55,23 @@ export async function getProductBySlug(slug: string, locale: string): Promise<Pr
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const fileContent = fs.readFileSync(filePath, 'utf8');
|
||||||
|
const { data, content } = matter(fileContent);
|
||||||
|
|
||||||
|
product = {
|
||||||
|
slug: fileSlug,
|
||||||
|
frontmatter: data as ProductFrontmatter,
|
||||||
|
content,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter out products without images
|
||||||
|
if (product && (!product.frontmatter.images || product.frontmatter.images.length === 0 || !product.frontmatter.images[0])) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileContent = fs.readFileSync(filePath, 'utf8');
|
return product;
|
||||||
const { data, content } = matter(fileContent);
|
|
||||||
|
|
||||||
return {
|
|
||||||
slug: fileSlug,
|
|
||||||
frontmatter: data as ProductFrontmatter,
|
|
||||||
content,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllProductSlugs(locale: string): Promise<string[]> {
|
export async function getAllProductSlugs(locale: string): Promise<string[]> {
|
||||||
|
|||||||
Reference in New Issue
Block a user