nomadro/apps/ebook/src/components/CoverPage.tsx
eric 626f6b19e8 Ship unified miniprogram H5/weapp parity and XHS offline portal.
Align Taro pages with Next hub/nav/book/community/VIP, pack the single-index Xiaohongshu portal with host-chrome safe areas, and refresh shared book content plus portal README constraints.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-30 09:37:03 +08:00

198 lines
7.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import Link from 'next/link';
import type { Book } from '@ebook/lib/book-types';
import type { SiteConfig } from '@ebook/lib/site-types';
import { ContinueReading } from './ContinueReading';
import { InsightCarousel } from './InsightCarousel';
import { AnimatedCounter } from './AnimatedCounter';
import { ShareToX } from './ShareToX';
import { ScrollReveal } from './ScrollReveal';
import { SkillRadar } from './SkillRadar';
import { CoverChapterGrid } from './CoverChapterGrid';
import { CoverStickyCta, SiteFooter } from './GrowthKit';
import { CryptoSupport } from './CryptoSupport';
import { BuyEbook } from './BuyEbook';
import { AdSlot } from './AdSlot';
import { getBookShareText, getBookShareUrl } from '@ebook/lib/share-text';
import { trackEvent } from '@ebook/lib/analytics';
import { useEffect } from 'react';
import { isEnabled } from '@ebook/lib/features';
import { useT } from '@ebook/components/LocaleProvider';
import { LocaleSwitcher } from '@ebook/components/LocaleSwitcher';
import { ThemeToggle } from '@ebook/components/ThemeToggle';
import { useBookRoutes } from '@ebook/components/BookRoutes';
function CoverHomeLogo() {
const { home } = useBookRoutes();
return (
<Link href={home} className="cover-home-logo" aria-label="返回首页">
<svg className="cover-home-mark" viewBox="0 0 40 40" fill="none" aria-hidden>
<circle cx="20" cy="20" r="18" stroke="url(#coverLogoGrad)" strokeWidth="2.5" />
<path
d="M12 22c4-8 12-8 16 0"
stroke="url(#coverLogoGrad)"
strokeWidth="2"
strokeLinecap="round"
/>
<circle cx="28" cy="14" r="3" fill="url(#coverLogoGrad)" />
<defs>
<linearGradient id="coverLogoGrad" x1="0" y1="0" x2="40" y2="40">
<stop offset="0%" stopColor="#FF6B6B" />
<stop offset="50%" stopColor="#FFE66D" />
<stop offset="100%" stopColor="#4ECDC4" />
</linearGradient>
</defs>
</svg>
<span className="cover-home-brand">nomadro</span>
<span className="cover-home-sep" aria-hidden>
·
</span>
<span className="cover-home-section">小册</span>
</Link>
);
}
export function CoverPage({
book,
site,
chapterMinutes,
coverAdSlot = '',
}: {
book: Book;
site: SiteConfig;
chapterMinutes?: Record<string, number>;
coverAdSlot?: string;
}) {
const t = useT();
const shareText = getBookShareText(book);
useEffect(() => {
if (isEnabled.analytics()) trackEvent('cover_view');
}, []);
return (
<>
<header className="cover-topbar">
<CoverHomeLogo />
<div className="cover-top-actions">
<ThemeToggle variant="cover" />
<LocaleSwitcher variant="cover" />
</div>
</header>
<div className="viral-cover relative min-h-screen overflow-hidden">
<div className="viral-cover-bg" aria-hidden>
<div className="hero-orb orb-1" />
<div className="hero-orb orb-2" />
<div className="hero-orb orb-3" />
<div className={`viral-cover-gradient bg-gradient-to-br ${book.coverGradient}`} />
<div className="viral-grid" />
</div>
<div className="relative mx-auto w-full max-w-6xl px-4 py-10 sm:px-6 sm:py-14 lg:py-16">
<ScrollReveal>
<div className="flex flex-wrap items-center justify-center gap-2 lg:justify-start">
{book.viralTags.map((tag) => (
<span key={tag} className="viral-tag">
#{tag}
</span>
))}
</div>
</ScrollReveal>
<div className="mt-8 grid items-center gap-10 lg:grid-cols-[1.1fr_0.9fr] lg:gap-14">
<div className="text-center lg:text-left">
<ScrollReveal delay={60}>
<h1 className="viral-title">{book.title}</h1>
<p className="viral-subtitle">{book.subtitle}</p>
<p className="viral-desc">{book.description}</p>
</ScrollReveal>
<ScrollReveal delay={120}>
<div className="viral-stats">
{book.stats.map((stat) => (
<div key={stat.label} className="viral-stat-card">
<span className="viral-stat-emoji">{stat.emoji}</span>
<AnimatedCounter value={stat.value} />
<span className="viral-stat-label">{stat.label}</span>
</div>
))}
</div>
</ScrollReveal>
<ScrollReveal delay={180}>
<ContinueReading book={book} chapterMinutes={chapterMinutes} />
<div className="mt-4 flex flex-wrap items-center justify-center gap-3 lg:justify-start">
<ShareToX text={shareText} url={getBookShareUrl()} label={t('cover.shareX')} />
</div>
</ScrollReveal>
<ScrollReveal delay={240}>
<p className="viral-tagline">「{book.tagline}」</p>
</ScrollReveal>
</div>
<ScrollReveal delay={100} className="mx-auto w-full max-w-sm space-y-6 lg:max-w-md">
<SkillRadar />
<div className="viral-book-card">
<div className="viral-book-card-glow" aria-hidden />
<div className="viral-book-card-inner">
<p className="text-xs uppercase tracking-[0.3em] text-white/50">Digital Nomad × Homelab</p>
<div className="mt-auto pt-16">
<p className="text-sm text-white/60">by {book.author}</p>
<h2 className="mt-2 font-serif text-4xl font-bold text-white">{book.title}</h2>
<p className="mt-3 text-white/75">{book.subtitle}</p>
<ul className="mt-6 space-y-2">
{book.chapters.slice(0, 4).map((ch) => (
<li key={ch.slug} className="flex items-center gap-2 text-sm text-white/70">
<span>{ch.emoji}</span>
<span className="truncate">{ch.title}</span>
</li>
))}
<li className="text-sm text-white/45">{t('cover.moreChapters', { n: book.chapters.length - 4 })}</li>
</ul>
</div>
</div>
</div>
</ScrollReveal>
</div>
<ScrollReveal delay={200}>
<InsightCarousel hooks={book.hooks} />
</ScrollReveal>
<ScrollReveal delay={260}>
<CoverChapterGrid book={book} chapterMinutes={chapterMinutes} />
</ScrollReveal>
{isEnabled.checkoutPay() && (
<ScrollReveal delay={270}>
<BuyEbook />
</ScrollReveal>
)}
{isEnabled.cryptoPay() && (
<ScrollReveal delay={280}>
<CryptoSupport />
</ScrollReveal>
)}
{isEnabled.ads() && coverAdSlot && (
<ScrollReveal delay={300}>
<AdSlot slotId={coverAdSlot} className="cover-ad-slot" label={t('cover.sponsor')} />
</ScrollReveal>
)}
<SiteFooter
bookTitle={book.title}
contactEmail={site.brand.contactEmail}
xHandle={site.brand.xHandle}
/>
</div>
<CoverStickyCta book={book} />
</div>
</>
);
}