|
| 1 | +import { useTranslation } from 'next-i18next' |
| 2 | +import Image from 'next/image' |
| 3 | +import Container from './Container' |
| 4 | +import Link from 'next/link' |
| 5 | +import UAParser from 'ua-parser-js' |
| 6 | +import androidSvg from '../public/images/platform/android.svg' |
| 7 | +import linuxSvg from '../public/images/platform/linux.svg' |
| 8 | +import macosSvg from '../public/images/platform/macos.svg' |
| 9 | +import windowsSvg from '../public/images/platform/windows.svg' |
| 10 | +import { useEffect, useState } from 'react' |
| 11 | + |
| 12 | +const HeroSection = ({ release }) => { |
| 13 | + const [downloadUrl, setDownloadUrl] = useState('') |
| 14 | + useEffect(() => { |
| 15 | + const parser = new UAParser() |
| 16 | + const os = parser.getOS().name |
| 17 | + const ua = { |
| 18 | + arch: parser.getCPU().architecture, |
| 19 | + } |
| 20 | + if (os.includes('Windows')) { |
| 21 | + ua.os = 'windows' |
| 22 | + } |
| 23 | + if (os.includes('Mac')) { |
| 24 | + ua.os = 'macos' |
| 25 | + } |
| 26 | + if (os.includes('Linux')) { |
| 27 | + ua.os = 'linux' |
| 28 | + } |
| 29 | + if (os.includes('Android')) { |
| 30 | + ua.os = 'android' |
| 31 | + } |
| 32 | + |
| 33 | + const osAssert = release.assert[ua.os] |
| 34 | + // first match os and arch |
| 35 | + if (osAssert?.[ua.arch]) { |
| 36 | + setDownloadUrl(osAssert[ua.arch]) |
| 37 | + return |
| 38 | + } |
| 39 | + // second match os |
| 40 | + if (osAssert) { |
| 41 | + setDownloadUrl(osAssert[Object.keys(osAssert)[0]]) |
| 42 | + return |
| 43 | + } |
| 44 | + // no match, fallback to github latest release |
| 45 | + setDownloadUrl('https://github.com/GopeedLab/gopeed/releases/latest') |
| 46 | + }, [release.assert]) |
| 47 | + |
| 48 | + const { t } = useTranslation('common') |
| 49 | + return ( |
| 50 | + <div className="relative" id="home"> |
| 51 | + <div className="absolute inset-x-0 top-32 lg:hidden"> |
| 52 | + <div aria-hidden="true" className="grid grid-cols-2 -space-x-52 opacity-50 dark:opacity-60 2xl:mx-auto 2xl:max-w-6xl"> |
| 53 | + <div className="h-60 bg-gradient-to-br from-primary to-purple-400 blur-3xl dark:from-blue-700"></div> |
| 54 | + <div className="h-72 rounded-full bg-gradient-to-r from-cyan-400 to-sky-300 blur-3xl dark:from-transparent dark:to-indigo-600"></div> |
| 55 | + </div> |
| 56 | + </div> |
| 57 | + <Container> |
| 58 | + <div className="relative pt-36 ml-auto"> |
| 59 | + <div className="gap-12 md:flex md:items-center"> |
| 60 | + <div className="text-center sm:px-12 md:w-2/3 md:px-0 md:text-left lg:w-1/2"> |
| 61 | + <h1 className="text-3xl font-black dark:text-white lg:text-5xl">{t('home.title')}</h1> |
| 62 | + <div> |
| 63 | + <p className="mt-8 text-lg text-gray-700 dark:text-gray-100">{t('home.desc')}</p> |
| 64 | + <div className="mt-12 flex justify-center gap-4 sm:gap-6 md:justify-start"> |
| 65 | + <Link |
| 66 | + href={downloadUrl} |
| 67 | + className="relative flex h-12 w-full items-center justify-center px-6 before:absolute before:inset-0 before:rounded-lg before:bg-primary before:transition before:duration-300 hover:before:scale-105 active:duration-75 active:before:scale-95 sm:w-max" |
| 68 | + > |
| 69 | + <span className="relative text-base font-semibold text-white normal-case">{t('download')}</span> |
| 70 | + </Link> |
| 71 | + <Link |
| 72 | + href="https://github.com/GopeedLab/gopeed/releases/latest" |
| 73 | + className="relative flex h-12 w-full items-center justify-center px-6 before:absolute before:inset-0 before:rounded-lg before:border before:border-transparent before:bg-primary/10 before:bg-gradient-to-b before:transition before:duration-300 hover:before:scale-105 active:duration-75 active:before:scale-95 dark:before:border-gray-800 dark:before:bg-gray-900 sm:w-max" |
| 74 | + > |
| 75 | + <span className="relative text-base font-semibold text-primary dark:text-white">{t('downloadMore')}</span> |
| 76 | + </Link> |
| 77 | + </div> |
| 78 | + </div> |
| 79 | + </div> |
| 80 | + <div className="relative mt-20 md:mt-0 md:w-2/5 lg:w-3/5"> |
| 81 | + <div className="md:-mr-72 lg:mr-0"> |
| 82 | + <Image className="h-full object-cover" priority src="/images/ui.png" alt="screenshot" width="1628" height="1233" /> |
| 83 | + </div> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + <div className="hidden py-8 mt-16 border-y border-gray-100 dark:border-gray-800 sm:flex justify-between"> |
| 87 | + <div className="text-left"> |
| 88 | + <h6 className="text-lg font-semibold text-gray-700 dark:text-white">{t('home.feat1.title')}</h6> |
| 89 | + <p className="mt-2 text-gray-500">{t('home.feat1.desc')}</p> |
| 90 | + </div> |
| 91 | + <div className="text-left"> |
| 92 | + <h6 className="text-lg font-semibold text-gray-700 dark:text-white">{t('home.feat2.title')}</h6> |
| 93 | + <p className="mt-2 text-gray-500">{t('home.feat2.desc')}</p> |
| 94 | + </div> |
| 95 | + <div className="text-left"> |
| 96 | + <h6 className="text-lg font-semibold text-gray-700 dark:text-white">{t('home.feat3.title')}</h6> |
| 97 | + <p className="mt-2 text-gray-500">{t('home.feat3.desc')}</p> |
| 98 | + </div> |
| 99 | + </div> |
| 100 | + </div> |
| 101 | + </Container> |
| 102 | + </div> |
| 103 | + ) |
| 104 | +} |
| 105 | + |
| 106 | +export default HeroSection |
0 commit comments