Merge pull request #2733 from tangly1024/feat/theme-magzine

Feat/theme magzine
This commit is contained in:
tangly1024
2024-09-13 19:18:20 +08:00
committed by GitHub
58 changed files with 3228 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
NEXT_PUBLIC_VERSION=4.7.0
NEXT_PUBLIC_VERSION=4.7.1
# 可在此添加环境变量,去掉最左边的(# )注释即可

View File

@@ -63,7 +63,8 @@ const ExternalPlugin = props => {
const MOUSE_FOLLOW = siteConfig('MOUSE_FOLLOW')
const CUSTOM_EXTERNAL_CSS = siteConfig('CUSTOM_EXTERNAL_CSS')
const CUSTOM_EXTERNAL_JS = siteConfig('CUSTOM_EXTERNAL_JS')
const ENABLE_NPROGRSS = siteConfig('ENABLE_NPROGRSS', true)
// 默认关闭NProgress
const ENABLE_NPROGRSS = siteConfig('ENABLE_NPROGRSS', false)
// 自定义样式css和js引入
if (isBrowser) {

View File

@@ -73,8 +73,11 @@ const OpenWrite = () => {
console.error('OpenWrite 加载异常', error)
}
}
useEffect(() => {
if (process.env.NODE_ENV === 'development') {
console.log('开发环境:屏蔽OpenWrite')
return
}
if (isBrowser && blogId) {
// Check if the element with id 'read-more-wrap' already exists
const readMoreWrap = document.getElementById('read-more-wrap')

View File

@@ -1,7 +1,9 @@
import { siteConfig } from '@/lib/config'
import dynamic from 'next/dynamic'
const ShareButtons = dynamic(() => import('@/components/ShareButtons'), { ssr: false })
const ShareButtons = dynamic(() => import('@/components/ShareButtons'), {
ssr: false
})
/**
* 分享栏
@@ -9,14 +11,20 @@ const ShareButtons = dynamic(() => import('@/components/ShareButtons'), { ssr: f
* @returns
*/
const ShareBar = ({ post }) => {
if (!JSON.parse(siteConfig('POST_SHARE_BAR_ENABLE')) || !post || post?.type !== 'Post') {
if (
!JSON.parse(siteConfig('POST_SHARE_BAR_ENABLE')) ||
!post ||
post?.type !== 'Post'
) {
return <></>
}
return <div className='m-1 overflow-x-auto'>
<div className='flex w-full md:justify-end'>
<ShareButtons post={post} />
</div>
return (
<div className='m-1 overflow-x-auto'>
<div className='flex w-full md:justify-end'>
<ShareButtons post={post} />
</div>
</div>
)
}
export default ShareBar

View File

@@ -8,7 +8,7 @@ import MemoryCache from './memory_cache'
* @returns
*/
export async function getDataFromCache(key, force) {
if (JSON.parse(BLOG.ENABLE_CACHE) || force) {
if (BLOG.ENABLE_CACHE || force) {
const dataFromCache = await getApi().getCache(key)
if (JSON.stringify(dataFromCache) === '[]') {
return null

View File

@@ -1,6 +1,6 @@
{
"name": "notion-next",
"version": "4.7.0",
"version": "4.7.1",
"homepage": "https://github.com/tangly1024/NotionNext.git",
"license": "MIT",
"repository": {

View File

@@ -403,7 +403,8 @@ summary > .notion-h {
.notion-h1 {
font-size: 1.575em;
margin-top: 1.08em;
@apply border-b w-full;
@apply w-full;
/* @apply border-b w-full; */
}
.notion-h2 {
@apply w-full;
@@ -554,7 +555,7 @@ summary > .notion-h {
width: 100%;
margin: 6px 0;
padding: 0;
border-bottom-width: 1px;
/* border-bottom-width: 1px; */
}
.notion-link {
@@ -1664,9 +1665,8 @@ code[class*='language-'] {
}
/* NOTION CSS OVERRIDE */
.notion {
@apply dark:text-gray-300;
@apply dark:text-gray-100;
overflow-wrap: break-word;
}
.notion,

View File

@@ -0,0 +1,30 @@
// import { useGlobal } from '@/lib/global'
import dynamic from 'next/dynamic'
const NotionPage = dynamic(() => import('@/components/NotionPage'))
/**
* Magzine主题的公告
*/
const Announcement = ({ post, className }) => {
// const { locale } = useGlobal()
if (post?.blockMap) {
return (
<div className={className}>
<section
id='announcement-wrapper'
className='dark:text-gray-300 rounded-xl px-2'>
{/* <div><i className='mr-2 fas fa-bullhorn' />{locale.COMMON.ANNOUNCEMENT}</div> */}
{post && (
<div id='announcement-content'>
<NotionPage post={post} className='' />
</div>
)}
</section>
</div>
)
} else {
return <></>
}
}
export default Announcement

View File

@@ -0,0 +1,32 @@
import Link from 'next/link'
/**
* 上一篇,下一篇文章
* @param {prev,next} param0
* @returns
*/
export default function ArticleAround ({ prev, next }) {
if (!prev || !next) {
return <></>
}
return (
<section className='text-gray-800 dark:text-gray-400 h-12 flex items-center justify-between space-x-5 my-4'>
<Link
href={`/${prev.slug}`}
passHref
className='text-sm cursor-pointer justify-start items-center flex hover:underline duration-300'>
<i className='mr-1 fas fa-angle-double-left' />{prev.title}
</Link>
<Link
href={`/${next.slug}`}
passHref
className='text-sm cursor-pointer justify-end items-center flex hover:underline duration-300'>
{next.title}
<i className='ml-1 my-1 fas fa-angle-double-right' />
</Link>
</section>
)
}

View File

@@ -0,0 +1,55 @@
import LazyImage from '@/components/LazyImage'
import NotionIcon from '@/components/NotionIcon'
import { siteConfig } from '@/lib/config'
import CategoryItem from './CategoryItem'
import TagItemMini from './TagItemMini'
/**
* 文章详情页介绍
* @param {*} props
* @returns
*/
export default function ArticleInfo(props) {
const { post, siteInfo } = props
return (
<>
<div className='flex flex-col gap-y-4 py-4 px-2 lg:px-0'>
<div className='flex justify-center mr-2 items-center'>
{siteConfig('MAGZINE_POST_LIST_CATEGORY') && (
<CategoryItem category={post?.category} />
)}
<div
className={
'flex items-center justify-start flex-wrap space-x-3 text-gray-400'
}>
{siteConfig('MAGZINE_POST_LIST_TAG') &&
post?.tagItems?.map(tag => (
<TagItemMini key={tag.name} tag={tag} />
))}
</div>
</div>
{/* title */}
<h2 className='text-4xl text-center dark:text-gray-300'>
{siteConfig('POST_TITLE_ICON') && (
<NotionIcon icon={post?.pageIcon} />
)}
{post?.title}
</h2>
<div className='text-xl text-center'>{post?.summary}</div>
</div>
{post?.type && !post?.type !== 'Page' && post?.pageCover && (
<div className='w-full relative md:flex-shrink-0 overflow-hidden'>
<LazyImage
alt={post?.title}
src={post?.pageCover}
className='object-cover max-h-[60vh] w-full'
/>
</div>
)}
</>
)
}

View File

@@ -0,0 +1,61 @@
import { useGlobal } from '@/lib/global'
import { useEffect, useRef } from 'react'
/**
* 加密文章校验组件
* @param {password, validPassword} props
* @param password 正确的密码
* @param validPassword(bool) 回调函数校验正确回调入参为true
* @returns
*/
export const ArticleLock = props => {
const { validPassword } = props
const { locale } = useGlobal()
const submitPassword = () => {
const p = document.getElementById('password')
if (!validPassword(p?.value)) {
const tips = document.getElementById('tips')
if (tips) {
tips.innerHTML = ''
tips.innerHTML = `<div class='text-red-500 animate__shakeX animate__animated'>${locale.COMMON.PASSWORD_ERROR}</div>`
}
}
}
const passwordInputRef = useRef(null)
useEffect(() => {
// 选中密码输入框并将其聚焦
passwordInputRef.current.focus()
}, [])
return (
<div
id='container'
className='w-full flex justify-center items-center h-96 '>
<div className='text-center space-y-3'>
<div className='font-bold'>{locale.COMMON.ARTICLE_LOCK_TIPS}</div>
<div className='flex mx-4'>
<input
id='password'
type='password'
onKeyDown={e => {
if (e.key === 'Enter') {
submitPassword()
}
}}
ref={passwordInputRef} // 绑定ref到passwordInputRef变量
className='outline-none w-full text-sm pl-5 rounded-l transition focus:shadow-lg dark:text-gray-300 leading-10 text-black bg-gray-100 dark:bg-gray-500'></input>
<div
onClick={submitPassword}
className='px-3 whitespace-nowrap cursor-pointer items-center justify-center py-2 bg-gray-500 hover:bg-gray-400 text-white rounded-r duration-300'>
<i className={'duration-200 cursor-pointer fas fa-key'}>
&nbsp;{locale.COMMON.SUBMIT}
</i>
</div>
</div>
<div id='tips'></div>
</div>
</div>
)
}

View File

@@ -0,0 +1,30 @@
import LazyImage from '@/components/LazyImage'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import BannerItem from './BannerItem'
/**
* 全宽
* @param {*} props
* @returns
*/
export default function BannerFullWidth() {
const { siteInfo } = useGlobal()
const banner = siteConfig('MAGZINE_HOME_BANNER_ENABLE')
if (!banner) {
return null
}
return (
<div className='w-full flex lg:flex-row flex-col justify-between h-96 bg-black'>
<LazyImage
alt={siteInfo?.title}
src={siteInfo?.pageCover}
className={`banner-cover w-full h-96 object-cover object-center `}
/>
<div className='w-full flex items-center justify-center'>
<BannerItem />
</div>
</div>
)
}

View File

@@ -0,0 +1,35 @@
import { siteConfig } from '@/lib/config'
import Link from 'next/link'
/**
* 文字广告Banner
* @param {*} props
* @returns
*/
export default function BannerItem() {
// 首屏信息栏按钮文字
const banner = siteConfig('MAGZINE_HOME_BANNER_ENABLE')
const button = siteConfig('MAGZINE_HOME_BUTTON')
const text = siteConfig('MAGZINE_HOME_BUTTON_TEXT')
const url = siteConfig('MAGZINE_HOME_BUTTON_URL')
const title = siteConfig('MAGZINE_HOME_TITLE')
const description = siteConfig('MAGZINE_HOME_DESCRIPTION')
const tips = siteConfig('MAGZINE_HOME_TIPS')
if (!banner) {
return null
}
return (
<div className='flex flex-col p-5 gap-y-5 dark items-center justify-between w-full bg-black text-white'>
{/* 首屏导航按钮 */}
<h2 className='text-2xl font-semibold'>{title}</h2>
<h3 className='text-sm'>{description}</h3>
{button && (
<div className='mt-2 text-center px-6 py-3 font-semibold rounded-3xl text-black bg-[#7BE986] hover:bg-[#62BA6B]'>
<Link href={url}>{text}</Link>
</div>
)}
<span className='text-xs'>{tips}</span>
</div>
)
}

View File

@@ -0,0 +1,9 @@
const Card = ({ children, headerSlot, className }) => {
return <div className={className}>
<>{headerSlot}</>
<section className="shadow px-2 py-4 bg-white dark:bg-gray-800 hover:shadow-xl duration-200">
{children}
</section>
</div>
}
export default Card

View File

@@ -0,0 +1,99 @@
import throttle from 'lodash.throttle'
import { uuidToId } from 'notion-utils'
import { useCallback, useEffect, useRef, useState } from 'react'
import Progress from './Progress'
/**
* 目录导航组件
* @param toc
* @returns {JSX.Element}
* @constructor
*/
const Catalog = ({ toc, className }) => {
const tocIds = []
// 目录自动滚动
const tRef = useRef(null)
// 同步选中目录事件
const [activeSection, setActiveSection] = useState(null)
// 监听滚动事件
useEffect(() => {
window.addEventListener('scroll', actionSectionScrollSpy)
actionSectionScrollSpy()
return () => {
window.removeEventListener('scroll', actionSectionScrollSpy)
}
}, [])
const throttleMs = 200
const actionSectionScrollSpy = useCallback(
throttle(() => {
const sections = document.getElementsByClassName('notion-h')
let prevBBox = null
let currentSectionId = activeSection
for (let i = 0; i < sections.length; ++i) {
const section = sections[i]
if (!section || !(section instanceof Element)) continue
if (!currentSectionId) {
currentSectionId = section.getAttribute('data-id')
}
const bbox = section.getBoundingClientRect()
const prevHeight = prevBBox ? bbox.top - prevBBox.bottom : 0
const offset = Math.max(150, prevHeight / 4)
// GetBoundingClientRect returns values relative to viewport
if (bbox.top - offset < 0) {
currentSectionId = section.getAttribute('data-id')
prevBBox = bbox
continue
}
// No need to continue loop, if last element has been detected
break
}
setActiveSection(currentSectionId)
const index = tocIds.indexOf(currentSectionId) || 0
tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' })
}, throttleMs)
)
// 无目录就直接返回空
if (!toc || toc.length < 1) {
return <></>
}
return (
<div className={className}>
<div className='w-full mt-2 mb-4'>
<Progress />
</div>
<div
className='overflow-y-auto max-h-44 overscroll-none scroll-hidden'
ref={tRef}>
<nav className='h-full text-black'>
{toc.map(tocItem => {
const id = uuidToId(tocItem.id)
tocIds.push(id)
return (
<a
key={id}
href={`#${id}`}
className={`notion-table-of-contents-item duration-300 transform dark:text-gray-300
notion-table-of-contents-item-indent-level-${tocItem.indentLevel} `}>
<span
style={{
display: 'inline-block',
marginLeft: tocItem.indentLevel * 16
}}
className={`truncate ${activeSection === id ? 'font-bold text-gray-500 underline' : ''}`}>
{tocItem.text}
</span>
</a>
)
})}
</nav>
</div>
</div>
)
}
export default Catalog

View File

@@ -0,0 +1,34 @@
import { useGlobal } from '@/lib/global'
import CategoryItem from './CategoryItem'
/**
* 分类
* @param {*} param0
* @returns
*/
const CategoryGroup = ({ currentCategory, categoryOptions }) => {
const { locale } = useGlobal()
if (!categoryOptions) {
return <></>
}
return (
<div id='category-list' className='pt-4'>
<div className='text-lg font-bold mb-2'>{locale.COMMON.CATEGORY}</div>
<div className=''>
{categoryOptions?.map(category => {
const selected = currentCategory === category.name
return (
<CategoryItem
key={category.name}
selected={selected}
category={category.name}
categoryCount={category.count}
/>
)
})}
</div>
</div>
)
}
export default CategoryGroup

View File

@@ -0,0 +1,19 @@
import Link from 'next/link'
export default function CategoryItem({ selected, category, categoryCount }) {
return (
<Link
href={`/category/${category}`}
passHref
className={
(selected
? ' bg-gray-600 text-white '
: 'dark:text-gray-400 text-gray-900 ') +
'text-sm hover:underline flex text-md items-center duration-300 cursor-pointer py-1 whitespace-nowrap'
}>
<div>
{category} {categoryCount && `(${categoryCount})`}
</div>
</Link>
)
}

View File

@@ -0,0 +1,114 @@
import DarkModeButton from '@/components/DarkModeButton'
import LazyImage from '@/components/LazyImage'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import Link from 'next/link'
import SocialButton from './SocialButton'
/**
* 网页底脚
*/
const Footer = ({ title }) => {
const d = new Date()
const currentYear = d.getFullYear()
const since = siteConfig('SINCE')
const copyrightDate =
parseInt(since) < currentYear ? since + '-' + currentYear : currentYear
const { siteInfo } = useGlobal()
const MAGZINE_FOOTER_LINKS = siteConfig('MAGZINE_FOOTER_LINKS', [])
return (
<footer className='z-10 bg-black text-white justify-center m-auto w-full p-6 relative'>
<div className='max-w-screen-2xl w-full mx-auto '>
{/* 信息与链接区块 */}
<div className='w-full flex lg:flex-row flex-col justify-between py-16'>
<div className='gap-x-2 py-6 flex items-center'>
{/* 站长信息 */}
<LazyImage
src={siteInfo?.icon}
className='rounded-full'
width={40}
alt={siteConfig('AUTHOR')}
/>
<div>
<h1 className='text-lg'>{title}</h1>
<i className='fas fa-copyright' />
<a
href={siteConfig('LINK')}
className='underline font-bold justify-start '>
{siteConfig('AUTHOR')}
</a>
</div>
</div>
{/* 右侧链接区块 */}
<div className='grid grid-cols-1 lg:grid-cols-4 lg:gap-16 gap-8'>
{MAGZINE_FOOTER_LINKS?.map((group, index) => {
return (
<div key={index}>
<div className='font-bold text-lg text-white lg:pb-8 pb-4'>
{group.name}
</div>
<div className='flex flex-col gap-y-2'>
{group?.menus?.map((menu, index) => {
return (
<div key={index}>
<Link href={menu.href} className='hover:underline'>
{menu.title}
</Link>
</div>
)
})}
</div>
</div>
)
})}
</div>
</div>
{/* 页脚 */}
<div className='py-4 flex justify-between items-center border-t border-gray-400'>
<span className='flex gap-x-2 items-center'>
<DarkModeButton />
{`${copyrightDate}`}
{siteConfig('BEI_AN') && (
<>
<i className='fas fa-shield-alt' />{' '}
<a href='https://beian.miit.gov.cn/' className='mr-2'>
{siteConfig('BEI_AN')}
</a>
<br />
</>
)}
</span>
<span className='text-sm font-serif'>
Powered by{' '}
<a
href='https://github.com/tangly1024/NotionNext'
className='underline justify-start text-white'>
NotionNext {siteConfig('VERSION')}
</a>
.
</span>
<div className='flex items-center gap-x-2'>
<span>
<i className='mx-1 animate-pulse fas fa-heart' />{' '}
<span className='hidden busuanzi_container_site_pv'>
<i className='fas fa-eye' />
<span className='px-1 busuanzi_value_site_pv'> </span>{' '}
</span>
<span className='pl-2 hidden busuanzi_container_site_uv'>
<i className='fas fa-users' />{' '}
<span className='px-1 busuanzi_value_site_uv'> </span>{' '}
</span>
</span>
<SocialButton />
</div>
</div>
</div>
</footer>
)
}
export default Footer

View File

@@ -0,0 +1,196 @@
import Collapse from '@/components/Collapse'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import throttle from 'lodash.throttle'
import { useRouter } from 'next/router'
import { useEffect, useRef, useState } from 'react'
import CONFIG from '../config'
import LogoBar from './LogoBar'
import { MenuBarMobile } from './MenuBarMobile'
import { MenuItemDrop } from './MenuItemDrop'
/**
* 顶部导航栏 + 菜单
* @param {} param0
* @returns
*/
export default function Header(props) {
const { customNav, customMenu } = props
const [isOpen, changeShow] = useState(false)
const collapseRef = useRef(null)
const lastScrollY = useRef(0) // 用于存储上一次的滚动位置
const { locale } = useGlobal()
const router = useRouter()
const defaultLinks = [
{
icon: 'fas fa-th',
name: locale.COMMON.CATEGORY,
href: '/category',
show: CONFIG.MENU_CATEGORY
},
{
icon: 'fas fa-tag',
name: locale.COMMON.TAGS,
href: '/tag',
show: CONFIG.MENU_TAG
},
{
icon: 'fas fa-archive',
name: locale.NAV.ARCHIVE,
href: '/archive',
show: CONFIG.MENU_ARCHIVE
},
{
icon: 'fas fa-search',
name: locale.NAV.SEARCH,
href: '/search',
show: CONFIG.MENU_SEARCH
}
]
let links = defaultLinks.concat(customNav)
const toggleMenuOpen = () => {
changeShow(!isOpen)
}
// 向下滚动时,调整导航条高度
useEffect(() => {
scrollTrigger()
window.addEventListener('scroll', scrollTrigger)
return () => {
window.removeEventListener('scroll', scrollTrigger)
}
}, [])
const throttleMs = 150
const scrollTrigger = throttle(() => {
const scrollS = window.scrollY
if (scrollS === lastScrollY.current) return // 如果滚动位置没有变化,则不做任何操作
const nav = document.querySelector('#top-navbar')
const narrowNav = scrollS > 60
if (narrowNav) {
nav && nav.classList.replace('h-20', 'h-14')
} else {
nav && nav.classList.replace('h-14', 'h-20')
}
lastScrollY.current = scrollS // 更新上一次的滚动位置
}, throttleMs)
const [showSearchInput, changeShowSearchInput] = useState(false)
// 展示搜索框
const toggleShowSearchInput = () => {
if (siteConfig('ALGOLIA_APP_ID')) {
searchModal.current.openSearch()
} else {
changeShowSearchInput(!showSearchInput)
}
}
const onKeyUp = e => {
if (e.keyCode === 13) {
const search = document.getElementById('simple-search').value
if (search) {
router.push({ pathname: '/search/' + search })
}
}
}
// 如果 开启自定义菜单则覆盖Page生成的菜单
if (siteConfig('CUSTOM_MENU')) {
links = customMenu
}
if (!links || links.length === 0) {
return null
}
return (
<div
id='top-navbar-wrapper'
className={
'sticky top-0 w-full z-40 shadow bg-white dark:bg-hexo-black-gray '
}>
{/* 导航栏菜单内容 */}
<div
id='top-navbar'
className='px-2 lg:px-0 flex w-full mx-auto max-w-screen-2xl h-20 transition-all duration-200 items-center justify-between'>
{/* 搜索栏 */}
{showSearchInput && (
<input
autoFocus
id='simple-search'
onKeyUp={onKeyUp}
className='outline-none flex flex-row text-base relative w-full border-b py-2'
aria-label='Submit search'
type='search'
name='s'
autoComplete='off'
placeholder='Type then hit enter to search...'
/>
)}
{/* 默认菜单 */}
{!showSearchInput && (
<>
{/* 左侧图标Logo */}
<div className='flex gap-x-8 h-full'>
<LogoBar {...props} />
{/* 桌面端顶部菜单 */}
<div className='hidden md:flex items-center gap-x-3'>
{links &&
links?.map((link, index) => (
<MenuItemDrop key={index} link={link} />
))}
</div>
</div>
</>
)}
{/* 右侧移动端折叠按钮 */}
<div className='flex items-center gap-x-2'>
{/* 搜索按钮 */}
<div className='flex text-center items-center cursor-pointer'>
<i
className={
showSearchInput
? 'fa-regular fa-circle-xmark'
: 'fa-solid fa-magnifying-glass' + ' align-middle'
}
onClick={toggleShowSearchInput}></i>
</div>
<div className='mr-1 flex md:hidden justify-end items-center text-lg space-x-4 font-serif dark:text-gray-200'>
<div onClick={toggleMenuOpen} className='cursor-pointer'>
{isOpen ? (
<i className='fas fa-times' />
) : (
<i className='fas fa-bars' />
)}
</div>
</div>
</div>
</div>
{/* 移动端折叠菜单 */}
<Collapse
type='vertical'
collapseRef={collapseRef}
isOpen={isOpen}
className='md:hidden'>
<div className='bg-white dark:bg-hexo-black-gray pt-1 py-2 lg:hidden '>
<MenuBarMobile
{...props}
onHeightChange={param =>
collapseRef.current?.updateCollapseHeight(param)
}
/>
</div>
</Collapse>
</div>
)
}

View File

@@ -0,0 +1,40 @@
// import { useGlobal } from '@/lib/global'
import BannerItem from './BannerItem'
import PostItemCardTop from './PostItemCardTop'
import PostItemCardWide from './PostItemCardWide'
/**
* 首页主宣传
* @param {*} param0
* @returns
*/
const Hero = ({ posts }) => {
// 获取置顶文章与次要文章
const postTop = posts[0]
const post1 = posts[1]
const post2 = posts[2]
return (
<>
<div className='w-full mx-auto max-w-screen-2xl xl:flex justify-between'>
{/* 左侧一篇主要置顶文章 */}
<div className='basis-1/2 mb-6 px-2 lg:px-5'>
<PostItemCardTop post={postTop} />
</div>
{/* 右侧 */}
<div>
{/* 首屏介绍 */}
<BannerItem />
{/* 两篇次要文章 */}
<div className='py-4 px-2 lg:px-5'>
<hr className='mb-8' />
<PostItemCardWide post={post1} />
<hr className='mb-8' />
<PostItemCardWide post={post2} />
</div>
</div>
</div>
</>
)
}
export default Hero

View File

@@ -0,0 +1,38 @@
import LazyImage from '@/components/LazyImage'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
/**
* 用户信息卡
* @param {*} props
* @returns
*/
const InfoCard = props => {
const { siteInfo } = useGlobal()
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')
}}>
<LazyImage
src={siteInfo?.icon}
width={120}
alt={siteConfig('AUTHOR')}
/>
</div>
<div className='text-xl py-2 hover:scale-105 transform duration-200 flex justify-start '>
{siteConfig('AUTHOR')}
</div>
<div className='text-gray-100 mb-2 hover:scale-105 transform duration-200 flex justify-start'>
{siteConfig('BIO')}
</div>
</div>
</div>
)
}
export default InfoCard

View File

@@ -0,0 +1,33 @@
import { siteConfig } from '@/lib/config'
/**
* 跳转到网页顶部
* 当屏幕下滑500像素后会出现该控件
* @param targetRef 关联高度的目标html标签
* @param showPercent 是否显示百分比
* @returns {JSX.Element}
* @constructor
*/
const JumpToTopButton = ({ showPercent = false, percent, className }) => {
if (!siteConfig('MAGZINE_WIDGET_TO_TOP')) {
return <></>
}
return (
<div
id='jump-to-top'
data-aos='fade-up'
data-aos-duration='300'
data-aos-once='false'
data-aos-anchor-placement='top-center'
className='fixed xl:right-80 right-2 mr-10 bottom-24 z-20'>
<i
className='fas fa-chevron-up cursor-pointer p-2 rounded-full border bg-white dark:bg-hexo-black-gray'
onClick={() => {
window.scrollTo({ top: 0, behavior: 'smooth' })
}}
/>
</div>
)
}
export default JumpToTopButton

View File

@@ -0,0 +1,15 @@
import Link from 'next/link'
export default function LeftMenuBar () {
return (
<div className='w-20 border-r hidden lg:block pt-12'>
<section>
<Link href='/' legacyBehavior>
<div className='text-center cursor-pointer hover:text-black'>
<i className='fas fa-home text-gray-500'/>
</div>
</Link>
</section>
</div>
);
}

View File

@@ -0,0 +1,22 @@
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
href='/'
className='flex text-md font-semibold md:text-xl hover:bg-black hover:text-white p-2 rounded-xl duration-200 dark:text-gray-200'>
{/* <LazyImage
src={siteInfo?.icon}
width={24}
height={20}
alt={siteConfig('AUTHOR')}
className='mr-2 hidden md:block rounded-full'
/> */}
{siteConfig('TITLE')}
</Link>
</div>
)
}

View File

@@ -0,0 +1,53 @@
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import { MenuItemCollapse } from './MenuItemCollapse'
export const MenuBarMobile = props => {
const { customMenu, customNav } = props
const { locale } = useGlobal()
let links = [
// { name: locale.NAV.INDEX, href: '/' || '/', show: true },
{
name: locale.COMMON.CATEGORY,
href: '/category',
show: siteConfig('MAGZINE_MENU_CATEGORY')
},
{
name: locale.COMMON.TAGS,
href: '/tag',
show: siteConfig('MAGZINE_MENU_TAG')
},
{
name: locale.NAV.ARCHIVE,
href: '/archive',
show: siteConfig('MAGZINE_MENU_ARCHIVE')
}
// { name: locale.NAV.SEARCH, href: '/search', show: siteConfig('MENU_SEARCH', ) }
]
if (customNav) {
links = links.concat(customNav)
}
// 如果 开启自定义菜单,则不再使用 Page生成菜单。
if (siteConfig('CUSTOM_MENU')) {
links = customMenu
}
if (!links || links.length === 0) {
return null
}
return (
<nav id='nav' className=' text-md'>
{links?.map((link, index) => (
<MenuItemCollapse
onHeightChange={props.onHeightChange}
key={index}
link={link}
/>
))}
</nav>
)
}

View File

@@ -0,0 +1,97 @@
import Collapse from '@/components/Collapse'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useState } from 'react'
/**
* 折叠菜单
* @param {*} param0
* @returns
*/
export const MenuItemCollapse = props => {
const { link } = props
const [show, changeShow] = useState(false)
const hasSubMenu = link?.subMenus?.length > 0
const [isOpen, changeIsOpen] = useState(false)
const router = useRouter()
if (!link || !link.show) {
return null
}
const selected = router.pathname === link.href || router.asPath === link.href
const toggleShow = () => {
changeShow(!show)
}
const toggleOpenSubMenu = () => {
changeIsOpen(!isOpen)
}
return (
<>
<div
className={
(selected
? 'bg-gray-600 text-white hover:text-white'
: 'hover:text-gray-600') +
' px-5 w-full text-left duration-200 dark:bg-hexo-black-gray dark:border-black'
}
onClick={toggleShow}>
{!hasSubMenu && (
<Link
href={link?.href}
target={link?.target}
className='py-2 w-full my-auto items-center justify-between flex '>
<div>
<div className={`${link.icon} text-center w-4 mr-4`} />
{link.name}
</div>
</Link>
)}
{hasSubMenu && (
<div
onClick={hasSubMenu ? toggleOpenSubMenu : null}
className='py-2 font-extralight flex justify-between cursor-pointer dark:text-gray-200 no-underline tracking-widest'>
<div>
<div className={`${link.icon} text-center w-4 mr-4`} />
{link.name}
</div>
<div className='inline-flex items-center '>
<i
className={`px-2 fas fa-chevron-right transition-all duration-200 ${isOpen ? 'rotate-90' : ''}`}></i>
</div>
</div>
)}
</div>
{/* 折叠子菜单 */}
{hasSubMenu && (
<Collapse isOpen={isOpen} onHeightChange={props.onHeightChange}>
{link?.subMenus?.map(sLink => {
return (
<div
key={sLink.id}
className='
not:last-child:border-b-0 border-b dark:border-gray-800 py-2 px-14 cursor-pointer hover:bg-gray-100 dark:text-gray-200
font-extralight dark:bg-black text-left justify-start text-gray-600 bg-gray-50 dark:hover:bg-gray-900 tracking-widest transition-all duration-200'>
<Link href={sLink.href} target={link?.target}>
<div>
<div
className={`${sLink.icon} text-center w-3 mr-3 text-xs`}
/>
{sLink.title}
</div>
</Link>
</div>
)
})}
</Collapse>
)}
</>
)
}

View File

@@ -0,0 +1,76 @@
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useState } from 'react'
export const MenuItemDrop = ({ link }) => {
const [show, changeShow] = useState(false)
// const show = true
// const changeShow = () => {}
const router = useRouter()
if (!link || !link.show) {
return null
}
const hasSubMenu = link?.subMenus?.length > 0
const selected = router.pathname === link.href || router.asPath === link.href
return (
<li
className='cursor-pointer list-none items-center h-full'
onMouseOver={() => changeShow(true)}
onMouseOut={() => changeShow(false)}>
{hasSubMenu && (
<div
className={
'h-full whitespace-nowrap duration-300 text-md justify-between dark:text-gray-300 cursor-pointer flex flex-nowrap items-center ' +
(selected
? 'bg-gray-600 text-white hover:text-white'
: 'hover:text-gray-600')
}>
<div className='items-center flex gap-x-1'>
{link?.icon && <i className={link?.icon} />} {link?.name}
{hasSubMenu && (
<i
className={`px-1 fas fa-chevron-down duration-500 transition-all ${show ? ' rotate-180' : ''}`}></i>
)}
</div>
</div>
)}
{!hasSubMenu && (
<div
className={
'px-3 gap-x-1 h-full whitespace-nowrap duration-300 text-sm justify-between dark:text-gray-300 cursor-pointer flex flex-nowrap items-center ' +
(selected
? 'bg-gray-600 text-white hover:text-white'
: 'hover:text-gray-600')
}>
<Link href={link?.href} target={link?.target}>
{link?.icon && <i className={link?.icon} />} {link?.name}
</Link>
</div>
)}
{/* 子菜单 */}
{hasSubMenu && (
<ul
className={`${show ? 'visible opacity-100 top-14 ' : 'invisible opacity-0 top-10 '} absolute border bg-white dark:bg-black dark:border-gray-800 transition-all duration-300 z-20 block rounded-lg drop-shadow-lg p-4 `}>
{link?.subMenus?.map(sLink => {
return (
<li
key={sLink.id}
className='text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-900 tracking-widest transition-all duration-200 dark:border-gray-800 py-3 pr-6 pl-3'>
<Link href={sLink.href} target={link?.target}>
<span className='text-sm hover:underline'>
{link?.icon && <i className={sLink?.icon}> &nbsp; </i>}
{sLink.title}
</span>
</Link>
</li>
)
})}
</ul>
)}
</li>
)
}

View File

@@ -0,0 +1,29 @@
import Link from 'next/link'
import { useRouter } from 'next/router'
export const NormalMenu = props => {
const { link } = props
const router = useRouter()
if (!link || !link.show) {
return null
}
const selected = router.pathname === link.href || router.asPath === link.href
return (
<Link
key={`${link.href}`}
title={link.href}
href={link.href}
className={
'py-0.5 duration-500 justify-between text-gray-500 dark:text-gray-300 hover:text-black hover:underline cursor-pointer flex flex-nowrap items-center ' +
(selected ? 'text-black' : ' ')
}>
<div className='my-auto items-center justify-center flex '>
<div className={'hover:text-black'}>{link.name}</div>
</div>
{link.slot}
</Link>
)
}

View File

@@ -0,0 +1,30 @@
import Link from 'next/link'
import { useRouter } from 'next/router'
export const MenuItemPCNormal = props => {
const { link } = props
const router = useRouter()
const selected = router.pathname === link.href || router.asPath === link.href
if (!link || !link.show) {
return null
}
return (
<Link
key={`${link.id}-${link.href}`}
title={link.href}
href={link.href}
className={
'px-2 duration-300 text-sm justify-between dark:text-gray-300 cursor-pointer flex flex-nowrap items-center ' +
(selected
? 'bg-gray-600 text-white hover:text-white'
: 'hover:text-gray-600')
}>
<div className='items-center justify-center flex '>
<i className={link.icon} />
<div className='ml-2 whitespace-nowrap'>{link.name}</div>
</div>
{link.slot}
</Link>
)
}

View File

@@ -0,0 +1,55 @@
import { useGlobal } from '@/lib/global'
import Link from 'next/link'
import { useRouter } from 'next/router'
/**
* 简易翻页插件
* @param page 当前页码
* @param totalPage 是否有下一页
* @returns {JSX.Element}
* @constructor
*/
const PaginationSimple = ({ page, totalPage }) => {
const { locale } = useGlobal()
const router = useRouter()
const currentPage = +page
const showNext = currentPage < totalPage
const pagePrefix = router.asPath
.split('?')[0]
.replace(/\/page\/[1-9]\d*/, '')
.replace(/\/$/, '')
return (
<div className='my-10 flex justify-between font-medium text-black dark:text-gray-100 space-x-2'>
<Link
href={{
pathname:
currentPage === 2
? `${pagePrefix}/`
: `${pagePrefix}/page/${currentPage - 1}`,
query: router.query.s ? { s: router.query.s } : {}
}}
passHref
rel='prev'
className={`${
currentPage === 1 ? 'invisible' : 'block'
} text-center w-full duration-200 px-4 py-2 hover:border-gray-500 border-b-2 hover:font-bold`}>
{locale.PAGINATION.PREV}
</Link>
<Link
href={{
pathname: `${pagePrefix}/page/${currentPage + 1}`,
query: router.query.s ? { s: router.query.s } : {}
}}
passHref
rel='next'
className={`${
+showNext ? 'block' : 'invisible'
} text-center w-full duration-200 px-4 py-2 hover:border-gray-500 border-b-2 hover:font-bold`}>
{locale.PAGINATION.NEXT}
</Link>
</div>
)
}
export default PaginationSimple

View File

@@ -0,0 +1,87 @@
import { siteConfig } from '@/lib/config'
import PostListHorizontal from './PostListHorizontal'
/**
* 按文章类别分组的文章列表区块
* @returns {JSX.Element}
* @constructor
*/
const PostBannerGroupByCategory = props => {
const { posts, categoryOptions, allNavPages, latestPosts } = props
if (!posts || posts.length === 0) {
return null
}
// 按分类将文章分组成文件夹
const categoryFolders = groupArticles(categoryOptions, allNavPages.slice(8))
return (
<>
{/* 不同的分类文章列表 */}
{categoryFolders?.map((categoryGroup, index) => {
if (
!categoryGroup ||
!categoryGroup.items ||
categoryGroup.items.length < 1
) {
return null
}
return (
<PostListHorizontal
key={index}
hasBg={index % 2 === 1}
title={categoryGroup?.category}
href={`/category/${categoryGroup?.category}`}
posts={categoryGroup?.items}
/>
)
})}
</>
)
}
// 按照分类将文章分组成文件夹
function groupArticles(categoryOptions, allPosts) {
if (!allPosts) {
return []
}
const groups = []
for (let i = 0; i < allPosts.length; i++) {
const item = allPosts[i]
const categoryName = item?.category ? item?.category : '' // 将 category 转换为字符串
let existingGroup = groups.find(group => group.category === categoryName) // 搜索同名的最后一个分组
if (existingGroup && existingGroup.category === categoryName) {
// 如果分组已存在并且该分组中的文章数量小于4添加文章
if (existingGroup.items.length < 4) {
existingGroup.items.push(item)
}
} else {
// 新建分组,并添加当前文章
groups.push({ category: categoryName, items: [item] })
}
}
const hiddenCategory = siteConfig('MAGZINE_HOME_HIDDEN_CATEGORY')
// 按照 categoryOptions 的顺序排序 groups
const sortedGroups = []
for (let i = 0; i < categoryOptions.length; i++) {
const option = categoryOptions[i]
const matchingGroup = groups.find(group => group.category === option.name)
if (matchingGroup) {
if (
hiddenCategory &&
hiddenCategory.indexOf(matchingGroup.category) >= 0
) {
continue
}
sortedGroups.push(matchingGroup)
}
}
return sortedGroups
}
export default PostBannerGroupByCategory

View File

@@ -0,0 +1,34 @@
import PostItemCard from './PostItemCard'
/**
* 博客归档列表
* @param posts 所有文章
* @param archiveTitle 归档标题
* @returns {JSX.Element}
* @constructor
*/
const PostGroupArchive = ({ posts = [], archiveTitle }) => {
if (!posts || posts.length === 0) {
return <></>
}
return (
<div className=''>
{/* 分组标题 */}
<div
className='pb-4 text-2xl font-bold dark:text-gray-300'
id={archiveTitle}>
{archiveTitle}
</div>
{/* 列表 */}
<ul className='grid grid-cols-4 *:gap-4'>
{posts?.map((p, index) => {
return <PostItemCard key={index} post={p} />
})}
</ul>
</div>
)
}
export default PostGroupArchive

View File

@@ -0,0 +1,71 @@
import LazyImage from '@/components/LazyImage'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
// import Image from 'next/image'
import Link from 'next/link'
import { useRouter } from 'next/router'
/**
* 最新文章列表
* @param posts 所有文章数据
* @param sliceCount 截取展示的数量 默认6
* @constructor
*/
const PostGroupLatest = props => {
const { latestPosts } = props
// 获取当前路径
const currentPath = useRouter().asPath
const { locale, siteInfo } = useGlobal()
if (!latestPosts) {
return <></>
}
return (
<>
{/* 标题 */}
<div className=' mb-2 px-1 flex flex-nowrap justify-between'>
<div className='font-bold text-lg'>{locale.COMMON.LATEST_POSTS}</div>
</div>
{/* 文章列表 */}
<div className='grid grid-cols-1 lg:grid-cols-4'>
{latestPosts.map(post => {
const selected =
currentPath === `${siteConfig('SUB_PATH', '')}/${post.slug}`
const headerImage = post?.pageCoverThumbnail
? post.pageCoverThumbnail
: siteInfo?.pageCover
return (
<Link
key={post.id}
title={post.title}
href={`${siteConfig('SUB_PATH', '')}/${post.slug}`}
passHref
className={'my-3 flex'}>
<div className='w-20 h-14 overflow-hidden relative'>
<LazyImage
src={`${headerImage}`}
className='object-cover w-full h-full'
/>
</div>
<div
className={
(selected ? ' text-green-400 ' : 'dark:text-gray-400 ') +
' text-sm overflow-x-hidden hover:text-green-600 px-2 duration-200 w-full rounded ' +
' hover:text-green-400 cursor-pointer items-center flex'
}>
<div>
<div className='line-clamp-2 menu-link'>{post.title}</div>
<div className='text-gray-500'>{post.lastEditedDay}</div>
</div>
</div>
</Link>
)
})}
</div>
</>
)
}
export default PostGroupLatest

View File

@@ -0,0 +1,58 @@
import LazyImage from '@/components/LazyImage'
import NotionIcon from '@/components/NotionIcon'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import Link from 'next/link'
import CategoryItem from './CategoryItem'
/**
* 普通的博客卡牌
* 带封面图
*/
const PostItemCard = ({ post }) => {
const { siteInfo } = useGlobal()
const cover = post?.pageCoverThumbnail || siteInfo?.pageCover
return (
<div key={post.id} className='mb-6 max-w-screen-2xl'>
<div className='flex flex-col'>
{siteConfig('MAGZINE_POST_LIST_COVER') && (
<Link
href={post?.href}
passHref
className={
'cursor-pointer hover:underline leading-tight text-gray-700 dark:text-gray-300 hover:text-gray-500 dark:hover:text-gray-400'
}>
<div className='w-full h-40 aspect-video overflow-hidden mb-2'>
<LazyImage
src={cover}
style={cover ? {} : { height: '0px' }}
className='w-full h-40 aspect-video object-cover hover:scale-125 duration-150'
/>
</div>
</Link>
)}
{siteConfig('MAGZINE_POST_LIST_CATEGORY') && (
<CategoryItem category={post.category} />
)}
<Link
href={post?.href}
passHref
className={
'cursor-pointer hover:underline leading-tight text-gray-700 dark:text-gray-300 hover:text-gray-500 dark:hover:text-gray-400'
}>
<h2>
{siteConfig('POST_TITLE_ICON') && (
<NotionIcon icon={post.pageIcon} />
)}
{post.title}
</h2>
</Link>
<div className='text-sm py-1'>{post.date?.start_date}</div>
</div>
</div>
)
}
export default PostItemCard

View File

@@ -0,0 +1,43 @@
import NotionIcon from '@/components/NotionIcon'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import Link from 'next/link'
import CategoryItem from './CategoryItem'
/**
* 不带图片
* @param {*} param0
* @returns
*/
const PostItemCardSimple = ({ post, showSummary }) => {
const showPreview = siteConfig('MAGZINE_POST_LIST_PREVIEW') && post.blockMap
const { locale } = useGlobal()
return (
<div
key={post.id}
className='lg:mb-6 max-w-screen-2xl border-t mr-8 py-2 gap-y-4 flex flex-col dark:border-gray-800 '>
<div className='flex mr-2 items-center'>
{siteConfig('MAGZINE_POST_LIST_CATEGORY') && (
<CategoryItem category={post.category} />
)}
</div>
{/* 文章标题 */}
<Link
href={post?.href}
passHref
className={
'cursor-pointer hover:underline text-lg leading-tight dark:text-gray-300 dark:hover:text-gray-400'
}>
<h2>
{siteConfig('POST_TITLE_ICON') && <NotionIcon icon={post.pageIcon} />}
{post.title}
</h2>
</Link>
<div className='text-sm py-2 text-gray-700'>{post.date?.start_date}</div>
</div>
)
}
export default PostItemCardSimple

View File

@@ -0,0 +1,104 @@
import LazyImage from '@/components/LazyImage'
import NotionIcon from '@/components/NotionIcon'
import NotionPage from '@/components/NotionPage'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import Link from 'next/link'
import CategoryItem from './CategoryItem'
import TagItemMini from './TagItemMini'
/**
* 置顶头条文章
* @param {*} param0
* @returns
*/
const PostItemCardTop = ({ post, showSummary }) => {
const showPreview = siteConfig('MAGZINE_POST_LIST_PREVIEW') && post.blockMap
const { locale } = useGlobal()
return (
<div
key={post.id}
data-aos='fade-up'
data-aos-duration='300'
data-aos-once='false'
data-aos-anchor-placement='top-bottom'
className='mb-6 max-w-screen-2xl '>
<div className='flex flex-col w-full'>
{siteConfig('MAGZINE_POST_LIST_COVER') && (
<Link
href={post?.href}
passHref
className={
'cursor-pointer hover:underline text-4xl leading-tight dark:text-gray-300 dark:hover:text-gray-400'
}>
<div className='w-full max-h-80 object-cover overflow-hidden mb-2'>
<LazyImage
src={post.pageCoverThumbnail}
style={post.pageCoverThumbnail ? {} : { height: '0px' }}
className='w-full max-h-80 object-cover hover:scale-125 duration-150'
/>
</div>
</Link>
)}
<div className='flex py-2 mr-2 items-center'>
{siteConfig('MAGZINE_POST_LIST_CATEGORY') && (
<CategoryItem category={post.category} />
)}
<div
className={
'flex items-center justify-start flex-wrap space-x-3 text-gray-400'
}>
{siteConfig('MAGZINE_POST_LIST_TAG') &&
post?.tagItems?.map(tag => (
<TagItemMini key={tag.name} tag={tag} />
))}
</div>
</div>
<Link
href={post?.href}
passHref
className={
'cursor-pointer hover:underline leading-tight dark:text-gray-300 dark:hover:text-gray-400'
}>
<h2 className='text-4xl'>
{siteConfig('POST_TITLE_ICON') && (
<NotionIcon icon={post.pageIcon} />
)}
{post.title}
</h2>
</Link>
<div className='flex'></div>
{(!showPreview || showSummary) && (
<main className='my-4 text-gray-900 dark:text-gray-300 text-lg leading-7'>
{post.summary}
</main>
)}
{showPreview && (
<div className='overflow-ellipsis truncate'>
<NotionPage post={post} />
<div className='pointer-events-none border-t pt-8 border-dashed'>
<div className='w-full justify-start flex'>
<Link
href={post?.href}
passHref
className='hover:bg-opacity-100 hover:scale-105 duration-200 pointer-events-auto transform font-bold text-gray-500 cursor-pointer'>
{locale.COMMON.ARTICLE_DETAIL}
<i className='ml-1 fas fa-angle-right' />
</Link>
</div>
</div>
</div>
)}
<div className='text-sm py-1'>{post.date?.start_date}</div>
</div>
</div>
)
}
export default PostItemCardTop

View File

@@ -0,0 +1,86 @@
import LazyImage from '@/components/LazyImage'
import NotionIcon from '@/components/NotionIcon'
import NotionPage from '@/components/NotionPage'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import Link from 'next/link'
import CategoryItem from './CategoryItem'
import TagItemMini from './TagItemMini'
/**
* 水平左右布局的博客卡片
* @param {*} param0
* @returns
*/
const PostItemCardWide = ({ post, showSummary }) => {
const showPreview = siteConfig('MAGZINE_POST_LIST_PREVIEW') && post.blockMap
const { locale } = useGlobal()
return (
<div key={post.id} className='flex justify-between space-x-6 mb-6 '>
{/* 卡牌左侧 */}
<div className='h-40 w-96'>
<Link
href={post?.href}
passHref
className={
' cursor-pointer font-semibold hover:underline text-xl leading-tight dark:text-gray-300 dark:hover:text-gray-400'
}>
<h3 className='max-w-80 break-words'>
{siteConfig('POST_TITLE_ICON') && (
<NotionIcon icon={post.pageIcon} />
)}
{post.title}
</h3>
</Link>
{(!showPreview || showSummary) && (
<main className='my-4 line-clamp-2 text-gray-900 dark:text-gray-300 text-sm'>
{post.summary}
</main>
)}
{showPreview && (
<div className='overflow-ellipsis truncate'>
<NotionPage post={post} />
<div className='pointer-events-none border-t pt-8 border-dashed'>
<div className='w-full justify-start flex'>
<Link
href={post?.href}
passHref
className='hover:bg-opacity-100 hover:scale-105 duration-200 pointer-events-auto transform font-bold text-gray-500 cursor-pointer'>
{locale.COMMON.ARTICLE_DETAIL}
<i className='ml-1 fas fa-angle-right' />
</Link>
</div>
</div>
</div>
)}
<div
className={
'flex mt-2 items-center justify-start flex-wrap space-x-3 text-gray-400'
}>
{siteConfig('MAGZINE_POST_LIST_CATEGORY') && (
<CategoryItem category={post.category} />
)}
{siteConfig('MAGZINE_POST_LIST_TAG') &&
post?.tagItems?.map(tag => (
<TagItemMini key={tag.name} tag={tag} />
))}
<div className='text-sm py-1'>{post.date?.start_date}</div>
</div>
</div>
{/* 卡牌右侧图片 */}
<div className='w-40 h-40 object-cover overflow-hidden mb-2'>
<LazyImage
src={post.pageCoverThumbnail}
style={post.pageCoverThumbnail ? {} : { height: '0px' }}
className='w-40 h-40 object-cover hover:scale-125 duration-150'
/>
</div>
</div>
)
}
export default PostItemCardWide

View File

@@ -0,0 +1,19 @@
import { useGlobal } from '@/lib/global'
/**
* 空白博客 列表
* @returns {JSX.Element}
* @constructor
*/
const PostListEmpty = ({ currentSearch }) => {
const { locale } = useGlobal()
return (
<div className='flex w-full items-center justify-center min-h-screen mx-auto md:-mt-20'>
<p className='text-gray-500 dark:text-gray-300'>
{locale.COMMON.NO_RESULTS_FOUND}{' '}
{currentSearch && <div>{currentSearch}</div>}
</p>
</div>
)
}
export default PostListEmpty

View File

@@ -0,0 +1,39 @@
import Link from 'next/link'
import PostItemCard from './PostItemCard'
import PostListEmpty from './PostListEmpty'
/**
* 博文水平列表
* 含封面
* 可以指定是否有模块背景色
* @returns {JSX.Element}
* @constructor
*/
const PostListHorizontal = ({ title, href, posts, hasBg }) => {
if (!posts || posts.length === 0) {
return <PostListEmpty />
}
return (
<div className={`w-full py-10 px-2 lg:px-0 ${hasBg ? 'bg-[#F6F6F1]' : ''}`}>
<div className='max-w-screen-2xl w-full mx-auto'>
{/* 标题 */}
<div className='flex justify-between items-center py-6'>
<h3 className='text-2xl'>{title}</h3>
<Link className='text-lg underline' href={href}>
<span>查看全部</span>
<i className='ml-2 fas fa-arrow-right' />
</Link>
</div>
{/* 列表 */}
<ul className='grid grid-cols-1 lg:grid-cols-4 gap-4'>
{posts?.map((p, index) => {
return <PostItemCard key={index} post={p} />
})}
</ul>
</div>
</div>
)
}
export default PostListHorizontal

View File

@@ -0,0 +1,39 @@
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import PaginationSimple from './PaginationSimple'
import PostItemCard from './PostItemCard'
import PostListEmpty from './PostListEmpty'
/**
* 文章列表分页表格
* @param page 当前页
* @param posts 所有文章
* @param tags 所有标签
* @returns {JSX.Element}
* @constructor
*/
const PostListPage = ({ page = 1, posts = [], postCount }) => {
const { NOTION_CONFIG } = useGlobal()
const POSTS_PER_PAGE = siteConfig('POSTS_PER_PAGE', null, NOTION_CONFIG)
const totalPage = Math.ceil(postCount / POSTS_PER_PAGE)
if (!posts || posts.length === 0) {
return <PostListEmpty />
}
return (
<div className='w-full justify-center'>
<div id='posts-wrapper'>
{/* 列表 */}
<ul className='grid grid-cols-4 gap-4'>
{posts?.map((p, index) => {
return <PostItemCard key={index} post={p} />
})}
</ul>
</div>
<PaginationSimple page={page} totalPage={totalPage} />
</div>
)
}
export default PostListPage

View File

@@ -0,0 +1,79 @@
import { siteConfig } from '@/lib/config'
import PostItemCard from './PostItemCard'
import PostListEmpty from './PostListEmpty'
/**
* 博文水平列表
* 含封面
* 可以指定是否有模块背景色
* @returns {JSX.Element}
* @constructor
*/
const PostListRecommend = ({ latestPosts, allNavPages }) => {
// 获取推荐文章
const recommendPosts = getTopPosts({ latestPosts, allNavPages })
if (!recommendPosts || recommendPosts.length === 0) {
return <PostListEmpty />
}
const title = siteConfig('MAGZINE_RECOMMEND_POST_TITLE')
return (
<div className={`w-full py-10 px-2 bg-[#F6F6F1]`}>
<div className='max-w-screen-2xl w-full mx-auto'>
{/* 标题 */}
<div className='flex justify-between items-center py-6'>
<h3 className='text-4xl font-bold'>{title}</h3>
</div>
{/* 列表 */}
<ul className='flex flex-col lg:flex-row gap-4 lg:overflow-x-scroll'>
{recommendPosts?.map(p => {
return <PostItemCard key={p.id} post={p} />
})}
</ul>
</div>
</div>
)
}
/**
* 获取推荐置顶文章
*/
function getTopPosts({ latestPosts, allNavPages }) {
// 默认展示最近更新
if (
!siteConfig('MAGZINE_RECOMMEND_POST_TAG') ||
siteConfig('MAGZINE_RECOMMEND_POST_TAG') === ''
) {
return latestPosts
}
// 显示包含‘推荐’标签的文章
let sortPosts = []
// 排序方式
if (siteConfig('MAGZINE_RECOMMEND_POST_SORT_BY_UPDATE_TIME')) {
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 count = siteConfig('MAGZINE_RECOMMEND_POST_COUNT', 6)
// 只取前4篇
const topPosts = []
for (const post of sortPosts) {
if (topPosts.length === count) {
break
}
// 查找标签
if (post?.tags?.indexOf(siteConfig('MAGZINE_RECOMMEND_POST_TAG')) >= 0) {
topPosts.push(post)
}
}
return topPosts
}
export default PostListRecommend

View File

@@ -0,0 +1,107 @@
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import throttle from 'lodash.throttle'
import { useRouter } from 'next/router'
import { useCallback, useEffect, useRef, useState } from 'react'
import PostItemCard from './PostItemCard'
import PostListEmpty from './PostListEmpty'
/**
* 博客列表滚动分页
* @param posts 所有文章
* @param tags 所有标签
* @returns {JSX.Element}
* @constructor
*/
const PostListScroll = ({ posts = [], currentSearch }) => {
const { NOTION_CONFIG } = useGlobal()
const POSTS_PER_PAGE = siteConfig('POSTS_PER_PAGE', null, NOTION_CONFIG)
const [page, updatePage] = useState(1)
const router = useRouter()
let filteredPosts = Object.assign(posts)
const searchKey = router?.query?.s || null
if (searchKey) {
filteredPosts = posts.filter(post => {
const tagContent = post?.tags ? post?.tags.join(' ') : ''
const searchContent = post.title + post.summary + tagContent
return searchContent.toLowerCase().includes(searchKey.toLowerCase())
})
}
const postsToShow = getPostByPage(page, filteredPosts, POSTS_PER_PAGE)
let hasMore = false
if (filteredPosts) {
const totalCount = filteredPosts.length
hasMore = page * POSTS_PER_PAGE < totalCount
}
const handleGetMore = () => {
if (!hasMore) return
updatePage(page + 1)
}
// 监听滚动自动分页加载
const scrollTrigger = useCallback(
throttle(() => {
const scrollS = window.scrollY + window.outerHeight
const clientHeight = targetRef
? targetRef.current
? targetRef.current.clientHeight
: 0
: 0
if (scrollS > clientHeight + 100) {
handleGetMore()
}
}, 500)
)
// 监听滚动
useEffect(() => {
window.addEventListener('scroll', scrollTrigger)
return () => {
window.removeEventListener('scroll', scrollTrigger)
}
})
const targetRef = useRef(null)
const { locale } = useGlobal()
if (!postsToShow || postsToShow.length === 0) {
return <PostListEmpty currentSearch={currentSearch} />
} else {
return (
<div id='posts-wrapper' ref={targetRef} className='w-full'>
{/* 文章列表 */}
<div className='space-y-1 lg:space-y-4'>
{postsToShow?.map(post => (
<PostItemCard key={post.id} post={post} showSummary={true} />
))}
</div>
<div>
<div
onClick={() => {
handleGetMore()
}}
className='w-full my-4 py-4 text-center cursor-pointer dark:text-gray-200'>
{' '}
{hasMore ? locale.COMMON.MORE : `${locale.COMMON.NO_MORE} 😰`}{' '}
</div>
</div>
</div>
)
}
}
/**
* 获取从第1页到指定页码的文章
* @param page 第几页
* @param totalPosts 所有文章
* @param POSTS_PER_PAGE 每页文章数量
* @returns {*}
*/
const getPostByPage = function (page, totalPosts, POSTS_PER_PAGE) {
return totalPosts.slice(0, POSTS_PER_PAGE * page)
}
export default PostListScroll

View File

@@ -0,0 +1,37 @@
import Link from 'next/link'
import PostItemCardSimple from './PostItemCardSimple'
import PostListEmpty from './PostListEmpty'
/**
* 博文水平列表;不带封面图
* @returns {JSX.Element}
* @constructor
*/
const PostSimpleListHorizontal = ({ title, href, posts }) => {
if (!posts || posts.length === 0) {
return <PostListEmpty />
}
return (
<div className='w-full py-10 bg-[#F6F6F1]'>
<div className='max-w-screen-2xl w-full mx-auto px-2'>
{/* 标题 */}
<div className='flex justify-between items-center py-6'>
<h3 className='text-2xl'>{title}</h3>
<Link className='text-lg underline' href={href}>
<span>查看全部</span>
<i className='ml-2 fas fa-arrow-right' />
</Link>
</div>
{/* 列表 */}
<ul className='grid grid-cols-1 lg:grid-cols-4'>
{posts?.map(p => {
return <PostItemCardSimple key={p.id} post={p} />
})}
</ul>
</div>
</div>
)
}
export default PostSimpleListHorizontal

View File

@@ -0,0 +1,29 @@
import { useGlobal } from '@/lib/global'
/**
* 文章列表上方嵌入
* @param {*} props
* @returns
*/
export default function PostListSlotBar(props) {
const { tag, category } = props
const { locale } = useGlobal()
if (tag) {
return (
<div className='flex items-center text-xl py-8'>
<i className='mr-2 fas fa-tag' />
{locale.COMMON.TAGS}:{tag}
</div>
)
} else if (category) {
return (
<div className='flex items-center text-xl py-8'>
<i className='mr-2 fas fa-th' />
{locale.COMMON.CATEGORY}:{category}
</div>
)
} else {
return <></>
}
}

View File

@@ -0,0 +1,44 @@
import { useEffect, useState } from 'react'
import { isBrowser } from '@/lib/utils'
/**
* 顶部页面阅读进度条
* @returns {JSX.Element}
* @constructor
*/
const Progress = ({ targetRef, showPercent = true }) => {
const currentRef = targetRef?.current || targetRef
const [percent, changePercent] = useState(0)
const scrollListener = () => {
const target = currentRef || (isBrowser && document.getElementById('article-wrapper'))
if (target) {
const clientHeight = target.clientHeight
const scrollY = window.pageYOffset
const fullHeight = clientHeight - window.outerHeight
let per = parseFloat(((scrollY / fullHeight) * 100).toFixed(0))
if (per > 100) per = 100
if (per < 0) per = 0
changePercent(per)
}
}
useEffect(() => {
document.addEventListener('scroll', scrollListener)
return () => document.removeEventListener('scroll', scrollListener)
}, [])
return (
<div className="h-4 w-full shadow-2xl bg-hexo-light-gray dark:bg-black">
<div
className="h-4 bg-gray-600 duration-200"
style={{ width: `${percent}%` }}
>
{showPercent && (
<div className="text-right text-white text-xs">{percent}%</div>
)}
</div>
</div>
)
}
export default Progress

View File

@@ -0,0 +1,36 @@
import { useEffect, useState } from 'react'
export default function RevolverMaps () {
const [load, changeLoad] = useState(false)
useEffect(() => {
if (!load) {
initRevolverMaps()
changeLoad(true)
}
})
return <div id="revolvermaps" className='p-4'/>
}
function initRevolverMaps () {
if (screen.width >= 768) {
Promise.all([
loadExternalResource('https://rf.revolvermaps.com/0/0/8.js?i=5jnp1havmh9&amp;m=0&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33')
]).then(() => {
// console.log('地图加载完成')
})
}
}
// 封装异步加载资源的方法
function loadExternalResource (url) {
return new Promise((resolve, reject) => {
const container = document.getElementById('revolvermaps')
const tag = document.createElement('script')
tag.src = url
if (tag) {
tag.onload = () => resolve(url)
tag.onerror = () => reject(url)
container.appendChild(tag)
}
})
}

View File

@@ -0,0 +1,97 @@
import { useRouter } from 'next/router'
import { useImperativeHandle, useRef, useState } from 'react'
let lock = false
const SearchInput = ({ currentTag, currentSearch, cRef, className }) => {
const [onLoading, setLoadingState] = useState(false)
const router = useRouter()
const searchInputRef = useRef()
useImperativeHandle(cRef, () => {
return {
focus: () => {
searchInputRef?.current?.focus()
}
}
})
const handleSearch = () => {
const key = searchInputRef.current.value
if (key && key !== '') {
setLoadingState(true)
location.href = '/search/' + key
} else {
router.push({ pathname: '/' }).then(r => {})
}
}
const handleKeyUp = e => {
if (e.keyCode === 13) {
// 回车
handleSearch(searchInputRef.current.value)
} else if (e.keyCode === 27) {
// ESC
cleanSearch()
}
}
const cleanSearch = () => {
searchInputRef.current.value = ''
}
const [showClean, setShowClean] = useState(false)
const updateSearchKey = val => {
if (lock) {
return
}
searchInputRef.current.value = val
if (val) {
setShowClean(true)
} else {
setShowClean(false)
}
}
function lockSearchInput() {
lock = true
}
function unLockSearchInput() {
lock = false
}
return (
<div className={'flex w-full bg-gray-100 ' + className}>
<input
ref={searchInputRef}
type='text'
className={
'outline-none w-full text-sm pl-2 transition focus:shadow-lg leading-10 text-black bg-gray-100 dark:bg-gray-900 dark:text-white'
}
onKeyUp={handleKeyUp}
onCompositionStart={lockSearchInput}
onCompositionUpdate={lockSearchInput}
onCompositionEnd={unLockSearchInput}
onChange={e => updateSearchKey(e.target.value)}
defaultValue={currentSearch}
/>
<div
className='-ml-8 cursor-pointer float-right items-center justify-center py-2'
onClick={handleSearch}>
<i
className={`hover:text-black transform duration-200 text-gray-500 dark:hover:text-gray-300 cursor-pointer fas ${onLoading ? 'fa-spinner animate-spin' : 'fa-search'} `}
/>
</div>
{showClean && (
<div className='-ml-12 cursor-pointer float-right items-center justify-center py-2'>
<i
className='fas fa-times hover:text-black transform duration-200 text-gray-400 cursor-pointer dark:hover:text-gray-300'
onClick={cleanSearch}
/>
</div>
)}
</div>
)
}
export default SearchInput

View File

@@ -0,0 +1,104 @@
import { siteConfig } from '@/lib/config'
/**
* 社交联系方式按钮组
* @returns {JSX.Element}
* @constructor
*/
const SocialButton = () => {
return (
<div className='space-x-3 text-xl text-white flex-wrap flex justify-start '>
{siteConfig('CONTACT_GITHUB') && (
<a
target='_blank'
rel='noreferrer'
title={'github'}
href={siteConfig('CONTACT_GITHUB')}>
<i className='fab fa-github transform hover:scale-125 duration-150 hover:text-gray-100' />
</a>
)}
{siteConfig('CONTACT_TWITTER') && (
<a
target='_blank'
rel='noreferrer'
title={'twitter'}
href={siteConfig('CONTACT_TWITTER')}>
<i className='fab fa-twitter transform hover:scale-125 duration-150 hover:text-gray-100' />
</a>
)}
{siteConfig('CONTACT_TELEGRAM') && (
<a
target='_blank'
rel='noreferrer'
href={siteConfig('CONTACT_TELEGRAM')}
title={'telegram'}>
<i className='fab fa-telegram transform hover:scale-125 duration-150 hover:text-gray-100' />
</a>
)}
{siteConfig('CONTACT_LINKEDIN') && (
<a
target='_blank'
rel='noreferrer'
href={siteConfig('CONTACT_LINKEDIN')}
title={'linkedIn'}>
<i className='transform hover:scale-125 duration-150 fab fa-linkedin dark:hover:text-indigo-400 hover:text-indigo-600' />
</a>
)}
{siteConfig('CONTACT_WEIBO') && (
<a
target='_blank'
rel='noreferrer'
title={'weibo'}
href={siteConfig('CONTACT_WEIBO')}>
<i className='fab fa-weibo transform hover:scale-125 duration-150 hover:text-gray-100' />
</a>
)}
{siteConfig('CONTACT_INSTAGRAM') && (
<a
target='_blank'
rel='noreferrer'
title={'instagram'}
href={siteConfig('CONTACT_INSTAGRAM')}>
<i className='fab fa-instagram transform hover:scale-125 duration-150 hover:text-gray-100' />
</a>
)}
{siteConfig('CONTACT_EMAIL') && (
<a
target='_blank'
rel='noreferrer'
title={'email'}
href={`mailto:${siteConfig('CONTACT_EMAIL')}`}>
<i className='fas fa-envelope transform hover:scale-125 duration-150 hover:text-gray-100' />
</a>
)}
{JSON.parse(siteConfig('ENABLE_RSS')) && (
<a
target='_blank'
rel='noreferrer'
title={'RSS'}
href={'/rss/feed.xml'}>
<i className='fas fa-rss transform hover:scale-125 duration-150 hover:text-gray-100' />
</a>
)}
{siteConfig('CONTACT_BILIBILI') && (
<a
target='_blank'
rel='noreferrer'
title={'bilibili'}
href={siteConfig('CONTACT_BILIBILI')}>
<i className='fab fa-bilibili transform hover:scale-125 duration-150 hover:text-gray-100' />
</a>
)}
{siteConfig('CONTACT_YOUTUBE') && (
<a
target='_blank'
rel='noreferrer'
title={'youtube'}
href={siteConfig('CONTACT_YOUTUBE')}>
<i className='fab fa-youtube transform hover:scale-125 duration-150 hover:text-gray-100' />
</a>
)}
</div>
)
}
export default SocialButton

View File

@@ -0,0 +1,30 @@
import { useGlobal } from '@/lib/global'
import TagItemMini from './TagItemMini'
/**
* 标签组
* @param tags
* @param currentTag
* @returns {JSX.Element}
* @constructor
*/
const TagGroups = ({ tagOptions, currentTag }) => {
const { locale } = useGlobal()
if (!tagOptions) return <></>
return (
<div id='tags-group' className='dark:border-gray-600 py-4'>
<div className='mb-2'>
<i className='mr-2 fas fa-tag' />
{locale.COMMON.TAGS}
</div>
<div className='space-y-2'>
{tagOptions?.map(tag => {
const selected = tag.name === currentTag
return <TagItemMini key={tag.name} tag={tag} selected={selected} />
})}
</div>
</div>
)
}
export default TagGroups

View File

@@ -0,0 +1,24 @@
import Link from 'next/link'
const TagItemMini = ({ tag, selected = false }) => {
return (
<Link
key={tag}
href={selected ? '/' : `/tag/${encodeURIComponent(tag.name)}`}
passHref
className={`cursor-pointer inline-block rounded hover:bg-gray-500 hover:text-white duration-200
mr-2 py-1 px-2 text-xs whitespace-nowrap dark:hover:text-white
${
selected
? 'text-white dark:text-gray-300 dark:hover:bg-gray-900'
: `text-gray-900 hover:shadow-xl dark:border-gray-400 dark:bg-gray-800`
}`}>
<div className=' dark:text-gray-400'>
{/* {selected && <i className='mr-1 fas fa-tag'/>} */}#
{tag.name + (tag.count ? `(${tag.count})` : '')}{' '}
</div>
</Link>
)
}
export default TagItemMini

View File

@@ -0,0 +1,48 @@
import { useMagzineGlobal } from '..'
import Catalog from './Catalog'
/**
* 悬浮抽屉目录
* @param toc
* @param post
* @returns {JSX.Element}
* @constructor
*/
const TocDrawer = ({ post, cRef }) => {
const { tocVisible, changeTocVisible } = useMagzineGlobal()
const switchVisible = () => {
changeTocVisible(!tocVisible)
}
return (
<>
<div id='medium-toc-float' className='fixed top-0 right-0 z-40'>
{/* 侧边菜单 */}
<div
className={
(tocVisible
? 'animate__slideInRight '
: ' -mr-72 animate__slideOutRight') +
' overflow-y-hidden shadow-card w-60 duration-200 fixed right-1 bottom-16 rounded py-2 bg-white dark:bg-gray-600'
}>
{post && (
<>
<div className='dark:text-gray-400 text-gray-600 h-56'>
<Catalog toc={post.toc} />
</div>
</>
)}
</div>
</div>
{/* 背景蒙版 */}
<div
id='right-drawer-background'
className={
(tocVisible ? 'block' : 'hidden') +
' fixed top-0 left-0 z-30 w-full h-full'
}
onClick={switchVisible}
/>
</>
)
}
export default TocDrawer

View File

@@ -0,0 +1,109 @@
import Collapse from '@/components/Collapse'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import { useRef, useState } from 'react'
import LogoBar from './LogoBar'
import { MenuBarMobile } from './MenuBarMobile'
import { MenuItemDrop } from './MenuItemDrop'
/**
* 顶部导航栏 + 菜单
* @param {} param0
* @returns
*/
export default function TopNavBar(props) {
const { className, customNav, customMenu } = props
const [isOpen, changeShow] = useState(false)
const collapseRef = useRef(null)
const { locale } = useGlobal()
const defaultLinks = [
{
icon: 'fas fa-th',
name: locale.COMMON.CATEGORY,
href: '/category',
show: siteConfig('MAGZINE_MENU_CATEGORY')
},
{
icon: 'fas fa-tag',
name: locale.COMMON.TAGS,
href: '/tag',
show: siteConfig('MAGZINE_MENU_TAG')
},
{
icon: 'fas fa-archive',
name: locale.NAV.ARCHIVE,
href: '/archive',
show: siteConfig('MAGZINE_MENU_ARCHIVE')
},
{
icon: 'fas fa-search',
name: locale.NAV.SEARCH,
href: '/search',
show: siteConfig('MAGZINE_MENU_SEARCH')
}
]
let links = defaultLinks.concat(customNav)
const toggleMenuOpen = () => {
changeShow(!isOpen)
}
// 如果 开启自定义菜单则覆盖Page生成的菜单
if (siteConfig('CUSTOM_MENU')) {
links = customMenu
}
if (!links || links.length === 0) {
return null
}
return (
<div
id='top-nav'
className={'sticky top-0 lg:relative w-full z-40 ' + className}>
{/* 移动端折叠菜单 */}
<Collapse
type='vertical'
collapseRef={collapseRef}
isOpen={isOpen}
className='md:hidden'>
<div className='bg-white dark:bg-hexo-black-gray pt-1 py-2 lg:hidden '>
<MenuBarMobile
{...props}
onHeightChange={param =>
collapseRef.current?.updateCollapseHeight(param)
}
/>
</div>
</Collapse>
{/* 导航栏菜单 */}
<div className='flex w-full h-12 shadow bg-white dark:bg-hexo-black-gray px-7 items-between'>
{/* 左侧图标Logo */}
<LogoBar {...props} />
{/* 折叠按钮、仅移动端显示 */}
<div className='mr-1 flex md:hidden justify-end items-center text-sm space-x-4 font-serif dark:text-gray-200'>
<div onClick={toggleMenuOpen} className='cursor-pointer'>
{isOpen ? (
<i className='fas fa-times' />
) : (
<i className='fas fa-bars' />
)}
</div>
</div>
{/* 桌面端顶部菜单 */}
<div className='hidden md:flex'>
{links &&
links?.map((link, index) => (
<MenuItemDrop key={index} link={link} />
))}
</div>
</div>
</div>
)
}

View File

@@ -0,0 +1,39 @@
import FlipCard from '@/components/FlipCard'
import { siteConfig } from '@/lib/config'
import Link from 'next/link'
/**
* 交流频道
* @returns
*/
export default function TouchMeCard() {
// 开关
if (!siteConfig('MAGZINE_SOCIAL_CARD', null)) {
return <></>
}
return (
<div className={'relative h-32 text-black flex flex-col'}>
<FlipCard
className='cursor-pointer lg:py-8 px-4 py-4 border bg-[#7BE986] dark:bg-yellow-600 dark:border-gray-600'
frontContent={
<div className='h-full'>
<h2 className='font-[1000] text-3xl'>
{siteConfig('MAGZINE_SOCIAL_CARD_TITLE_1')}
</h2>
<h3 className='pt-2'>
{siteConfig('MAGZINE_SOCIAL_CARD_TITLE_2')}
</h3>
</div>
}
backContent={
<Link href={siteConfig('MAGZINE_SOCIAL_CARD_URL')}>
<div className='font-[1000] text-xl h-full'>
{siteConfig('MAGZINE_SOCIAL_CARD_TITLE_3')}
</div>
</Link>
}
/>
</div>
)
}

130
themes/magzine/config.js Normal file
View File

@@ -0,0 +1,130 @@
const CONFIG = {
// 首屏信息栏按钮文字
MAGZINE_HOME_BANNER_ENABLE: true, // 首屏右上角的宣传位
MAGZINE_HOME_BUTTON: true,
MAGZINE_HOME_BUTTON_URL: '/about',
MAGZINE_HOME_BUTTON_TEXT: '了解更多',
MAGZINE_HOME_HIDDEN_CATEGORY: '分享杂文', //不希望在首页展示的文章分类,用英文逗号隔开
MAGZINE_HOME_TITLE: '立即开创您的在线业务。完全免费。',
MAGZINE_HOME_DESCRIPTION:
'借助NotionNext获得助您开创、经营和扩展业务所需的全部工具和帮助。',
MAGZINE_HOME_TIPS: 'AI时代来临这是属于超级个体的狂欢盛宴',
// 首页底部推荐文章标签, 例如 [推荐] , 最多六篇文章; 若留空白'',则推荐最近更新文章
MAGZINE_RECOMMEND_POST_TAG: '推荐',
MAGZINE_RECOMMEND_POST_COUNT: 6,
MAGZINE_RECOMMEND_POST_TITLE: '推荐文章',
MAGZINE_RECOMMEND_POST_SORT_BY_UPDATE_TIME: false, // 推荐文章排序,为`true`时将强制按最后修改时间倒序
// Style
MAGZINE_RIGHT_PANEL_DARK: process.env.NEXT_PUBLIC_MAGZINE_RIGHT_DARK || false, // 右侧面板深色模式
MAGZINE_POST_LIST_COVER: true, // 文章列表显示图片封面
MAGZINE_POST_LIST_PREVIEW: true, // 列表显示文章预览
MAGZINE_POST_LIST_CATEGORY: true, // 列表显示文章分类
MAGZINE_POST_LIST_TAG: true, // 列表显示文章标签
MAGZINE_POST_DETAIL_CATEGORY: true, // 文章显示分类
MAGZINE_POST_DETAIL_TAG: true, // 文章显示标签
// 文章页面联系卡
MAGZINE_SOCIAL_CARD: true, // 是否显示右侧,点击加入社群按钮
MAGZINE_SOCIAL_CARD_TITLE_1: '交流频道',
MAGZINE_SOCIAL_CARD_TITLE_2: '加入社群讨论分享',
MAGZINE_SOCIAL_CARD_TITLE_3: '点击加入社群',
MAGZINE_SOCIAL_CARD_URL: 'https://docs.tangly1024.com/article/chat-community',
// 页脚菜单
MAGZINE_FOOTER_LINKS: [
{
name: '友情链接',
menus: [
{ title: '尘世の歌', href: 'https://chenge.ink' },
{
title: '设计狮网址导航',
href: 'https://ct.ued.cat/'
},
{
title: '积极的长腿怪',
href: 'https://jjdctg.com'
},
{
title: '自动驾驶小白说',
href: 'https://www.helloxiaobai.cn/about'
},
{
title: 'AI-皇帝',
href: 'https://www.ai-hd.com/'
},
{
title: 'Andy`s Pro',
href: 'https://tw.andys.pro/'
},
{ title: 'LUCEN', href: 'https://www.lucenczz.top/' }
]
},
{
name: '开发者',
menus: [
{ title: 'Github', href: 'https://github.com/tangly1024/NotionNext' },
{
title: '开发帮助',
href: 'https://docs.tangly1024.com/article/how-to-develop-with-notion-next'
},
{
title: '功能反馈',
href: 'https://github.com/tangly1024/NotionNext/issues/new/choose'
},
{
title: '技术讨论',
href: 'https://github.com/tangly1024/NotionNext/discussions'
},
{
title: '关于作者',
href: 'https://blog.tangly1024.com/about'
}
]
},
{
name: '支持',
menus: [
{
title: '站长社群',
href: 'https://docs.tangly1024.com/article/chat-community'
},
{
title: '咨询与定制',
href: 'https://docs.tangly1024.com/article/my-service'
},
{
title: '升级手册',
href: 'https://docs.tangly1024.com/article/my-service'
},
{
title: '安装教程',
href: 'https://docs.tangly1024.com/article/how-to-update-notionnext'
},
{ title: 'SEO推广', href: 'https://seo.tangly1024.com/' }
]
},
{
name: '解决方案',
menus: [
{ title: '建站工具', href: 'https://www.tangly1024.com/' },
{ title: 'NotionNext', href: 'https://docs.tangly1024.com/about' }
]
}
],
// 旧版本顶部菜单
MAGZINE_MENU_CATEGORY: true, // 显示分类
MAGZINE_MENU_TAG: true, // 显示标签
MAGZINE_MENU_ARCHIVE: true, // 显示归档
MAGZINE_MENU_SEARCH: true, // 显示搜索
MAGZINE_WIDGET_TO_TOP: true // 跳回顶部
}
export default CONFIG

435
themes/magzine/index.js Normal file
View File

@@ -0,0 +1,435 @@
import Comment from '@/components/Comment'
import LoadingCover from '@/components/LoadingCover'
import replaceSearchResult from '@/components/Mark'
import NotionPage from '@/components/NotionPage'
import ShareBar from '@/components/ShareBar'
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import { isBrowser } from '@/lib/utils'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { createContext, useContext, useEffect, useState } from 'react'
import Announcement from './components/Announcement'
import ArticleInfo from './components/ArticleInfo'
import { ArticleLock } from './components/ArticleLock'
import BannerFullWidth from './components/BannerFullWidth'
import Catalog from './components/Catalog'
import CategoryGroup from './components/CategoryGroup'
import CategoryItem from './components/CategoryItem'
import Footer from './components/Footer'
import Header from './components/Header'
import Hero from './components/Hero'
import PostBannerGroupByCategory from './components/PostBannerGroupByCategory'
import PostGroupArchive from './components/PostGroupArchive'
import PostGroupLatest from './components/PostGroupLatest'
import PostListPage from './components/PostListPage'
import PostListRecommend from './components/PostListRecommend'
import PostListScroll from './components/PostListScroll'
import PostSimpleListHorizontal from './components/PostListSimpleHorizontal'
import TagGroups from './components/TagGroups'
import TagItemMini from './components/TagItemMini'
import TocDrawer from './components/TocDrawer'
import TouchMeCard from './components/TouchMeCard'
import CONFIG from './config'
import { Style } from './style'
// 主题全局状态
const ThemeGlobalMagzine = createContext()
export const useMagzineGlobal = () => useContext(ThemeGlobalMagzine)
/**
* 基础布局
* 采用左右两侧布局,移动端使用顶部导航栏
* @returns {JSX.Element}
* @constructor
*/
const LayoutBase = props => {
const { children, notice, showInfoCard = true, post } = props
const { locale } = useGlobal()
const router = useRouter()
const [tocVisible, changeTocVisible] = useState(false)
const { onLoading, fullWidth } = useGlobal()
const [slotRight, setSlotRight] = useState(null)
return (
<ThemeGlobalMagzine.Provider value={{ tocVisible, changeTocVisible }}>
{/* CSS样式 */}
<Style />
<div
id='theme-medium'
className={`${siteConfig('FONT_STYLE')} bg-white dark:bg-hexo-black-gray w-full h-full min-h-screen justify-center dark:text-gray-300 scroll-smooth`}>
<main
id='wrapper'
className={'relative flex justify-between w-full h-full mx-auto'}>
{/* 主区 */}
<div id='container-wrapper' className='w-full relative z-10'>
<Header {...props} />
<div id='main' role='main'>
{children}
</div>
{/* 底部 */}
<Announcement
post={notice}
className={'text-center text-black bg-[#7BE986] py-16'}
/>
<Footer title={siteConfig('TITLE')} />
</div>
</main>
<LoadingCover />
</div>
</ThemeGlobalMagzine.Provider>
)
}
/**
* 首页
* 首页就是一个博客列表
* @param {*} props
* @returns
*/
const LayoutIndex = props => {
const { posts, categoryOptions, allNavPages, latestPosts } = props
// 最新文章 从第4个元素开始截取出4个
const newPosts = posts.slice(3, 7)
return (
<div className='pt-10 md:pt-18'>
{/* 首屏宣传区块 */}
<Hero posts={posts} />
{/* 最新文章区块 */}
<PostSimpleListHorizontal
title='最新文章'
href='/archive'
posts={newPosts}
/>
{/* 文章分类陈列区 */}
<PostBannerGroupByCategory {...props} />
{/* 文章推荐 */}
<PostListRecommend {...props} />
</div>
)
}
/**
* 博客列表
* @returns
*/
const LayoutPostList = props => {
// 当前筛选的分类或标签
const { category, tag } = props
return (
<div className=' max-w-screen-2xl mx-auto w-full'>
{/* 一个顶部条 */}
<h2 className='py-8 text-2xl font-bold'>{category || tag}</h2>
{siteConfig('POST_LIST_STYLE') === 'page' ? (
<PostListPage {...props} />
) : (
<PostListScroll {...props} />
)}
</div>
)
}
/**
* 文章详情
* @param {*} props
* @returns
*/
const LayoutSlug = props => {
const { post, recommendPosts, prev, next, lock, validPassword } = props
const { locale } = useGlobal()
const router = useRouter()
useEffect(() => {
// 404
if (!post) {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)
})
}
}
},
siteConfig('POST_WAITING_TIME_FOR_404') * 1000
)
}
}, [post])
return (
<>
<div {...props} className='w-full mx-auto max-w-screen-2xl'>
{/* 文章锁 */}
{lock && <ArticleLock validPassword={validPassword} />}
{!lock && (
<div className='w-full max-w-screen-2xl mx-auto'>
{/* 文章信息 */}
<ArticleInfo {...props} />
{/* 文章区块分为三列 */}
<div className='grid grid-cols-1 lg:grid-cols-5 gap-8 py-12'>
<div className='h-full lg:col-span-1 hidden lg:contents'>
<Catalog toc={post?.toc} className='sticky top-20' />
</div>
{/* Notion文章主体 */}
<article
id='article-wrapper'
className='max-w-3xl lg:col-span-3 w-full mx-auto px-2 lg:px-0'>
<NotionPage post={post} />
{/* 文章底部区域 */}
<section>
{/* 分享 */}
<ShareBar post={post} />
{/* 文章分类和标签信息 */}
<div className='flex justify-between'>
{siteConfig('MAGZINE_POST_DETAIL_CATEGORY') &&
post?.category && (
<CategoryItem category={post?.category} />
)}
<div>
{siteConfig('MAGZINE_POST_DETAIL_TAG') &&
post?.tagItems?.map(tag => (
<TagItemMini key={tag.name} tag={tag} />
))}
</div>
</div>
{/* 评论区 */}
<Comment frontMatter={post} />
</section>
</article>
<div className='lg:col-span-1 flex flex-col justify-between px-2 lg:px-0 space-y-2 lg:space-y-0'>
{/* meta信息 */}
<section className='text-lg gap-y-6 '>
<div className='text-gray-500 py-1 dark:text-gray-600'>
{/* <div className='whitespace-nowrap'>
<i className='far fa-calendar mr-2' />
{post?.publishDay}
</div> */}
<div className='whitespace-nowrap mr-2'>
<i className='far fa-calendar-check mr-2' />
{post?.lastEditedDay}
</div>
<div className='hidden busuanzi_container_page_pv mr-2 whitespace-nowrap'>
<i className='mr-1 fas fa-fire' />
<span className='busuanzi_value_page_pv' />
</div>
</div>
</section>
{/* 最新文章区块 */}
<div>
<PostGroupLatest {...props} />
</div>
{/* 文章分类区块 */}
<div>
<CategoryGroup {...props} />
</div>
<div>
<TouchMeCard />
</div>
{/* 底部留白 */}
<div></div>
</div>
</div>
{/* 移动端目录 */}
<TocDrawer {...props} />
</div>
)}
</div>
{/* 广告醒图 */}
<BannerFullWidth />
{/* 最新文章区块 */}
<PostSimpleListHorizontal
title={locale.COMMON.RELATE_POSTS}
href='/archive'
posts={recommendPosts}
/>
</>
)
}
/**
* 搜索
* @param {*} props
* @returns
*/
const LayoutSearch = props => {
const { locale } = useGlobal()
const { keyword } = props
const router = useRouter()
const currentSearch = keyword || router?.query?.s
useEffect(() => {
if (isBrowser) {
replaceSearchResult({
doms: document.getElementById('posts-wrapper'),
search: keyword,
target: {
element: 'span',
className: 'text-red-500 border-b border-dashed'
}
})
}
}, [])
return (
<div className='max-w-screen-2xl w-full mx-auto'>
{/* 搜索导航栏 */}
<div className='py-12'>
<div className='pb-4 w-full'>{locale.NAV.SEARCH}</div>
{!currentSearch && (
<>
<TagGroups {...props} />
<CategoryGroup {...props} />
</>
)}
</div>
{/* 文章列表 */}
{currentSearch && (
<div>
{siteConfig('POST_LIST_STYLE') === 'page' ? (
<PostListPage {...props} />
) : (
<PostListScroll {...props} />
)}
</div>
)}
</div>
)
}
/**
* 归档
* @param {*} props
* @returns
*/
const LayoutArchive = props => {
const { archivePosts } = props
return (
<>
<div className='w-full max-w-screen-2xl mx-auto mt-14 min-h-full'>
{Object.keys(archivePosts)?.map(archiveTitle => (
<PostGroupArchive
key={archiveTitle}
archiveTitle={archiveTitle}
posts={archivePosts[archiveTitle]}
/>
))}
</div>
</>
)
}
/**
* 404
* @param {*} props
* @returns
*/
const Layout404 = props => {
return (
<>
<div className='w-full h-96 py-80 flex justify-center items-center'>
404 Not found.
</div>
</>
)
}
/**
* 分类列表
* @param {*} props
* @returns
*/
const LayoutCategoryIndex = props => {
const { categoryOptions } = props
const { locale } = useGlobal()
return (
<div className='w-full max-w-screen-2xl mx-auto min-h-96'>
<div className='bg-white dark:bg-gray-700 py-10'>
<div className='dark:text-gray-200 mb-5 text-2xl font-bold'>
{/* <i className='mr-4 fas fa-th' /> */}
{locale.COMMON.CATEGORY}:
</div>
<div id='category-list' className='duration-200 flex flex-wrap'>
{categoryOptions?.map(category => {
return (
<Link
key={category.name}
href={`/category/${category.name}`}
passHref
legacyBehavior>
<div
className={
'hover:text-black dark:hover:text-white dark:text-gray-300 dark:hover:bg-gray-600 px-5 cursor-pointer py-2 hover:bg-gray-100'
}>
{/* <i className='mr-4 fas fa-folder' /> */}
{category.name}({category.count})
</div>
</Link>
)
})}
</div>
</div>
</div>
)
}
/**
* 标签列表
* @param {*} props
* @returns
*/
const LayoutTagIndex = props => {
const { tagOptions } = props
const { locale } = useGlobal()
return (
<div className='w-full max-w-screen-2xl mx-auto min-h-96'>
<div className='bg-white dark:bg-gray-700 py-10'>
<div className='dark:text-gray-200 mb-5 text-2xl font-bold'>
{/* <i className='mr-4 fas fa-tag' /> */}
{locale.COMMON.TAGS}:
</div>
<div id='tags-list' className='duration-200 flex flex-wrap'>
{tagOptions?.map(tag => {
return (
<div key={tag.name} className='p-2'>
<TagItemMini key={tag.name} tag={tag} />
</div>
)
})}
</div>
</div>
</div>
)
}
export {
Layout404,
LayoutArchive,
LayoutBase,
LayoutCategoryIndex,
LayoutIndex,
LayoutPostList,
LayoutSearch,
LayoutSlug,
LayoutTagIndex,
CONFIG as THEME_CONFIG
}

18
themes/magzine/style.js Normal file
View File

@@ -0,0 +1,18 @@
/* eslint-disable react/no-unknown-property */
/**
* 此处样式只对当前主题生效
* 此处不支持tailwindCSS的 @apply 语法
* @returns
*/
const Style = () => {
return <style jsx global>{`
// 底色
.dark body{
background-color: black;
}
`}</style>
}
export { Style }

View File

@@ -1,8 +1,8 @@
import Link from 'next/link'
import { useMediumGlobal } from '@/themes/medium'
import { useMediumGlobal } from '..'
import JumpToTopButton from './JumpToTopButton'
export default function BottomMenuBar ({ post, className }) {
export default function BottomMenuBar({ post, className }) {
const { tocVisible, changeTocVisible } = useMediumGlobal()
const showTocButton = post?.toc?.length > 0
@@ -11,24 +11,34 @@ export default function BottomMenuBar ({ post, className }) {
}
return (
<div className={'sticky z-10 bottom-0 w-full h-12 bg-white dark:bg-hexo-black-gray ' + className}>
<div
className={
'sticky z-10 bottom-0 w-full h-12 bg-white dark:bg-hexo-black-gray ' +
className
}>
<div className='flex justify-between h-full shadow-card'>
<Link href='/search' passHref legacyBehavior>
<div className='flex w-full items-center justify-center cursor-pointer'>
<i className='fas fa-search'/>
<i className='fas fa-search' />
</div>
</Link>
<div className='flex w-full items-center justify-center cursor-pointer z-20'>
<JumpToTopButton/>
<JumpToTopButton />
</div>
{showTocButton && <div onClick={toggleToc} className='flex w-full items-center justify-center cursor-pointer z-30'>
<i className='fas fa-list-ol ' />
</div>}
{ !showTocButton && <Link href='/' passHref legacyBehavior>
<div className='flex w-full items-center justify-center cursor-pointer'>
<i className='fas fa-home' />
{showTocButton && (
<div
onClick={toggleToc}
className='flex w-full items-center justify-center cursor-pointer z-30'>
<i className='fas fa-list-ol ' />
</div>
</Link>}
)}
{!showTocButton && (
<Link href='/' passHref legacyBehavior>
<div className='flex w-full items-center justify-center cursor-pointer'>
<i className='fas fa-home' />
</div>
</Link>
)}
</div>
</div>
)

View File

@@ -1,5 +1,5 @@
import { useMediumGlobal } from '..'
import Catalog from './Catalog'
import { useMediumGlobal } from '@/themes/medium'
/**
* 悬浮抽屉目录
@@ -13,22 +13,36 @@ const TocDrawer = ({ post, cRef }) => {
const switchVisible = () => {
changeTocVisible(!tocVisible)
}
return <>
<div id='medium-toc-float' className='fixed top-0 right-0 z-40'>
{/* 侧边菜单 */}
<div
className={(tocVisible ? 'animate__slideInRight ' : ' -mr-72 animate__slideOutRight') +
' overflow-y-hidden shadow-card w-60 duration-200 fixed right-1 bottom-16 rounded py-2 bg-white dark:bg-gray-600'}>
{post && <>
<div className='dark:text-gray-400 text-gray-600 h-56'>
<Catalog toc={post.toc}/>
</div>
</>}
return (
<>
<div id='medium-toc-float' className='fixed top-0 right-0 z-40'>
{/* 侧边菜单 */}
<div
className={
(tocVisible
? 'animate__slideInRight '
: ' -mr-72 animate__slideOutRight') +
' overflow-y-hidden shadow-card w-60 duration-200 fixed right-1 bottom-16 rounded py-2 bg-white dark:bg-gray-600'
}>
{post && (
<>
<div className='dark:text-gray-400 text-gray-600 h-56'>
<Catalog toc={post.toc} />
</div>
</>
)}
</div>
</div>
</div>
{/* 背景蒙版 */}
<div id='right-drawer-background' className={(tocVisible ? 'block' : 'hidden') + ' fixed top-0 left-0 z-30 w-full h-full'}
onClick={switchVisible} />
</>
{/* 背景蒙版 */}
<div
id='right-drawer-background'
className={
(tocVisible ? 'block' : 'hidden') +
' fixed top-0 left-0 z-30 w-full h-full'
}
onClick={switchVisible}
/>
</>
)
}
export default TocDrawer