fix(navbar): eliminate hardcoded names and make navbar and categories 100% dynamic JSON-driven

This commit is contained in:
2026-11-11 11:20:04 +05:30
parent 4afbf80709
commit 1e675d56fa
6 changed files with 94 additions and 79 deletions
+17 -4
View File
@@ -35,11 +35,14 @@
"header": [ "header": [
{ {
"label": { "en": "Tools", "hi": "टूल्स" }, "label": { "en": "Tools", "hi": "टूल्स" },
"href": "/tools" "href": "/tools",
"hasDropdown": true,
"badge": "14 tools"
}, },
{ {
"label": { "en": "Apps", "hi": "ऐप्स" }, "label": { "en": "Apps", "hi": "ऐप्स" },
"href": "/apps" "href": "/apps",
"badge": "iOS · Mac"
}, },
{ {
"label": { "en": "Pricing", "hi": "मूल्य निर्धारण" }, "label": { "en": "Pricing", "hi": "मूल्य निर्धारण" },
@@ -51,8 +54,18 @@
} }
], ],
"cta": { "cta": {
"label": { "en": "Get the App", "hi": "ऐप प्राप्त करें" }, "label": { "en": "Try Tools Free", "hi": "टूल्स मुफ्त आज़माएं" },
"href": "/apps" "href": "/tools"
},
"toolsDropdown": {
"viewAllText": {
"en": "Explore all studio tools",
"hi": "सभी स्टूडियो टूल्स देखें"
},
"tagline": {
"en": "Instant client GPU trial · Zero retention",
"hi": "त्वरित क्लाइंट जीपीयू परीक्षण · शून्य प्रतिधारण"
}
} }
}, },
"footer": { "footer": {
+9 -2
View File
@@ -1,7 +1,7 @@
import type { Metadata } from 'next'; import type { Metadata } from 'next';
import { Poppins, Inter, JetBrains_Mono } from 'next/font/google'; import { Poppins, Inter, JetBrains_Mono } from 'next/font/google';
import './globals.css'; import './globals.css';
import { getSiteConfig } from '@/lib/config/loader'; import { getSiteConfig, getAllCategories, getAllTools } from '@/lib/config/loader';
import { Navbar } from '@/components/ui/Navbar'; import { Navbar } from '@/components/ui/Navbar';
import { Footer } from '@/components/ui/Footer'; import { Footer } from '@/components/ui/Footer';
import { SmoothScrollProvider } from '@/components/ui/SmoothScrollProvider'; import { SmoothScrollProvider } from '@/components/ui/SmoothScrollProvider';
@@ -70,6 +70,8 @@ export default function RootLayout({
children: React.ReactNode; children: React.ReactNode;
}) { }) {
const config = getSiteConfig(); const config = getSiteConfig();
const categories = getAllCategories();
const tools = getAllTools();
const siteUrl = process.env.SITE_URL || config.seo.siteUrl || 'http://localhost:3000'; const siteUrl = process.env.SITE_URL || config.seo.siteUrl || 'http://localhost:3000';
// Root Schema.org JSON-LD for Organization & WebSite // Root Schema.org JSON-LD for Organization & WebSite
@@ -96,7 +98,12 @@ export default function RootLayout({
<body className="min-h-screen flex flex-col antialiased bg-paper text-ink relative font-sans overflow-x-clip"> <body className="min-h-screen flex flex-col antialiased bg-paper text-ink relative font-sans overflow-x-clip">
<SmoothScrollProvider> <SmoothScrollProvider>
<a href="#main-content" className="skip-link">Skip to main content</a> <a href="#main-content" className="skip-link">Skip to main content</a>
<Navbar config={config} currentLocale="en" /> <Navbar
config={config}
currentLocale="en"
categories={categories}
totalToolsCount={tools.length}
/>
<main id="main-content" className="flex-1">{children}</main> <main id="main-content" className="flex-1">{children}</main>
<Footer config={config} currentLocale="en" /> <Footer config={config} currentLocale="en" />
</SmoothScrollProvider> </SmoothScrollProvider>
+2 -10
View File
@@ -148,32 +148,27 @@ const CATEGORY_THEMES: Record<
icon: React.ReactNode; icon: React.ReactNode;
color: string; color: string;
badgeBg: string; badgeBg: string;
description: string;
} }
> = { > = {
'portrait-retouch': { 'portrait-retouch': {
icon: <Smile className="w-4 h-4 text-rose-500" />, icon: <Smile className="w-4 h-4 text-rose-500" />,
color: 'text-rose-600', color: 'text-rose-600',
badgeBg: 'bg-rose-500/10 text-rose-700 border-rose-500/20', badgeBg: 'bg-rose-500/10 text-rose-700 border-rose-500/20',
description: 'Sub-pore blemish removal, enamel whitening, redness clearing, and radiant studio lighting.',
}, },
'restoration': { 'restoration': {
icon: <Sparkles className="w-4 h-4 text-indigo-500" />, icon: <Sparkles className="w-4 h-4 text-indigo-500" />,
color: 'text-indigo-600', color: 'text-indigo-600',
badgeBg: 'bg-indigo-500/10 text-indigo-700 border-indigo-500/20', badgeBg: 'bg-indigo-500/10 text-indigo-700 border-indigo-500/20',
description: 'Super-resolution 4K deblurring, vintage scratch removal, and authentic archival colorization.',
}, },
'background-cutout': { 'background-cutout': {
icon: <Scissors className="w-4 h-4 text-emerald-500" />, icon: <Scissors className="w-4 h-4 text-emerald-500" />,
color: 'text-emerald-600', color: 'text-emerald-600',
badgeBg: 'bg-emerald-500/10 text-emerald-700 border-emerald-500/20', badgeBg: 'bg-emerald-500/10 text-emerald-700 border-emerald-500/20',
description: 'P3M deep learning alpha matting separating hair strands, semi-transparent glass, and edges.',
}, },
'creative-art': { 'creative-art': {
icon: <Palette className="w-4 h-4 text-amber-500" />, icon: <Palette className="w-4 h-4 text-amber-500" />,
color: 'text-amber-600', color: 'text-amber-600',
badgeBg: 'bg-amber-500/10 text-amber-700 border-amber-500/20', badgeBg: 'bg-amber-500/10 text-amber-700 border-amber-500/20',
description: 'Cel-shaded anime synthesis, vintage Polaroid emulsion borders, and object generative fill.',
}, },
}; };
@@ -856,8 +851,7 @@ export function ToolGridSection({
</span> </span>
</div> </div>
<p className="text-sm sm:text-base text-ink-2 font-body max-w-2xl mt-1.5 leading-relaxed"> <p className="text-sm sm:text-base text-ink-2 font-body max-w-2xl mt-1.5 leading-relaxed">
{CATEGORY_THEMES[activeCategoryItem.id]?.description || {resolveLocalised(activeCategoryItem.category?.description, locale)}
resolveLocalised(activeCategoryItem.category?.description, locale)}
</p> </p>
</div> </div>
</div> </div>
@@ -954,9 +948,7 @@ export function ToolGridSection({
const catName = group.category const catName = group.category
? resolveLocalised(group.category.name, locale) ? resolveLocalised(group.category.name, locale)
: group.id; : group.id;
const catDesc = const catDesc = group.category ? resolveLocalised(group.category.description, locale) : '';
theme?.description ||
(group.category ? resolveLocalised(group.category.description, locale) : '');
return ( return (
<div <div
+59 -62
View File
@@ -14,50 +14,33 @@ import {
Smile, Smile,
Scissors, Scissors,
Palette, Palette,
Wand2,
ChevronDown, ChevronDown,
ChevronRight ChevronRight
} from 'lucide-react'; } from 'lucide-react';
import { SiteConfig } from '@/types'; import { SiteConfig, CategoryItem, resolveLocalised } from '@/types';
import { BrandLogo } from './BrandLogo'; import { BrandLogo } from './BrandLogo';
import { RainbowButton } from '@/components/magicui/rainbow-button'; import { RainbowButton } from '@/components/magicui/rainbow-button';
interface NavbarProps { interface NavbarProps {
config: SiteConfig; config: SiteConfig;
currentLocale: string; currentLocale: string;
categories?: CategoryItem[];
totalToolsCount?: number;
} }
const TOOL_CATEGORIES = [ const ICON_MAP: Record<string, React.ComponentType<{ className?: string }>> = {
{ Smile,
id: 'portrait-retouch', Sparkles,
name: 'Portrait & Retouch', Scissors,
tagline: 'Blemish, teeth whitening & face swap', Palette,
icon: Smile, Wand2,
href: '/tools#category-portrait-retouch', Layers,
}, Smartphone,
{ ShieldCheck,
id: 'restoration', };
name: 'Enhance & Restore',
tagline: 'Deblur, 4K resolution & colorize',
icon: Sparkles,
href: '/tools#category-restoration',
},
{
id: 'background-cutout',
name: 'Cutout & Inpaint',
tagline: 'Object eraser & background remover',
icon: Scissors,
href: '/tools#category-background-cutout',
},
{
id: 'creative-art',
name: 'Creative & Diffusion',
tagline: 'Anime avatar, dress & text-to-image',
icon: Palette,
href: '/tools#category-creative-art',
},
];
export function Navbar({ config, currentLocale }: NavbarProps) { export function Navbar({ config, currentLocale, categories = [], totalToolsCount }: NavbarProps) {
const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
const [scrolled, setScrolled] = useState(false); const [scrolled, setScrolled] = useState(false);
const [toolsDropdownOpen, setToolsDropdownOpen] = useState(false); const [toolsDropdownOpen, setToolsDropdownOpen] = useState(false);
@@ -111,19 +94,29 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
}; };
}, [mobileMenuOpen]); }, [mobileMenuOpen]);
const navLinks = [ // Dynamic Navigation Items from JSON (PRD §5 CFG-01..04)
{ href: '/', label: 'Home', exact: true }, const navLinks = (config.nav?.header || []).map((item) => ({
{ href: '/tools', label: 'Tools', badge: '10+', hasDropdown: true }, href: item.href,
{ href: '/apps', label: 'Apps', badge: 'iOS · Mac' }, label: resolveLocalised(item.label, currentLocale),
{ href: '/pricing', label: 'Pricing' }, badge: item.badge,
{ href: '/trust', label: 'Trust & privacy' }, hasDropdown: item.hasDropdown ?? (item.href === '/tools'),
]; exact: item.href === '/',
}));
const isLinkActive = (href: string, exact?: boolean) => { const isLinkActive = (href: string, exact?: boolean) => {
if (exact) return pathname === href; if (exact) return pathname === href;
return pathname.startsWith(href); return pathname.startsWith(href);
}; };
const ctaLabel = resolveLocalised(config.nav?.cta?.label, currentLocale) || 'Try tools free';
const ctaHref = config.nav?.cta?.href || '/tools';
const viewAllText = config.nav?.toolsDropdown?.viewAllText
? resolveLocalised(config.nav.toolsDropdown.viewAllText, currentLocale)
: `Explore all ${totalToolsCount || ''} studio tools`;
const dropdownTagline = config.nav?.toolsDropdown?.tagline
? resolveLocalised(config.nav.toolsDropdown.tagline, currentLocale)
: 'Instant client GPU trial · Zero retention';
return ( return (
<header <header
className={`sticky top-0 left-0 right-0 w-full z-40 motion-safe:transition-[background-color,border-color,box-shadow] duration-200 bg-paper border-b border-rule shadow-xs ${ className={`sticky top-0 left-0 right-0 w-full z-40 motion-safe:transition-[background-color,border-color,box-shadow] duration-200 bg-paper border-b border-rule shadow-xs ${
@@ -168,20 +161,24 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
}`} /> }`} />
</Link> </Link>
{/* Tools Dropdown Menu - Sleek, Professional & Minimal */} {/* Tools Dropdown Menu - Sleek, Dynamic JSON-Driven */}
{toolsDropdownOpen && ( {toolsDropdownOpen && (
<div <div
className="absolute top-full left-1/2 -translate-x-1/2 pt-2.5 w-[320px] z-50 animate-in fade-in zoom-in-95 duration-150" className="absolute top-full left-1/2 -translate-x-1/2 pt-2.5 w-[320px] z-50 animate-in fade-in zoom-in-95 duration-150"
> >
<div className="p-2 rounded-2xl bg-paper-hi border border-rule shadow-xl space-y-1"> <div className="p-2 rounded-2xl bg-paper-hi border border-rule shadow-xl space-y-1">
{/* Categories List */} {/* Dynamic Categories List from JSON */}
<div className="space-y-0.5"> <div className="space-y-0.5">
{TOOL_CATEGORIES.map((cat) => { {categories.map((cat) => {
const Icon = cat.icon; const Icon = (cat.icon && ICON_MAP[cat.icon]) || Sparkles;
const catName = resolveLocalised(cat.name, currentLocale);
const catDesc = resolveLocalised(cat.description, currentLocale);
const catHref = `/tools#category-${cat.id}`;
return ( return (
<Link <Link
key={cat.id} key={cat.id}
href={cat.href} href={catHref}
onClick={() => { onClick={() => {
setToolsDropdownOpen(false); setToolsDropdownOpen(false);
if (typeof window !== 'undefined' && window.location.pathname.startsWith('/tools')) { if (typeof window !== 'undefined' && window.location.pathname.startsWith('/tools')) {
@@ -196,12 +193,12 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<span className="font-display font-semibold text-xs text-ink group-hover/item:text-accent transition-colors"> <span className="font-display font-semibold text-xs text-ink group-hover/item:text-accent transition-colors">
{cat.name} {catName}
</span> </span>
<ChevronRight className="w-3.5 h-3.5 text-muted opacity-0 -translate-x-1 group-hover/item:opacity-100 group-hover/item:translate-x-0 transition-all" /> <ChevronRight className="w-3.5 h-3.5 text-muted opacity-0 -translate-x-1 group-hover/item:opacity-100 group-hover/item:translate-x-0 transition-all" />
</div> </div>
<p className="text-[11px] text-muted truncate font-body"> <p className="text-[11px] text-muted truncate font-body">
{cat.tagline} {catDesc}
</p> </p>
</div> </div>
</Link> </Link>
@@ -212,11 +209,11 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
{/* Clean Minimal Footer */} {/* Clean Minimal Footer */}
<div className="pt-1.5 mt-1 border-t border-rule/70 px-2.5 py-1"> <div className="pt-1.5 mt-1 border-t border-rule/70 px-2.5 py-1">
<Link <Link
href="/tools" href={link.href}
onClick={() => setToolsDropdownOpen(false)} onClick={() => setToolsDropdownOpen(false)}
className="text-xs font-semibold text-accent hover:text-accent-hi inline-flex items-center justify-between w-full transition-colors py-1" className="text-xs font-semibold text-accent hover:text-accent-hi inline-flex items-center justify-between w-full transition-colors py-1"
> >
<span>Explore all 14 studio tools</span> <span>{viewAllText}</span>
<ArrowRight className="w-3.5 h-3.5" /> <ArrowRight className="w-3.5 h-3.5" />
</Link> </Link>
</div> </div>
@@ -254,11 +251,10 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
})} })}
</nav> </nav>
{/* Right CTA Actions */} {/* Right CTA Actions from JSON */}
<div className="hidden md:flex items-center gap-3 relative z-20 flex-shrink-0"> <div className="hidden md:flex items-center gap-3 relative z-20 flex-shrink-0">
{/* Rainbow Button CTA */} <RainbowButton href={ctaHref}>
<RainbowButton href="/tools"> <span>{ctaLabel}</span>
<span>Try tools free</span>
<ArrowRight className="w-3.5 h-3.5 ml-1 inline" aria-hidden="true" /> <ArrowRight className="w-3.5 h-3.5 ml-1 inline" aria-hidden="true" />
</RainbowButton> </RainbowButton>
</div> </div>
@@ -311,14 +307,17 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
</Link> </Link>
{/* Sub-categories under Tools on mobile drawer */} {/* Sub-categories under Tools on mobile drawer */}
{link.href === '/tools' && ( {link.href === '/tools' && categories.length > 0 && (
<div className="pl-3 pr-1 py-1 grid grid-cols-2 gap-1.5"> <div className="pl-3 pr-1 py-1 grid grid-cols-2 gap-1.5">
{TOOL_CATEGORIES.map((cat) => { {categories.map((cat) => {
const Icon = cat.icon; const Icon = (cat.icon && ICON_MAP[cat.icon]) || Sparkles;
const catName = resolveLocalised(cat.name, currentLocale);
const catHref = `/tools#category-${cat.id}`;
return ( return (
<Link <Link
key={cat.id} key={cat.id}
href={cat.href} href={catHref}
onClick={() => { onClick={() => {
setMobileMenuOpen(false); setMobileMenuOpen(false);
if (typeof window !== 'undefined' && window.location.pathname.startsWith('/tools')) { if (typeof window !== 'undefined' && window.location.pathname.startsWith('/tools')) {
@@ -328,7 +327,7 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
className="flex items-center gap-2 p-2 rounded-xl text-xs text-ink hover:text-accent hover:bg-paper-2 bg-paper-hi/60 border border-rule font-body transition-colors" className="flex items-center gap-2 p-2 rounded-xl text-xs text-ink hover:text-accent hover:bg-paper-2 bg-paper-hi/60 border border-rule font-body transition-colors"
> >
<Icon className="w-3.5 h-3.5 text-accent shrink-0" /> <Icon className="w-3.5 h-3.5 text-accent shrink-0" />
<span className="truncate font-medium">{cat.name}</span> <span className="truncate font-medium">{catName}</span>
</Link> </Link>
); );
})} })}
@@ -341,17 +340,15 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
<div className="pt-6 border-t border-rule space-y-3"> <div className="pt-6 border-t border-rule space-y-3">
<RainbowButton <RainbowButton
href="/tools" href={ctaHref}
onClick={() => setMobileMenuOpen(false)} onClick={() => setMobileMenuOpen(false)}
className="w-full text-center" className="w-full text-center"
> >
<span>Explore 10+ studio tools</span> <span>{ctaLabel}</span>
<ArrowRight className="w-4 h-4 ml-1 inline" aria-hidden="true" /> <ArrowRight className="w-4 h-4 ml-1 inline" aria-hidden="true" />
</RainbowButton> </RainbowButton>
<div className="flex items-center justify-center gap-4 text-xs text-muted font-body"> <div className="flex items-center justify-center gap-4 text-xs text-muted font-body">
<span>Zero server retention</span> <span>{dropdownTagline}</span>
<span>•</span>
<span>WebGPU acceleration</span>
</div> </div>
</div> </div>
</div> </div>
+1 -1
View File
@@ -167,7 +167,7 @@ export function getAppById(id: string): AppItem | null {
} }
export function getAllCategories(): CategoryItem[] { export function getAllCategories(): CategoryItem[] {
if (categoriesCache.size > 0) return Array.from(categoriesCache.values()); categoriesCache.clear();
const dir = path.join(CONTENT_DIR, 'collections', 'categories'); const dir = path.join(CONTENT_DIR, 'collections', 'categories');
if (fs.existsSync(dir)) { if (fs.existsSync(dir)) {
+6
View File
@@ -47,11 +47,17 @@ export interface SiteConfig {
label: Localised; label: Localised;
href: string; href: string;
children?: string; children?: string;
badge?: string;
hasDropdown?: boolean;
}>; }>;
cta: { cta: {
label: Localised; label: Localised;
href: string; href: string;
}; };
toolsDropdown?: {
viewAllText?: Localised;
tagline?: Localised;
};
}; };
footer: { footer: {
copyright: string; copyright: string;