Merge remote-tracking branch 'origin/main' into navbar
This commit is contained in:
@@ -78,7 +78,7 @@ export default async function ProductPage({
|
||||
productCategory={productCategory}
|
||||
className="mt-6"
|
||||
/>
|
||||
<div className="mt-20">
|
||||
<div id="productList" className="mt-20">
|
||||
<h2 className="mb-6 text-3xl font-semibold text-gray-500">
|
||||
{productCategory.title} Products
|
||||
</h2>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { productCategories } from '../../data';
|
||||
import type { IProductCardProps } from '@/components/pages/products/productCard/productCard.d';
|
||||
import { productCategoriesData } from '../../data';
|
||||
|
||||
// Helper to generate 50 products for a category
|
||||
export function generateProductsForCategory(
|
||||
@@ -18,7 +18,7 @@ export function generateProductsForCategory(
|
||||
// Map of categoryId to products
|
||||
export const productsByCategory: Record<string, IProductCardProps[]> =
|
||||
Object.fromEntries(
|
||||
productCategories.map((cat) => [
|
||||
productCategoriesData.map((cat) => [
|
||||
cat.id,
|
||||
generateProductsForCategory(cat.id, cat.title),
|
||||
]),
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { NextResponse, NextRequest } from 'next/server';
|
||||
import { cookies } from 'next/headers';
|
||||
import { productCategories } from '../../data';
|
||||
import { generateProductsForCategory } from './data';
|
||||
import { productCategoriesData } from '../../data';
|
||||
|
||||
export async function GET(request: NextRequest, context: any) {
|
||||
const cookieStore = await cookies();
|
||||
const lang = cookieStore.get('locale')?.value || 'en';
|
||||
|
||||
const params = await context.params;
|
||||
const category = productCategories.find((cat) => cat.id === params.id);
|
||||
const category = productCategoriesData.find((cat) => cat.id === params.id);
|
||||
|
||||
if (!category) {
|
||||
return NextResponse.json({ error: 'Not found' }, { status: 404 });
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { NextResponse, NextRequest } from 'next/server';
|
||||
import { cookies } from 'next/headers';
|
||||
import { productCategories } from '../data';
|
||||
import { productCategoriesData } from '../data';
|
||||
|
||||
interface IContext {
|
||||
params: {
|
||||
@@ -20,7 +20,7 @@ export async function GET(request: NextRequest, context: any) {
|
||||
|
||||
const { id } = params;
|
||||
|
||||
let category = productCategories.find((cat) => cat.id === id);
|
||||
let category = productCategoriesData.find((cat) => cat.id === id);
|
||||
|
||||
if (!category) {
|
||||
return NextResponse.json({ error: 'Not found' }, { status: 404 });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export const productCategories = [
|
||||
export const productCategoriesData = [
|
||||
{
|
||||
id: '1',
|
||||
title: 'Ghazaghi',
|
||||
|
||||
@@ -1,63 +1,36 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { cookies } from 'next/headers';
|
||||
import { productCategories } from './data';
|
||||
import { APIProductCategoryEntity } from '@/models/api';
|
||||
import { productCategoriesData } from './data';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
let data = productCategories;
|
||||
try {
|
||||
let data = productCategoriesData as APIProductCategoryEntity[];
|
||||
|
||||
const cookieStore = await cookies();
|
||||
const lang = (await cookieStore).get('lang')?.value || 'fa';
|
||||
const cookieStore = await cookies();
|
||||
const lang = (await cookieStore).get('locale')?.value || 'en';
|
||||
console.log('!!!!!!!!!!!!!!!!!!!!');
|
||||
console.log(lang);
|
||||
|
||||
if (lang === 'fa') {
|
||||
data = productCategories.map(
|
||||
({
|
||||
id,
|
||||
title,
|
||||
fa_title,
|
||||
icon,
|
||||
typesCount,
|
||||
priceTypeTitle,
|
||||
fa_priceTypeTitle,
|
||||
meta_description,
|
||||
meta_keywords,
|
||||
meta_title,
|
||||
slug,
|
||||
bestForTitle,
|
||||
fa_bestForTitle,
|
||||
description,
|
||||
fa_description,
|
||||
}) => {
|
||||
if (lang === 'fa') {
|
||||
return {
|
||||
id,
|
||||
icon,
|
||||
typesCount,
|
||||
meta_description,
|
||||
meta_keywords,
|
||||
meta_title,
|
||||
slug,
|
||||
title: fa_title || title,
|
||||
priceTypeTitle: fa_priceTypeTitle || priceTypeTitle,
|
||||
bestForTitle: fa_bestForTitle || bestForTitle,
|
||||
description: fa_description || description,
|
||||
};
|
||||
}
|
||||
return {
|
||||
id,
|
||||
icon,
|
||||
typesCount,
|
||||
title,
|
||||
priceTypeTitle,
|
||||
bestForTitle,
|
||||
meta_description,
|
||||
meta_keywords,
|
||||
meta_title,
|
||||
slug,
|
||||
description,
|
||||
};
|
||||
},
|
||||
if (lang === 'fa') {
|
||||
data = productCategoriesData.map((productCategory) => ({
|
||||
...productCategory,
|
||||
title: (lang && productCategory.fa_title) || productCategory.title,
|
||||
priceTypeTitle:
|
||||
productCategory.fa_priceTypeTitle || productCategory.priceTypeTitle,
|
||||
bestForTitle:
|
||||
productCategory.fa_bestForTitle || productCategory.bestForTitle,
|
||||
description:
|
||||
productCategory.fa_description || productCategory.description,
|
||||
}));
|
||||
}
|
||||
|
||||
return NextResponse.json({ data });
|
||||
} catch (error) {
|
||||
console.error('Error fetching product categories:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch product categories' },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({ data: productCategories });
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
'use server';
|
||||
|
||||
// app/(api)/sitemap/route.ts
|
||||
import { NextResponse } from 'next/server';
|
||||
import { productCategoriesData } from '../product_categories/data';
|
||||
import { host } from '@/config';
|
||||
import { projects } from '../projects/data';
|
||||
|
||||
const pages = [
|
||||
'/',
|
||||
'/about-us',
|
||||
'/contact-us',
|
||||
'/blog',
|
||||
'/product-categories',
|
||||
'/projects',
|
||||
];
|
||||
|
||||
const locales = ['en', 'fa'];
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
pages.push(
|
||||
...productCategoriesData.map(
|
||||
(productCategory) => `/product-categories/${productCategory.id}`,
|
||||
),
|
||||
);
|
||||
pages.push(...projects.map((project) => `/projects/${project.id}`));
|
||||
|
||||
const urls = pages.flatMap((page) =>
|
||||
locales.map((locale) => {
|
||||
const loc = `/${locale}`;
|
||||
return `
|
||||
<url>
|
||||
<loc>${host}${loc}${page}</loc>
|
||||
<changefreq>weekly</changefreq>
|
||||
<priority>0.8</priority>
|
||||
</url>
|
||||
`;
|
||||
}),
|
||||
);
|
||||
|
||||
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
${urls.join('\n')}
|
||||
</urlset>`;
|
||||
|
||||
return new NextResponse(xml, {
|
||||
headers: {
|
||||
'Content-Type': 'application/xml',
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Sitemap generation failed:', err);
|
||||
return new NextResponse('Internal Server Errorsssssss', { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user