refactor: optimize project structure and clean up code
- Split Banner.tsx into reusable components (Header, Footer, NavCard) - Extract custom hooks: useTypewriter, useParallax - Separate navigation data from components into data/navigation.ts - Add TypeScript types (NavItem) for type safety - Configure @ path alias in tsconfig.app.json for consistency - Remove unused dependencies: radix-ui, react-helmet-async - Organize components into layout/ and ui/ directories
This commit is contained in:
1 parent
73788ad2d2
commit
3539cb04e9
15 files changed
+911
-2766
No files matched your search
+17
-105
@@ -1,82 +1,29 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import {
|
||||
Code2,
|
||||
Mail,
|
||||
LayoutDashboard,
|
||||
GitFork,
|
||||
ChevronDown
|
||||
} from "lucide-react";
|
||||
import bannerImg from "../assets/banner.png";
|
||||
import { useTypewriter } from "@/hooks/useTypewriter";
|
||||
import { useParallax } from "@/hooks/useParallax";
|
||||
import { NAV_ITEMS } from "@/data/navigation";
|
||||
import Header from "@/components/layout/Header";
|
||||
import Footer from "@/components/layout/Footer";
|
||||
import NavCard from "@/components/NavCard";
|
||||
import bannerImg from "@/assets/banner.png";
|
||||
|
||||
const FULL_TEXT = "Xiaozhou's Website";
|
||||
|
||||
export default function Banner() {
|
||||
const fullText = "Xiaozhou's Website";
|
||||
const [text, setText] = useState("");
|
||||
const [offset, setOffset] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
let i = 0;
|
||||
const timer = setInterval(() => {
|
||||
setText(fullText.slice(0, i + 1));
|
||||
i++;
|
||||
if (i === fullText.length) clearInterval(timer);
|
||||
}, 100);
|
||||
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const handleScroll = () => {
|
||||
setOffset(window.scrollY * 0.25);
|
||||
};
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
return () => window.removeEventListener("scroll", handleScroll);
|
||||
}, []);
|
||||
|
||||
const navItems = [
|
||||
{
|
||||
name: "Blog",
|
||||
desc: "技术随笔与生活记录",
|
||||
path: "https://blog.xiaozhou233.cn",
|
||||
icon: <LayoutDashboard className="text-emerald-400" size={36} />,
|
||||
borderHover: "hover:border-emerald-500/50 hover:shadow-[0_0_20px_rgba(52,211,153,0.2)]"
|
||||
},
|
||||
{
|
||||
name: "Git",
|
||||
desc: "开源项目与代码托管",
|
||||
path: "https://git.xiaozhou233.cn",
|
||||
icon: <GitFork className="text-blue-400" size={36} />,
|
||||
borderHover: "hover:border-blue-500/50 hover:shadow-[0_0_20px_rgba(96,165,250,0.2)]"
|
||||
}
|
||||
];
|
||||
const text = useTypewriter(FULL_TEXT, 100);
|
||||
const parallaxRef = useParallax(0.25);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={parallaxRef}
|
||||
className="relative w-full h-screen flex flex-col justify-between text-white overflow-hidden font-mono select-none"
|
||||
style={{
|
||||
backgroundImage: `url(${bannerImg})`,
|
||||
backgroundSize: "cover",
|
||||
backgroundPosition: `center ${-offset}px`,
|
||||
}}
|
||||
>
|
||||
<div className="absolute inset-0 bg-black/45 pointer-events-none" />
|
||||
|
||||
<header className="relative z-10 w-full px-6 py-4 flex justify-between items-center bg-linear-to-b from-black/60 to-transparent">
|
||||
<div className="text-emerald-400 font-medium tracking-tight text-sm md:text-base">
|
||||
root@Xiaozhou:~#
|
||||
</div>
|
||||
|
||||
|
||||
<div className="flex items-center gap-4 text-gray-400">
|
||||
<a href="https://github.com" target="_blank" rel="noopener noreferrer" className="hover:text-white transition-colors" title="GitHub">
|
||||
<svg className="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
||||
<path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4" />
|
||||
<path d="M9 18c-4.51 2-5-2-7-2" />
|
||||
</svg>
|
||||
</a>
|
||||
<a href="#" className="hover:text-white transition-colors" title="Code"><Code2 size={20} /></a>
|
||||
<a href="#" className="hover:text-white transition-colors" title="Contact"><Mail size={20} /></a>
|
||||
</div>
|
||||
</header>
|
||||
<Header />
|
||||
|
||||
<main className="relative z-10 flex-1 flex flex-col items-center justify-center px-4 -translate-y-4">
|
||||
<h1 className="text-5xl md:text-7xl lg:text-8xl font-extrabold tracking-tighter text-transparent bg-clip-text bg-linear-to-r from-emerald-50 via-white to-emerald-50 drop-shadow-[0_0_15px_rgba(52,211,153,0.4)]">
|
||||
@@ -91,48 +38,13 @@ export default function Banner() {
|
||||
<div className="w-12 h-0.5 bg-emerald-500 mt-5 shadow-[0_0_8px_#10b981]" />
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-5 gap-6 mt-14 w-full max-w-6xl px-4">
|
||||
{navItems.map((item, index) => (
|
||||
<a
|
||||
key={index}
|
||||
href={item.path}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className={`flex items-center md:flex-col md:text-center gap-5 md:gap-4 p-6 md:py-8 rounded-2xl bg-black/35 backdrop-blur-md border border-white/5 transition-all duration-300 cursor-pointer hover:-translate-y-1 hover:bg-black/45 ${item.borderHover} group block`}
|
||||
>
|
||||
<div className="shrink-0 transition-transform duration-300 group-hover:scale-105">
|
||||
{item.icon}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col min-w-0 items-start md:items-center">
|
||||
<span className="text-xl md:text-3xl font-bold tracking-tight text-gray-100 transition-colors group-hover:text-white">
|
||||
{item.name}
|
||||
</span>
|
||||
<span className="text-xs md:text-sm text-gray-400/80 mt-1.5 tracking-wide line-clamp-1 group-hover:text-gray-300 transition-colors font-sans">
|
||||
{item.desc}
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
{NAV_ITEMS.map((item) => (
|
||||
<NavCard key={item.name} item={item} />
|
||||
))}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer className="relative z-10 w-full pb-6 flex flex-col items-center justify-center gap-4 bg-linear-to-t from-black/40 to-transparent">
|
||||
<div className="animate-bounce">
|
||||
<ChevronDown size={26} className="text-emerald-400/50 cursor-pointer hover:text-emerald-400 transition-colors" />
|
||||
</div>
|
||||
|
||||
<div className="text-xs md:text-sm text-gray-400/70 tracking-wide font-sans flex items-center gap-1.5 selection:bg-emerald-500/30">
|
||||
<span className="text-red-500 animate-pulse">❤</span>
|
||||
<span>Built with</span>
|
||||
<span className="text-gray-200 font-medium hover:text-cyan-400 transition-colors duration-300 cursor-pointer">
|
||||
React
|
||||
</span>
|
||||
<span>&</span>
|
||||
<span className="text-gray-200 font-medium hover:text-sky-400 transition-colors duration-300 cursor-pointer">
|
||||
Tailwind CSS
|
||||
</span>
|
||||
</div>
|
||||
</footer>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Helmet } from "react-helmet-async";
|
||||
|
||||
type HeaderProps = {
|
||||
title: string;
|
||||
};
|
||||
|
||||
export default function Header({ title }: HeaderProps) {
|
||||
return (
|
||||
<Helmet>
|
||||
<title>{title}</title>
|
||||
</Helmet>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import type { NavItem } from "@/types";
|
||||
|
||||
interface NavCardProps {
|
||||
item: NavItem;
|
||||
}
|
||||
|
||||
export default function NavCard({ item }: NavCardProps) {
|
||||
const { name, desc, path, Icon, color, borderHover } = item;
|
||||
|
||||
return (
|
||||
<a
|
||||
href={path}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className={`flex items-center md:flex-col md:text-center gap-5 md:gap-4 p-6 md:py-8 rounded-2xl bg-black/35 backdrop-blur-md border border-white/5 transition-all duration-300 cursor-pointer hover:-translate-y-1 hover:bg-black/45 ${borderHover} group block`}
|
||||
>
|
||||
<div className="shrink-0 transition-transform duration-300 group-hover:scale-105">
|
||||
<Icon className={color} size={36} />
|
||||
</div>
|
||||
<div className="flex flex-col min-w-0 items-start md:items-center">
|
||||
<span className="text-xl md:text-3xl font-bold tracking-tight text-gray-100 transition-colors group-hover:text-white">
|
||||
{name}
|
||||
</span>
|
||||
<span className="text-xs md:text-sm text-gray-400/80 mt-1.5 tracking-wide line-clamp-1 group-hover:text-gray-300 transition-colors font-sans">
|
||||
{desc}
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { ChevronDown } from "lucide-react";
|
||||
|
||||
export default function Footer() {
|
||||
return (
|
||||
<footer className="relative z-10 w-full pb-6 flex flex-col items-center justify-center gap-4 bg-linear-to-t from-black/40 to-transparent">
|
||||
<div className="animate-bounce">
|
||||
<ChevronDown size={26} className="text-emerald-400/50 cursor-pointer hover:text-emerald-400 transition-colors" />
|
||||
</div>
|
||||
<div className="text-xs md:text-sm text-gray-400/70 tracking-wide font-sans flex items-center gap-1.5 selection:bg-emerald-500/30">
|
||||
<span className="text-red-500 animate-pulse">❤</span>
|
||||
<span>Built with</span>
|
||||
<span className="text-gray-200 font-medium hover:text-cyan-400 transition-colors duration-300 cursor-pointer">React</span>
|
||||
<span>&</span>
|
||||
<span className="text-gray-200 font-medium hover:text-sky-400 transition-colors duration-300 cursor-pointer">Tailwind CSS</span>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Code2, Mail } from "lucide-react";
|
||||
|
||||
export default function Header() {
|
||||
return (
|
||||
<header className="relative z-10 w-full px-6 py-4 flex justify-between items-center bg-linear-to-b from-black/60 to-transparent">
|
||||
<div className="text-emerald-400 font-medium tracking-tight text-sm md:text-base">
|
||||
root@Xiaozhou:~#
|
||||
</div>
|
||||
<div className="flex items-center gap-4 text-gray-400">
|
||||
<a href="https://github.com" target="_blank" rel="noopener noreferrer" className="hover:text-white transition-colors" title="GitHub">
|
||||
<svg className="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
||||
<path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4" />
|
||||
<path d="M9 18c-4.51 2-5-2-7-2" />
|
||||
</svg>
|
||||
</a>
|
||||
<a href="#" className="hover:text-white transition-colors" title="Code"><Code2 size={20} /></a>
|
||||
<a href="#" className="hover:text-white transition-colors" title="Contact"><Mail size={20} /></a>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user