diff --git a/frontend/src/components/home/Hero.tsx b/frontend/src/components/home/Hero.tsx index 700f820..5a13493 100644 --- a/frontend/src/components/home/Hero.tsx +++ b/frontend/src/components/home/Hero.tsx @@ -10,9 +10,46 @@ import { InlineEdit } from '../admin/InlineEdit' import { HeroProjectBadge } from './HeroProjectBadge' import { SingletonPill } from '../../admin/Editable' +/** واژه‌های عمومی برچسب نشان که در تطبیق نام پروژه نادیده گرفته می‌شوند */ +const NOISE_WORDS = ['پروژه', 'فعال', 'آرامش', 'گروه', 'ساختمانی', 'Active', 'Project', 'Aramesh'] +/** نام لاتین برچسب انگلیسی → معادل فارسی در عنوان پروژه (پروژه‌های بدون title_en) */ +const LATIN_ALIAS: Record = { elysian: 'الیسیان' } + export function Hero() { - const { brand, hero } = useSite() - const { t, href } = useLang() + const { brand, hero, projects } = useSite() + const { t, href, lang } = useLang() + + /** + * پروژهٔ فعال هیرو → صفحهٔ همان پروژه. + * برچسب نشان مثل «پروژه فعال آرامش الیسیان» یا «Elysian Aramesh Active Project» + * است؛ واژه‌های عمومی حذف و نام باقی‌مانده با عنوان پروژه‌ها تطبیق داده می‌شود. + */ + const activeProjectHref = (() => { + const label = hero.badge_label.trim() + if (!label) return undefined + + const strip = (text: string) => { + let out = text + NOISE_WORDS.forEach((w) => { + out = out.split(w).join(' ') + }) + return out.replace(/[\s\-—_]+/g, '').trim().toLowerCase() + } + + let key = strip(label) + // برچسب انگلیسی ممکن است نام لاتین داشته باشد و پروژه فقط عنوان فارسی (Elysian → الیسیان) + if (key.length < 3 || LATIN_ALIAS[key]) key = LATIN_ALIAS[key] ?? key + if (key.length < 3) return undefined + + const hit = projects.find((p) => { + const candidates = [p.title, p.title_en ?? ''].filter(Boolean) + return candidates.some((title) => { + const k = strip(title) + return k.length >= 3 && (k.includes(key) || key.includes(k)) + }) + }) + return hit ? `/projects/${hit.slug}` : undefined + })() const save = useFieldSaver() const { scrollY } = useScroll() const imageY = useTransform(scrollY, [0, 700], [0, 110]) @@ -141,7 +178,11 @@ export function Hero() {