From 58b027813daaf32540e46a2ea1fd463b7816d986 Mon Sep 17 00:00:00 2001
From: soheil khaledabadi
Date: Sun, 21 Jun 2026 20:20:20 +0330
Subject: [PATCH] feat(core): update
---
app/[lang]/home/layout.js | 14 ++++
app/[lang]/home/page.js | 17 +++++
app/[lang]/layout.js | 4 --
app/[lang]/management/layout.js | 14 ++++
app/[lang]/page.js | 113 ++++++++++++++++++++++++++++----
components/About.js | 17 ++---
components/Footer.js | 14 +---
components/Header.js | 4 +-
components/Hero.js | 14 +---
components/ProductCard.js | 2 +-
components/Production.js | 21 ++----
components/Products.js | 15 +----
lib/content.js | 23 +++++++
lib/localImages.js | 37 +++++++----
middleware.js | 36 +++++-----
15 files changed, 232 insertions(+), 113 deletions(-)
create mode 100644 app/[lang]/home/layout.js
create mode 100644 app/[lang]/home/page.js
create mode 100644 app/[lang]/management/layout.js
mode change 100755 => 100644 app/[lang]/page.js
create mode 100644 lib/content.js
diff --git a/app/[lang]/home/layout.js b/app/[lang]/home/layout.js
new file mode 100644
index 0000000..39fd182
--- /dev/null
+++ b/app/[lang]/home/layout.js
@@ -0,0 +1,14 @@
+import Header from '@/components/Header'
+import Footer from '@/components/Footer'
+
+export default async function HomeLayout({ params, children }) {
+ const { lang } = await params
+
+ return (
+ <>
+
+ {children}
+
+ >
+ )
+}
diff --git a/app/[lang]/home/page.js b/app/[lang]/home/page.js
new file mode 100644
index 0000000..ee1db81
--- /dev/null
+++ b/app/[lang]/home/page.js
@@ -0,0 +1,17 @@
+import Hero from '@/components/Hero'
+import Products from '@/components/Products'
+import Production from '@/components/Production'
+import About from '@/components/About'
+
+export default async function Home({ params }) {
+ const { lang } = await params
+
+ return (
+
+
+
+
+
+
+ )
+}
diff --git a/app/[lang]/layout.js b/app/[lang]/layout.js
index 78d3f2a..a9908f3 100755
--- a/app/[lang]/layout.js
+++ b/app/[lang]/layout.js
@@ -1,7 +1,5 @@
import '../globals.css'
import localFont from 'next/font/local'
-import Header from '@/components/Header'
-import Footer from '@/components/Footer'
import {Providers} from "../providers";
@@ -55,9 +53,7 @@ export default async function RootLayout({ params, children }) {
-
{children}
-
diff --git a/app/[lang]/management/layout.js b/app/[lang]/management/layout.js
new file mode 100644
index 0000000..4e3bf71
--- /dev/null
+++ b/app/[lang]/management/layout.js
@@ -0,0 +1,14 @@
+import Header from '@/components/Header'
+import Footer from '@/components/Footer'
+
+export default async function ManagementLayout({ params, children }) {
+ const { lang } = await params
+
+ return (
+ <>
+
+ {children}
+
+ >
+ )
+}
diff --git a/app/[lang]/page.js b/app/[lang]/page.js
old mode 100755
new mode 100644
index 6409ae8..d7c44cf
--- a/app/[lang]/page.js
+++ b/app/[lang]/page.js
@@ -1,21 +1,108 @@
+import Link from 'next/link'
-import Hero from '@/components/Hero'
-import Products from '@/components/Products'
-import SmartHome from '@/components/SmartHome'
-import Production from '@/components/Production'
-import About from '@/components/About'
-import BlogPosts from '@/components/BlogPosts'
+function BrandMark() {
+ return (
+
+
+
+
+
+ )
+}
-export default async function Home({ params }) {
+export async function generateMetadata({ params }) {
const { lang } = await params
+ const isFa = lang === 'fa'
+
+ return {
+ title: isFa ? 'بهزودی برمیگردیم | رهاورد' : 'Coming soon | Rahavard',
+ description: isFa
+ ? 'وبسایت رهاورد در حال بهروزرسانی است.'
+ : 'The Rahavard website is being updated.',
+ }
+}
+
+export default async function ComingSoon({ params }) {
+ const { lang } = await params
+ const isFa = lang === 'fa'
+ const otherLanguage = isFa ? 'en' : 'fa'
return (
-
-
-
-
-
- {/**/}
+
+
+
+
+
+
+
+
+
+ {isFa ? 'رهاورد منیزیم پارسه' : 'RAHAVARD MGP'}
+
+
+
+ {isFa ? 'English' : 'فارسی'}
+
+
+
+
+
+
+
+
+ {isFa ? 'در حال بهروزرسانی' : 'UNDER CONSTRUCTION'}
+
+
+
+
+ {isFa ? (
+ <>
+ بهزودی
+
+ برمیگردیم.
+ >
+ ) : (
+ <>
+ We'll be
+
+ back soon.
+ >
+ )}
+
+
+
+
+
+ {isFa
+ ? 'در حال آمادهسازی تجربهای تازه برای شما هستیم. وبسایت جدید رهاورد بهزودی در دسترس خواهد بود.'
+ : 'We are preparing a new experience for you. The new Rahavard website will be available shortly.'}
+
+
+
+
+
+ {isFa ? 'قم، ایران' : 'Qom, Iran'}
+ © {new Date().getFullYear()} RAHAVARD MGP
+
)
}
diff --git a/components/About.js b/components/About.js
index a6a6f82..158ca54 100755
--- a/components/About.js
+++ b/components/About.js
@@ -1,21 +1,12 @@
import Image from 'next/image'
import PicAbout from '../public/PicAbout.png'
import Link from 'next/link'
+import { getPublicContent } from '@/lib/content'
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}`)
-
- if (!res.ok) {
- throw new Error('Failed to fetch data')
- }
-
- return res.json()
-}
-
export default async function About({lang}) {
- const data = await getData(lang === 'fa' ? 1 : 2);
+ const data = await getPublicContent(lang);
// Add safety checks for data structure
if (!data || typeof data !== 'object') {
@@ -62,7 +53,7 @@ export default async function About({lang}) {
-
+
{ data.about2Head?.[0]?.body || '' }
@@ -77,7 +68,7 @@ export default async function About({lang}) {
-
+
)
diff --git a/components/Footer.js b/components/Footer.js
index 8cc075e..272867c 100755
--- a/components/Footer.js
+++ b/components/Footer.js
@@ -1,4 +1,5 @@
import Crown from '@/components/Crown'
+import { getPublicContent } from '@/lib/content'
export function RMGPSVG (){
return (
@@ -21,19 +22,8 @@ export function RMGPSVG (){
)
}
-async function getData(id) {
- const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/public/content/index/${id}`)
-
- if (!res.ok) {
- throw new Error('Failed to fetch data')
- }
-
- return res.json()
-}
-
-
export default async function Footer({ lang }){
- const data = await getData(lang === 'fa' ? 1 : 2);
+ const data = await getPublicContent(lang);
// Add safety checks for data structure
if (!data || typeof data !== 'object') {
diff --git a/components/Header.js b/components/Header.js
index bfdc4f1..f918329 100644
--- a/components/Header.js
+++ b/components/Header.js
@@ -54,12 +54,12 @@ export default function Header({ lang = 'fa' }){
const pathname = usePathname()
const [isOpen, setIsOpen] = useState(false)
const isFa = lang === 'fa'
- const basePath = `/${lang}`
+ const basePath = `/${lang}/home`
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' },
+ { href: `/${lang}/management`, label: isFa ? 'مدیریت' : 'Management' },
]
return (
diff --git a/components/Hero.js b/components/Hero.js
index d2b3c18..433fc38 100755
--- a/components/Hero.js
+++ b/components/Hero.js
@@ -1,6 +1,7 @@
import Image from 'next/image'
import bg from '../public/bg.webp'
import MG from '@/components/MG'
+import { getPublicContent } from '@/lib/content'
export function RMGPSVG (){
return (
@@ -56,20 +57,9 @@ const circles = (
)
-async function getData(id) {
- const res = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/public/content/index/${id}`)
-
- if (!res.ok) {
- throw new Error('Failed to fetch data')
- }
-
- return res.json()
-}
-
-
export default async function Hero({lang}){
- const data = await getData(lang === 'fa' ? 1 : 2);
+ const data = await getPublicContent(lang);
// Add safety checks for data structure
if (!data || typeof data !== 'object') {
diff --git a/components/ProductCard.js b/components/ProductCard.js
index 615eb51..c823262 100755
--- a/components/ProductCard.js
+++ b/components/ProductCard.js
@@ -4,7 +4,7 @@ export default function ProductCard({ image, desc }) {
return (
-
+
{ desc }
diff --git a/components/Production.js b/components/Production.js
index 9bcb503..3b32b46 100755
--- a/components/Production.js
+++ b/components/Production.js
@@ -1,20 +1,11 @@
import Image from 'next/image'
+import { getPublicContent } from '@/lib/content'
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}`)
-
- if (!res.ok) {
- throw new Error('Failed to fetch data')
- }
-
- return res.json()
-}
-
export default async function Production({ lang }){
- const data = await getData(lang === 'fa' ? 1 : 2);
+ const data = await getPublicContent(lang);
// Add safety checks for data structure
if (!data || typeof data !== 'object') {
@@ -64,14 +55,14 @@ export default async function Production({ lang }){
-
+
{ data.equipment3Title?.[0]?.body || '' }
{ data.equipment3Desc?.[0]?.body || '' }
-
+
{ data.equipment3Title?.[1]?.body || '' }
{ data.equipment3Desc?.[1]?.body || '' }
@@ -82,14 +73,14 @@ export default async function Production({ lang }){
{ data.equipment3Title?.[2]?.body || '' }
{ data.equipment3Desc?.[2]?.body || '' }
-
+
{ data.equipment3Title?.[3]?.body || '' }
{ data.equipment3Desc?.[3]?.body || '' }
-
+
diff --git a/components/Products.js b/components/Products.js
index 3d7ca74..62385b0 100755
--- a/components/Products.js
+++ b/components/Products.js
@@ -1,20 +1,11 @@
import Image from 'next/image'
import productbg from '../public/productbg.webp'
import ProductCard from '@/components/ProductCard'
+import { getPublicContent } from '@/lib/content'
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}`)
-
- if (!res.ok) {
- throw new Error('Failed to fetch data')
- }
-
- return res.json()
-}
-
export default async function Products({ lang }){
- const data = await getData(lang === 'fa' ? 1 : 2);
+ const data = await getPublicContent(lang);
// Add safety checks for data structure
if (!data || typeof data !== 'object') {
@@ -33,7 +24,7 @@ export default async function Products({ lang }){
{
productImages.map((image, index) => (
-
+
))
}
diff --git a/lib/content.js b/lib/content.js
new file mode 100644
index 0000000..0e4ac21
--- /dev/null
+++ b/lib/content.js
@@ -0,0 +1,23 @@
+export async function getPublicContent(lang) {
+ const id = lang === 'fa' ? 1 : 2
+ const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL
+
+ if (!baseUrl) {
+ console.error('NEXT_PUBLIC_API_BASE_URL is not set')
+ return {}
+ }
+
+ try {
+ const res = await fetch(`${baseUrl}/api/public/content/index/${id}`)
+
+ if (!res.ok) {
+ console.error(`Failed to fetch public content: ${res.status}`)
+ return {}
+ }
+
+ return res.json()
+ } catch (error) {
+ console.error('Failed to fetch public content', error)
+ return {}
+ }
+}
diff --git a/lib/localImages.js b/lib/localImages.js
index 7de9a9d..6126274 100644
--- a/lib/localImages.js
+++ b/lib/localImages.js
@@ -1,20 +1,33 @@
+import aboutMagnesiumRock from '@/public/images/about-magnesium-rock.jpg'
+import aboutProduction from '@/public/images/about-production.jpg'
+import equipmentCastingMachine from '@/public/images/equipment-casting-machine.jpg'
+import equipmentElectrothermLine from '@/public/images/equipment-electrotherm-line.jpg'
+import equipmentFurnace from '@/public/images/equipment-furnace.jpg'
+import equipmentPressMachine from '@/public/images/equipment-press-machine.jpg'
+import productAnodeBars from '@/public/images/product-anode-bars.jpg'
+import productCncParts from '@/public/images/product-cnc-parts.jpg'
+import productIngotStack from '@/public/images/product-ingot-stack.jpg'
+import productMachinedAnodes from '@/public/images/product-machined-anodes.jpg'
+import productPlates from '@/public/images/product-plates.jpg'
+import productSacrificialAnodes from '@/public/images/product-sacrificial-anodes.jpg'
+
export const aboutImages = {
- primary: "/images/about-production.jpg",
- secondary: "/images/about-magnesium-rock.jpg",
+ primary: aboutProduction,
+ secondary: aboutMagnesiumRock,
}
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",
+ productIngotStack,
+ productPlates,
+ productAnodeBars,
+ productCncParts,
+ productMachinedAnodes,
+ productSacrificialAnodes,
]
export const equipmentImages = [
- "/images/equipment-furnace.jpg",
- "/images/equipment-electrotherm-line.jpg",
- "/images/equipment-casting-machine.jpg",
- "/images/equipment-press-machine.jpg",
+ equipmentFurnace,
+ equipmentElectrothermLine,
+ equipmentCastingMachine,
+ equipmentPressMachine,
]
diff --git a/middleware.js b/middleware.js
index fbb1e41..b60ade9 100755
--- a/middleware.js
+++ b/middleware.js
@@ -2,23 +2,25 @@ import { match } from '@formatjs/intl-localematcher'
import Negotiator from 'negotiator'
// Get the preferred locale, similar to the above or using a library
-let locales = ['en', 'fa']
-function getLocale(request) {
- let headers = { 'accept-language': 'en-US,en;q=0.5' }
- let languages = new Negotiator({ headers }).languages()
- let defaultLocale = 'en-US';
- let domains= [
- {
- domain: "rahavardmgp.ir",
- defaultLocale: 'fa'
- },
- {
- domain: "rahavardmgp.com",
- defaultLocale: 'en'
- }
- ]
-
- return match(languages, locales, defaultLocale, domains) // -> 'en-US'
+const locales = ['en', 'fa']
+
+function getLocale(request) {
+ const hostname = request.headers.get('host')?.split(':')[0]
+
+ if (hostname === 'rahavardmgp.ir' || hostname === 'www.rahavardmgp.ir') {
+ return 'fa'
+ }
+
+ if (hostname === 'rahavardmgp.com' || hostname === 'www.rahavardmgp.com') {
+ return 'en'
+ }
+
+ const headers = {
+ 'accept-language': request.headers.get('accept-language') || 'fa'
+ }
+ const languages = new Negotiator({ headers }).languages()
+
+ return match(languages, locales, 'fa')
}
export function middleware(request) {