Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Sep 23, 2024
2 parents 6294046 + 6b4ed37 commit 68a6352
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 6 deletions.
22 changes: 19 additions & 3 deletions themes/gitbook/components/NavPostItem.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Badge from '@/components/Badge'
import Collapse from '@/components/Collapse'
import { siteConfig } from '@/lib/config'
import { useEffect, useState } from 'react'
import CONFIG from '../config'
import BlogPostCard from './BlogPostCard'

Expand All @@ -13,17 +14,32 @@ import BlogPostCard from './BlogPostCard'
*/
const NavPostItem = props => {
const { group, expanded, toggleItem } = props // 接收传递的展开状态和切换函数
// const [isOpen, setIsOpen] = useState(expanded) // 使用展开状态作为组件内部状态
const hoverExpand = siteConfig('GITBOOK_FOLDER_HOVER_EXPAND', false, CONFIG)
const [isTouchDevice, setIsTouchDevice] = useState(false)

// 检测是否为触摸设备
useEffect(() => {
const checkTouchDevice = () => {
if (window.matchMedia('(pointer: coarse)').matches) {
setIsTouchDevice(true)
}
}
checkTouchDevice()

// 可选:监听窗口大小变化时重新检测
window.addEventListener('resize', checkTouchDevice)
return () => {
window.removeEventListener('resize', checkTouchDevice)
}
}, [])

// 当展开状态改变时触发切换函数,并根据传入的展开状态更新内部状态
const toggleOpenSubMenu = () => {
toggleItem() // 调用父组件传递的切换函数
// setIsOpen(!expanded) // 更新内部状态为传入的展开状态的相反值
}
const onHoverToggle = () => {
// 允许鼠标悬停时自动展开,而非点击展开
if (!hoverExpand) {
if (!hoverExpand || isTouchDevice) {
return
}
toggleOpenSubMenu()
Expand Down
4 changes: 3 additions & 1 deletion themes/magzine/components/InfoCard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import LazyImage from '@/components/LazyImage'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import { useRouter } from 'next/router'

/**
* 用户信息卡
Expand All @@ -9,14 +10,15 @@ import { useGlobal } from '@/lib/global'
*/
const InfoCard = props => {
const { siteInfo } = useGlobal()
const router = useRouter()

return (
<div id='info-card'>
<div className='items-center justify-start'>
<div
className='hover:scale-105 transform duration-200 cursor-pointer flex justify-start'
onClick={() => {
Router.push('/about')
router.push('/about')
}}>
<LazyImage
src={siteInfo?.icon}
Expand Down
1 change: 0 additions & 1 deletion themes/magzine/components/LogoBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { siteConfig } from '@/lib/config'
import Link from 'next/link'

export default function LogoBar(props) {
const { siteInfo } = props
return (
<div id='top-wrapper' className='w-full flex items-center '>
<Link
Expand Down
1 change: 1 addition & 0 deletions themes/magzine/components/PostGroupLatest.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const PostGroupLatest = props => {
className={'my-3 flex'}>
<div className='w-20 h-14 overflow-hidden relative'>
<LazyImage
alt={post?.title}
src={`${headerImage}`}
className='object-cover w-full h-full'
/>
Expand Down
1 change: 1 addition & 0 deletions themes/magzine/components/PostItemCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const PostItemCard = ({ post }) => {
}>
<div className='w-full h-40 aspect-video overflow-hidden mb-2'>
<LazyImage
alt={post?.title}
src={cover}
style={cover ? {} : { height: '0px' }}
className='w-full h-40 aspect-video object-cover'
Expand Down
2 changes: 2 additions & 0 deletions themes/magzine/components/PostItemCardTop.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const PostItemCardTop = ({ post, showSummary }) => {
}>
<div className='w-full max-h-80 object-cover overflow-hidden mb-2'>
<LazyImage
priority
alt={post?.title}
src={post.pageCoverThumbnail}
style={post.pageCoverThumbnail ? {} : { height: '0px' }}
className='w-full max-h-80 object-cover hover:scale-125 duration-150'
Expand Down
3 changes: 2 additions & 1 deletion themes/magzine/components/PostItemCardWide.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const PostItemCardWide = ({ post, showSummary }) => {

<div
className={
'flex items-center justify-start flex-wrap space-x-3 text-gray-400'
'flex items-center justify-start flex-wrap space-x-3 text-gray-500'
}>
{/* {siteConfig('MAGZINE_POST_LIST_TAG') &&
post?.tagItems?.map(tag => (
Expand All @@ -73,6 +73,7 @@ const PostItemCardWide = ({ post, showSummary }) => {
{/* 卡牌右侧图片 */}
<div className='w-40 h-40 object-cover overflow-hidden mb-2'>
<LazyImage
alt={post?.title}
src={post.pageCoverThumbnail}
style={post.pageCoverThumbnail ? {} : { height: '0px' }}
className='w-40 h-40 object-cover hover:scale-125 duration-150'
Expand Down

0 comments on commit 68a6352

Please sign in to comment.