import { useState } from 'react'; import { catalog, samples } from 'virtual:tutorial-catalog'; import { DOCS_URL, GITHUB_URL, messages, trackInfo } from '../i18n'; import { ArrowRight, BookOpen, FileCode, Github, Globe, Terminal } from '../icons'; import { preferredLocale, rememberLocale, useTheme } from '../prefs'; import { href, onLinkClick } from '../router'; import type { Locale, Track } from '../types'; import { IconButton, LocaleButton, Logo, ThemeButton } from './common'; const TRACKS: Track[] = ['class', 'function']; const HOW_ICONS = [BookOpen, FileCode, Globe]; /** 教程首页:介绍 + 选择写法。 */ export function Landing() { const [locale, setLocale] = useState(preferredLocale); const [theme, toggleTheme] = useTheme(); const t = messages[locale]; const switchLocale = () => { const next = locale === 'zh-cn' ? 'en' : 'zh-cn'; rememberLocale(next); setLocale(next); }; return (
{t.docs}
{t.heroEyebrow}

{t.heroTitleA} {t.heroTitleB}

{t.heroDesc}

{t.chooseTrack}

{TRACKS.map(track => { const entry = catalog.find(c => c.track === track && c.locale === locale)!; const info = trackInfo[track][locale]; const count = entry.parts.reduce((n, p) => n + p.lessons.length, 0); const first = entry.parts[0]; const to = href(track, locale, first.slug, first.lessons[0].slug); return (

{info.name}

{info.desc}

{t.lessons(count)}
    {entry.parts.map(part => (
  1. {part.title}
  2. ))}
{t.start}
); })}

{t.howTitle}

{t.how.map((step, i) => { const StepIcon = HOW_ICONS[i]; return (

0{i + 1} {step.title}

{step.desc}

); })}
); }