// import Image from 'next/image' import { ArrowSmallRight, PlusSmall } from '@/components/HeroIcons' import LazyImage from '@/components/LazyImage' import { siteConfig } from '@/lib/config' import Link from 'next/link' import { useRouter } from 'next/router' import { useImperativeHandle, useRef, useState } from 'react' import CONFIG from '../config' /** * 顶部英雄区 * 左右布局, * 左侧:banner组 * 右侧:今日卡牌遮罩 * @returns */ const Hero = props => { const HEO_HERO_REVERSE = siteConfig('HEO_HERO_REVERSE', false, CONFIG) return (
{/* 左侧banner组 */} {/* 中间留白 */}
{/* 右侧置顶文章组 */}
) } /** * 英雄区左侧banner组 * @returns */ function BannerGroup(props) { return ( // 左侧英雄区
{/* 动图 */} {/* 导航分类 */}
) } /** * 英雄区左上角banner动图 * @returns */ function Banner(props) { const router = useRouter() const { latestPosts } = props /** * 随机跳转文章 */ function handleClickBanner() { const randomIndex = Math.floor(Math.random() * latestPosts.length) const randomPost = latestPosts[randomIndex] router.push(`${siteConfig('SUB_PATH', '')}/${randomPost?.slug}`) } return (
{/* 斜向滚动的图标 */} {/* 遮罩 */}
) } /** * 图标滚动标签组 * 英雄区左上角banner条中斜向滚动的图标 */ function TagsGroupBar() { const groupIcons = siteConfig('HEO_GROUP_ICONS', null, CONFIG).concat(siteConfig('HEO_GROUP_ICONS', null, CONFIG)) return (
{groupIcons?.map((g, index) => { return (
) })}
) } /** * 英雄区左下角3个指定分类按钮 * @returns */ function GroupMenu() { return (
{siteConfig('HEO_HERO_CATEGORY_1', null, CONFIG)?.title}
{siteConfig('HEO_HERO_CATEGORY_2', null, CONFIG)?.title}
{/* 第三个标签在小屏上不显示 */}
{siteConfig('HEO_HERO_CATEGORY_3', null, CONFIG)?.title}
) } /** * 置顶文章区域 */ function TopGroup(props) { const { latestPosts, allNavPages, siteInfo } = props const todayCardRef = useRef() function handleMouseLeave() { todayCardRef.current.coverUp() } // 获取置顶推荐文章 const topPosts = getTopPosts({ latestPosts, allNavPages }) return (
{/* 置顶推荐文章 */}
{topPosts?.map((p, index) => { return (
{p?.title}
{/* hover 悬浮的 ‘荐’ 字 */}
) })}
) } /** * 获取推荐置顶文章 */ function getTopPosts({ latestPosts, allNavPages }) { // 默认展示最近更新 if ( !siteConfig('HEO_HERO_RECOMMEND_POST_TAG', null, CONFIG) || siteConfig('HEO_HERO_RECOMMEND_POST_TAG', null, CONFIG) === '' ) { return latestPosts } // 显示包含‘推荐’标签的文章 let sortPosts = [] // 排序方式 if (JSON.parse(siteConfig('HEO_HERO_RECOMMEND_POST_SORT_BY_UPDATE_TIME', null, CONFIG))) { sortPosts = Object.create(allNavPages).sort((a, b) => { const dateA = new Date(a?.lastEditedDate) const dateB = new Date(b?.lastEditedDate) return dateB - dateA }) } else { sortPosts = Object.create(allNavPages) } const topPosts = [] for (const post of sortPosts) { if (topPosts.length === 6) { break } // 查找标签 if (post?.tags?.indexOf(siteConfig('HEO_HERO_RECOMMEND_POST_TAG', null, CONFIG)) >= 0) { topPosts.push(post) } } return topPosts } /** * 英雄区右侧,今日卡牌 * @returns */ function TodayCard({ cRef, siteInfo }) { const router = useRouter() // 卡牌是否盖住下层 const [isCoverUp, setIsCoverUp] = useState(true) /** * 外部可以调用此方法 */ useImperativeHandle(cRef, () => { return { coverUp: () => { setIsCoverUp(true) } } }) /** * 点击更多 * @param {*} e */ function handleClickMore(e) { e.stopPropagation() setIsCoverUp(false) } /** * 点击卡片跳转的链接 * @param {*} e */ function handleCardClick(e) { router.push(siteConfig('HEO_HERO_TITLE_LINK', null, CONFIG)) } return ( ) } export default Hero