mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-29 15:10:06 +00:00
feature:
首页、文章页背景色微调; 侧边抽屉完善; 标签组长度调整; 最近文章日期格式化,增加路由高亮,封装; 清除冗余代码;
This commit is contained in:
@@ -2,18 +2,18 @@ import Link from 'next/link'
|
||||
import BLOG from '@/blog.config'
|
||||
import SearchInput from '@/components/SearchInput'
|
||||
import MenuButtonGroup from '@/components/MenuButtonGroup'
|
||||
import TocBar from '@/components/TocBar'
|
||||
import React, { useImperativeHandle, useState } from 'react'
|
||||
import InfoCard from '@/components/InfoCard'
|
||||
import TagList from '@/components/TagList'
|
||||
import Logo from '@/components/Logo'
|
||||
import LastedPosts from '@/components/LastedPosts'
|
||||
|
||||
/**
|
||||
* 抽屉面板,可以从侧面拉出
|
||||
* @returns {JSX.Element}
|
||||
* @constructor
|
||||
*/
|
||||
const Drawer = ({ post, currentTag, cRef, tags }) => {
|
||||
const Drawer = ({ post, currentTag, cRef, tags, posts }) => {
|
||||
// 暴露给父组件 通过cRef.current.handleMenuClick 调用
|
||||
useImperativeHandle(cRef, () => {
|
||||
return {
|
||||
@@ -26,14 +26,13 @@ const Drawer = ({ post, currentTag, cRef, tags }) => {
|
||||
switchShowDrawer(!showDrawer)
|
||||
}
|
||||
return <>
|
||||
<div className='fixed top-0 left-0 z-40 h-full'>
|
||||
<div className='fixed top-0 left-0 z-50 h-screen shadow-2xl bg-white dark:bg-gray-800'>
|
||||
{/* LOGO */}
|
||||
<div
|
||||
className={(showDrawer ? 'shadow-2xl' : '-ml-72') + ' overflow-y-auto duration-200 w-72 h-full bg-white dark:bg-gray-800 border-r dark:border-gray-600'}>
|
||||
{/* LOGO */}
|
||||
<div
|
||||
className='sticky top-0 z-20 bg-white w-72 flex space-x-4 px-5 py-1 dark:border-gray-500 border-b dark:bg-gray-600 '>
|
||||
className={(showDrawer ? '' : '-ml-72') + ' duration-200 w-72 border-r dark:border-gray-600'}>
|
||||
<div className='w-72 flex space-x-4 px-5 py-1 dark:border-gray-500 '>
|
||||
<div
|
||||
className='z-10 py-2 duration-200 mr-2 bg-white dark:bg-gray-600 text-gray-600 text-xl cursor-pointer dark:text-gray-300'>
|
||||
className='z-10 py-2 duration-200 mr-2 text-gray-600 text-xl cursor-pointer dark:text-gray-300'>
|
||||
<i className='fa hover:scale-125 transform duration-200 fa-bars ' onClick={handleMenuClick} />
|
||||
</div>
|
||||
<Logo/>
|
||||
@@ -42,28 +41,45 @@ const Drawer = ({ post, currentTag, cRef, tags }) => {
|
||||
|
||||
{/* 侧边菜单 */}
|
||||
<div
|
||||
className={(showDrawer ? 'shadow-2xl' : '-ml-72') + ' w-72 duration-200 h-full fixed left-0 top-16 overflow-y-auto'}>
|
||||
<div className='z-20'>
|
||||
className={(showDrawer ? 'shadow-2xl' : '-ml-72') + ' overflow-y-scroll h-screen w-72 duration-200 overflow-y-auto'}>
|
||||
<div className='pb-56'>
|
||||
{/* 搜索框 */}
|
||||
<div className='px-5 my-3 block md:hidden'>
|
||||
<SearchInput currentTag={currentTag} />
|
||||
</div>
|
||||
<InfoCard/>
|
||||
{/* 菜单 */}
|
||||
<MenuButtonGroup allowCollapse={false} />
|
||||
{tags && (
|
||||
<div className='p-4'>
|
||||
{/* 标签云 */}
|
||||
<section>
|
||||
<strong className='text-xl text-gray-600 dark:text-gray-400'>标签</strong>
|
||||
<TagList tags={tags} currentTag={currentTag} />
|
||||
</section>
|
||||
|
||||
{/* 信息卡 */}
|
||||
<InfoCard />
|
||||
<hr className='dark:border-gray-700' />
|
||||
<MenuButtonGroup allowCollapse={true} />
|
||||
|
||||
<hr className='dark:border-gray-700 my-2' />
|
||||
|
||||
{/* 最新文章 */}
|
||||
{posts && (
|
||||
<div className='mt-2 sticky top-0'>
|
||||
<LastedPosts posts={posts}/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 标签云 */}
|
||||
{tags && (
|
||||
<div className='mt-2'>
|
||||
<section
|
||||
className='text-sm font-bold py-3 px-5 text-gray-600 dark:text-gray-400 dark:hover:bg-black duration-100 flex flex-nowrap align-middle'>
|
||||
<div className='w-32'>标签</div>
|
||||
</section>
|
||||
<div className='px-5'>
|
||||
<TagList tags={tags} currentTag={currentTag} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* 背景蒙版 */}
|
||||
<div id='drawer-background' className={(showDrawer ? 'block' : 'hidden') + ' fixed top-0 left-0 z-30 w-full h-full bg-black bg-opacity-50'}
|
||||
<div id='drawer-background' className={(showDrawer ? 'block' : 'hidden') + ' fixed top-0 left-0 z-30 w-full h-full bg-black bg-opacity-30'}
|
||||
onClick={handleMenuClick} />
|
||||
</>
|
||||
}
|
||||
|
||||
45
components/LastedPosts.js
Normal file
45
components/LastedPosts.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import Link from 'next/link'
|
||||
import BLOG from '@/blog.config'
|
||||
import { formatDateFmt } from '@/lib/formatDate'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
/**
|
||||
* 最新文章列表
|
||||
* @param posts
|
||||
* @constructor
|
||||
*/
|
||||
const LastedPosts = ({ posts }) => {
|
||||
// 按时间排序
|
||||
if (posts) {
|
||||
posts = posts.sort((a, b) => {
|
||||
const dateA = new Date(a?.lastEditedTime || a.createdTime)
|
||||
const dateB = new Date(b?.lastEditedTime || b.createdTime)
|
||||
return dateB - dateA
|
||||
}).slice(0, 5)
|
||||
}
|
||||
const router = useRouter()
|
||||
|
||||
return <>
|
||||
<section
|
||||
className='text-sm font-bold py-3 px-5 text-gray-600 dark:text-gray-400 dark:hover:bg-black duration-100 flex flex-nowrap align-middle'>
|
||||
<div className='w-32'>最近更新</div>
|
||||
</section>
|
||||
<div>
|
||||
{posts.map(post => {
|
||||
return (
|
||||
<Link key={post.id} title={post.title} href={`${BLOG.path}/article/${post.slug}`} >
|
||||
<div className={(router.asPath === `${BLOG.path}/article/${post.slug}` ? 'bg-gray-200 dark:bg-black' : '') + ' text-xs leading-5 py-1.5 px-5 cursor-pointer hover:underline flex'}>
|
||||
<div className='mr-2 text-gray-500'>
|
||||
{formatDateFmt(post.lastEditedTime, 'yyyy/MM/dd')}
|
||||
</div>
|
||||
<div className='text-sm flex w-50 overflow-x-hidden whitespace-nowrap dark:text-gray-300'>
|
||||
{post.title}
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
export default LastedPosts
|
||||
@@ -24,7 +24,7 @@ const MenuButtonGroup = ({ allowCollapse = false }) => {
|
||||
link =>
|
||||
link.show && (
|
||||
<Link key={link.id + link.icon} title={link.to} href={link.to} >
|
||||
<a className={(router.asPath === link.to ? 'bg-gray-200 dark:bg-gray-900' : '') + ' py-2 px-5 hover:bg-gray-100 cursor-pointer dark:hover:bg-black duration-100 flex flex-nowrap align-middle'} >
|
||||
<a className={(router.asPath === link.to ? 'bg-gray-200 dark:bg-black' : '') + ' py-2 px-5 hover:bg-gray-100 cursor-pointer dark:hover:bg-black duration-100 flex flex-nowrap align-middle'} >
|
||||
<div className='my-auto w-5 text-2xl justify-center flex'>
|
||||
<i className={'fa ' + link.icon} />
|
||||
</div>
|
||||
|
||||
@@ -2,8 +2,7 @@ import React from 'react'
|
||||
import MenuButtonGroup from '@/components/MenuButtonGroup'
|
||||
import InfoCard from '@/components/InfoCard'
|
||||
import TagList from '@/components/TagList'
|
||||
import BLOG from '@/blog.config'
|
||||
import Link from 'next/link'
|
||||
import LastedPosts from '@/components/LastedPosts'
|
||||
|
||||
const SideBar = ({ tags, currentTag, post, posts }) => {
|
||||
// 按时间排序
|
||||
@@ -18,35 +17,19 @@ const SideBar = ({ tags, currentTag, post, posts }) => {
|
||||
return <aside className='z-10 dark:border-gray-500 border-gray-200 bg-white hidden xl:block'>
|
||||
<div
|
||||
className='w-72 dark:bg-gray-800 h-full scroll-hidden left-0 duration-500 ease-in-out min-h-screen'>
|
||||
<div id='sidebar' className='hidden md:block sticky top-20 duration-500'>
|
||||
<div id='sidebar' className='hidden md:block sticky top-20 pb-56 duration-500'>
|
||||
<>
|
||||
<InfoCard />
|
||||
<hr className='dark:border-gray-700' />
|
||||
<MenuButtonGroup allowCollapse={true} />
|
||||
</>
|
||||
|
||||
<hr className='dark:border-gray-700 my-2' />
|
||||
|
||||
{/* 最新文章 */}
|
||||
{posts && (
|
||||
<div className='mt-2'>
|
||||
<hr className='dark:border-gray-700' />
|
||||
<section
|
||||
className='text-sm font-bold py-3 px-5 text-gray-600 dark:text-gray-400 dark:hover:bg-black duration-100 flex flex-nowrap align-middle'>
|
||||
<div className='w-32'>最近更新</div>
|
||||
</section>
|
||||
<div>
|
||||
{posts.map(post => {
|
||||
return (
|
||||
<Link key={post.id} title={post.title} href={`${BLOG.path}/article/${post.slug}`} >
|
||||
<div className='text-sm py-1.5 px-5 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-600 flex'>
|
||||
<div className='w-12 overflow-hidden'>
|
||||
<img className='w-12 w-12 object-cover cursor-pointer transform hover:scale-110 duration-500' src={post.page_cover} alt={post.title} />
|
||||
</div>
|
||||
<div className='w-60 ml-2 overflow-hidden whitespace-nowrap dark:text-gray-300'>{post.title}</div>
|
||||
</div>
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
<LastedPosts posts={posts}/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import TagItemMini from '@/components/TagItemMini'
|
||||
const TagList = ({ tags, currentTag }) => {
|
||||
if (!tags) return <></>
|
||||
return (
|
||||
<div id='tags-list' className='duration-500 dark:border-gray-600 dark:bg-gray-800 w-52'>
|
||||
<div id='tags-list' className='duration-500 dark:border-gray-600 dark:bg-gray-800 w-66'>
|
||||
{Object.keys(tags).map(tag => {
|
||||
const selected = tag === currentTag
|
||||
return (
|
||||
|
||||
@@ -7,13 +7,13 @@ import Drawer from '@/components/Drawer'
|
||||
import DrawerRight from '@/components/DrawerRight'
|
||||
import Logo from '@/components/Logo'
|
||||
|
||||
const TopNav = ({ tags, currentTag, post }) => {
|
||||
const TopNav = ({ tags, currentTag, post, posts }) => {
|
||||
const drawer = useRef()
|
||||
const drawerRight = useRef()
|
||||
|
||||
return (<>
|
||||
{/* 侧面抽屉 */}
|
||||
<Drawer post={post} currentTag={currentTag} cRef={drawer} tags={tags} />
|
||||
<Drawer post={post} currentTag={currentTag} cRef={drawer} tags={tags} posts={posts}/>
|
||||
<DrawerRight post={post} cRef={drawerRight}/>
|
||||
|
||||
{/* 导航栏 */}
|
||||
|
||||
Reference in New Issue
Block a user