Files
blog-nextjs/components/hero.tsx
gbanyan 0bb3ee40c6 Optimize performance: Replace Framer Motion and FontAwesome, convert Mastodon to Server Component
Major performance optimizations addressing PageSpeed Insights warnings:

**Phase 1: Replace Framer Motion with CSS (~60-100KB savings)**
- Remove Framer Motion from components/post-layout.tsx
- Add CSS transitions to styles/globals.css for TOC animations
- Replace motion.div/motion.button with regular elements + CSS classes
- Remove framer-motion package dependency

**Phase 2: Replace FontAwesome with React Icons (~150-250KB savings)**
- Replace FontAwesome in 16 components with react-icons
- Use Feather icons (react-icons/fi) for UI elements
- Use FontAwesome brand icons (react-icons/fa) for social media
- Remove 4 @fortawesome packages (@fortawesome/fontawesome-svg-core,
  @fortawesome/free-brands-svg-icons, @fortawesome/free-solid-svg-icons,
  @fortawesome/react-fontawesome)
- Updated components:
  - app/error.tsx, app/tags/page.tsx, app/tags/[tag]/page.tsx
  - components/hero.tsx, components/mastodon-feed.tsx
  - components/meta-item.tsx, components/nav-menu.tsx
  - components/post-card.tsx, components/post-layout.tsx
  - components/post-list-item.tsx, components/post-list-with-controls.tsx
  - components/post-storyline-nav.tsx, components/post-toc.tsx
  - components/right-sidebar.tsx, components/search-modal.tsx
  - components/site-footer.tsx, components/theme-toggle.tsx

**Phase 3: Convert Mastodon Feed to Server Component**
- Convert components/mastodon-feed.tsx from Client Component to async Server Component
- Replace client-side useEffect fetching with server-side ISR
- Add 30-minute revalidation (next: { revalidate: 1800 })
- Eliminate 2 blocking client-side network requests
- Remove loading state (rendered on server)

**Total Impact:**
- JavaScript bundle: ~210-350KB reduction
- Blocking network requests: 2 eliminated
- Main thread time: Reduced by ~100-160ms
- Build:  Verified successful

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 21:51:24 +08:00

94 lines
3.4 KiB
TypeScript

import { siteConfig } from '@/lib/config';
import { FaGithub, FaTwitter, FaMastodon, FaGit, FaLinkedin } from 'react-icons/fa';
import { FiMail, FiFeather } from 'react-icons/fi';
import { MetaItem } from './meta-item';
export function Hero() {
const { name, tagline, social } = siteConfig;
const initial = name?.charAt(0)?.toUpperCase() || 'G';
const items = [
social.github && {
key: 'github',
href: social.github,
label: 'GitHub',
icon: FaGithub
},
social.twitter && {
key: 'twitter',
href: `https://twitter.com/${social.twitter.replace('@', '')}`,
label: 'Twitter',
icon: FaTwitter
},
social.mastodon && {
key: 'mastodon',
href: social.mastodon,
label: 'Mastodon',
icon: FaMastodon
},
social.gitea && {
key: 'gitea',
href: social.gitea,
label: 'Gitea',
icon: FaGit
},
social.linkedin && {
key: 'linkedin',
href: social.linkedin,
label: 'LinkedIn',
icon: FaLinkedin
},
social.email && {
key: 'email',
href: `mailto:${social.email}`,
label: 'Email',
icon: FiMail
}
].filter(Boolean) as {
key: string;
href: string;
label: string;
icon: any;
}[];
return (
<section className="motion-card group relative mb-8 overflow-hidden rounded-xl border bg-gradient-to-r from-sky-50 via-indigo-50 to-slate-50 px-6 py-6 shadow-sm dark:border-slate-800 dark:from-slate-900 dark:via-slate-950 dark:to-slate-900">
<div className="pointer-events-none absolute -left-16 -top-16 h-40 w-40 rounded-full bg-sky-300/40 blur-3xl mix-blend-soft-light motion-safe:animate-float-soft dark:bg-sky-500/25" />
<div className="pointer-events-none absolute -bottom-20 right-[-3rem] h-44 w-44 rounded-full bg-indigo-300/35 blur-3xl mix-blend-soft-light motion-safe:animate-float-soft dark:bg-indigo-500/25" />
<div className="relative flex items-center gap-4 motion-safe:animate-fade-in-up">
<div className="flex h-16 w-16 items-center justify-center rounded-full bg-slate-900 text-xl font-semibold text-slate-50 shadow-md transition-transform duration-300 ease-out group-hover:scale-105 dark:bg-slate-100 dark:text-slate-900">
{initial}
</div>
<div>
<h1 className="hero-title type-display font-bold tracking-tight">
<span className="hero-title__sweep" aria-hidden="true" />
{name}
</h1>
<div className="mt-1">
<MetaItem icon={FiFeather}>
{tagline}
</MetaItem>
</div>
{items.length > 0 && (
<div className="mt-3 flex flex-wrap items-center gap-3 text-xs text-slate-500">
{items.map((item) => (
<a
key={item.key}
href={item.href}
target="_blank"
rel="noopener noreferrer"
className="motion-link flex items-center gap-2 rounded-full bg-white/80 px-3 py-1 text-slate-600 shadow-sm ring-1 ring-slate-200 hover:-translate-y-0.5 hover:bg-accent-soft hover:text-accent hover:shadow-md dark:bg-slate-900/80 dark:text-slate-200 dark:ring-slate-700"
>
<item.icon className="h-3.5 w-3.5 text-accent" />
<span>{item.label}</span>
</a>
))}
</div>
)}
</div>
</div>
</section>
);
}