From 4d995a61afa724e76b390bc6118794d7bcf8dd01 Mon Sep 17 00:00:00 2001 From: soheil khaledabadi Date: Fri, 22 May 2026 13:35:28 +0330 Subject: [PATCH] feat(Menu,Lang,Image): fix bug menu and change lang and set images --- .env | 2 +- .env.example | 2 +- app/[lang]/layout.js | 4 +- app/[lang]/page.js | 3 +- components/About.js | 10 ++- components/Header.js | 148 +++++++++++++++++++++++++++----------- components/ProductCard.js | 13 ++-- components/Production.js | 47 ++++++------ components/Products.js | 13 ++-- lib/localImages.js | 20 ++++++ middleware.js | 6 +- 11 files changed, 176 insertions(+), 92 deletions(-) mode change 100755 => 100644 components/Header.js create mode 100644 lib/localImages.js diff --git a/.env b/.env index 989a3af..831f0e0 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -NEXT_PUBLIC_API_BASE_URL=https://cms.soheilkhaledabadi.ir +NEXT_PUBLIC_API_BASE_URL=https://cms.rahavardmgp.com/ NEXT_PUBLIC_IMAGE_HOSTNAME=axicon-portal.iran.liara.run ARVAN_NAMESPACE=docker.arvancloud.ir IMAGE_TAG=latest diff --git a/.env.example b/.env.example index 55886b3..a1ffb2e 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ # API base URL (backend CMS) -NEXT_PUBLIC_API_BASE_URL=https://your-api-domain.com +NEXT_PUBLIC_API_BASE_URL=https://cms.rahavardmgp.com/ # Hostname of the image server returned by the API (for Next.js Image optimization) NEXT_PUBLIC_IMAGE_HOSTNAME=your-image-cdn-domain.com diff --git a/app/[lang]/layout.js b/app/[lang]/layout.js index 6419a38..78d3f2a 100755 --- a/app/[lang]/layout.js +++ b/app/[lang]/layout.js @@ -48,7 +48,9 @@ export const metadata = { } export const dynamic = 'force-dynamic'; -export default function RootLayout({ params: { lang }, children }) { +export default async function RootLayout({ params, children }) { + const { lang } = await params + return ( diff --git a/app/[lang]/page.js b/app/[lang]/page.js index 5576fca..6409ae8 100755 --- a/app/[lang]/page.js +++ b/app/[lang]/page.js @@ -6,7 +6,8 @@ import Production from '@/components/Production' import About from '@/components/About' import BlogPosts from '@/components/BlogPosts' -export default async function Home({ params: { lang } }) { +export default async function Home({ params }) { + const { lang } = await params return (
diff --git a/components/About.js b/components/About.js index bba7d83..a6a6f82 100755 --- a/components/About.js +++ b/components/About.js @@ -1,9 +1,7 @@ - -import PicSmall from '../public/PicSmall.png' -import Avatars from '../public/Avatars.png' import Image from 'next/image' import PicAbout from '../public/PicAbout.png' import Link from 'next/link' +import { aboutImages } from '@/lib/localImages' async function getData(id) { const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/public/content/index/${id}`) @@ -27,7 +25,7 @@ export default async function About({lang}) { return( -
+
{ data.aboutSuper?.[0]?.body || '' } @@ -64,7 +62,7 @@ export default async function About({lang}) {

- +
{ data.about2Head?.[0]?.body || '' } @@ -79,7 +77,7 @@ export default async function About({lang}) {
- +
) diff --git a/components/Header.js b/components/Header.js old mode 100755 new mode 100644 index 7ae231d..bfdc4f1 --- a/components/Header.js +++ b/components/Header.js @@ -1,48 +1,112 @@ -import Link from 'next/link'; +"use client" -export default function Header(){ +import Link from 'next/link' +import { usePathname } from 'next/navigation' +import { useState } from 'react' +const locales = ['fa', 'en'] + +function getLocalizedPath(pathname, nextLocale) { + const parts = pathname.split('/').filter(Boolean) + + if (locales.includes(parts[0])) { + parts[0] = nextLocale + return `/${parts.join('/')}` + } + + return `/${nextLocale}${pathname === '/' ? '' : pathname}` +} + +function MenuIcon({ open }) { return ( -
- - - - - - - - - - - - - - - - - - - - -
- - English - - / - - فارسی - -
-
+ ) } +function Logo() { + return ( + + + + + + + + + + + + + ) +} + +export default function Header({ lang = 'fa' }){ + const pathname = usePathname() + const [isOpen, setIsOpen] = useState(false) + const isFa = lang === 'fa' + const basePath = `/${lang}` + const items = [ + { href: `${basePath}#about`, label: isFa ? 'درباره ما' : 'About' }, + { href: `${basePath}#products`, label: isFa ? 'محصولات' : 'Products' }, + { href: `${basePath}#production`, label: isFa ? 'تجهیزات' : 'Equipment' }, + { href: `${basePath}/management`, label: isFa ? 'مدیریت' : 'Management' }, + ] + + return ( +
+
+ + + setIsOpen(false)}> + + + +
+ + English + + / + + فارسی + +
+
+ + {isOpen && ( +
+ +
+ )} +
+ ) +} diff --git a/components/ProductCard.js b/components/ProductCard.js index fccc095..615eb51 100755 --- a/components/ProductCard.js +++ b/components/ProductCard.js @@ -1,15 +1,14 @@ import Image from 'next/image' -import productpic from '../public/productpic.webp' export default function ProductCard({ image, desc }) { return ( -
-
- +
+
+
-
-

{ desc }

+
+

{ desc }

) -} \ No newline at end of file +} diff --git a/components/Production.js b/components/Production.js index e9beb70..9bcb503 100755 --- a/components/Production.js +++ b/components/Production.js @@ -1,7 +1,6 @@ import Image from 'next/image' - -import CategoryImage from '../public/img.png' +import { equipmentImages } from '@/lib/localImages' async function getData(id) { const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/public/content/index/${id}`) @@ -24,7 +23,7 @@ export default async function Production({ lang }){ } return( -
+
{ data.equipmentSuper?.[0]?.body || '' } @@ -63,34 +62,34 @@ export default async function Production({ lang }){ { data.equipmentDesc?.[0]?.body || '' }

-
-
- -
- { data.equipment3Title?.[0]?.body || '' } -

{ data.equipment3Desc?.[0]?.body || '' }

+
+
+ +
+ { data.equipment3Title?.[0]?.body || '' } +

{ data.equipment3Desc?.[0]?.body || '' }

-
- -
- { data.equipment3Title?.[1]?.body || '' } -

{ data.equipment3Desc?.[1]?.body || '' }

+
+ +
+ { data.equipment3Title?.[1]?.body || '' } +

{ data.equipment3Desc?.[1]?.body || '' }

-
-
- { data.equipment3Title?.[2]?.body || '' } -

{ data.equipment3Desc?.[2]?.body || '' }

+
+
+ { data.equipment3Title?.[2]?.body || '' } +

{ data.equipment3Desc?.[2]?.body || '' }

- +
-
-
- { data.equipment3Title?.[3]?.body || '' } -

{ data.equipment3Desc?.[3]?.body || '' }

+
+
+ { data.equipment3Title?.[3]?.body || '' } +

{ data.equipment3Desc?.[3]?.body || '' }

- +
diff --git a/components/Products.js b/components/Products.js index c240c53..3d7ca74 100755 --- a/components/Products.js +++ b/components/Products.js @@ -1,6 +1,7 @@ import Image from 'next/image' import productbg from '../public/productbg.webp' import ProductCard from '@/components/ProductCard' +import { productImages } from '@/lib/localImages' async function getData(id) { const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/public/content/index/${id}`) @@ -22,18 +23,18 @@ export default async function Products({ lang }){ } return( -
- +
+
{data.productsSuper?.[0]?.body || ''} {data.productsHead?.[0]?.body || ''}

{data.productsDesc?.[0]?.body || ''}

-
+
{ - data.productImages?.map((image, index) => ( - - )) || [] + productImages.map((image, index) => ( + + )) }
diff --git a/lib/localImages.js b/lib/localImages.js new file mode 100644 index 0000000..7de9a9d --- /dev/null +++ b/lib/localImages.js @@ -0,0 +1,20 @@ +export const aboutImages = { + primary: "/images/about-production.jpg", + secondary: "/images/about-magnesium-rock.jpg", +} + +export const productImages = [ + "/images/product-ingot-stack.jpg", + "/images/product-plates.jpg", + "/images/product-anode-bars.jpg", + "/images/product-cnc-parts.jpg", + "/images/product-machined-anodes.jpg", + "/images/product-sacrificial-anodes.jpg", +] + +export const equipmentImages = [ + "/images/equipment-furnace.jpg", + "/images/equipment-electrotherm-line.jpg", + "/images/equipment-casting-machine.jpg", + "/images/equipment-press-machine.jpg", +] diff --git a/middleware.js b/middleware.js index 14e1b34..fbb1e41 100755 --- a/middleware.js +++ b/middleware.js @@ -40,9 +40,9 @@ export function middleware(request) { export const config = { matcher: [ - // Skip all internal paths (_next) - '/((?!_next).*)', + // Skip internal Next.js paths and public files. + '/((?!_next|.*\\..*).*)', // Optional: only run on root (/) URL // '/' ], -} \ No newline at end of file +}