主题配置文件Notion化

This commit is contained in:
tangly1024.com
2023-11-07 14:52:21 +08:00
parent e084053098
commit f2e2ae8d5f
118 changed files with 570 additions and 528 deletions

View File

@@ -1,10 +1,11 @@
import { useGlobal } from '@/lib/global'
import Link from 'next/link'
import CONFIG from '../config'
import { siteConfig } from '@/lib/config'
export default function ArticleCopyright ({ author, url }) {
const { locale } = useGlobal()
if (!CONFIG.ARTICLE_COPYRIGHT) {
if (!siteConfig('NEXT_ARTICLE_COPYRIGHT', null, CONFIG)) {
return <></>
}
return (

View File

@@ -24,7 +24,7 @@ export default function ArticleDetail(props) {
const { post, recommendPosts, prev, next } = props
const url = siteConfig('LINK') + useRouter().asPath
const { locale } = useGlobal()
const showArticleInfo = CONFIG.ARTICLE_INFO
const showArticleInfo = siteConfig('NEXT_ARTICLE_INFO', null, CONFIG)
return (
<div id="article-wrapper"
@@ -39,7 +39,7 @@ export default function ArticleDetail(props) {
{showArticleInfo && <header>
{/* 头图 */}
{CONFIG.POST_HEADER_IMAGE_VISIBLE && post?.type && !post?.type !== 'Page' && post?.pageCover && (
{siteConfig('NEXT_POST_HEADER_IMAGE_VISIBLE', null, CONFIG) && 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-center w-full' />
</div>

View File

@@ -12,7 +12,7 @@ import { siteConfig } from '@/lib/config'
const BlogPostCard = ({ post, showSummary }) => {
const { locale } = useGlobal()
const showPreview = CONFIG.POST_LIST_PREVIEW && post.blockMap
const showPreview = siteConfig('NEXT_POST_LIST_PREVIEW', null, CONFIG) && post.blockMap
return (
<Card className="w-full">
<div
@@ -114,7 +114,7 @@ const BlogPostCard = ({ post, showSummary }) => {
</div>
</div>
{CONFIG.POST_LIST_COVER && post?.pageCoverThumbnail && (
{siteConfig('NEXT_POST_LIST_COVER', null, CONFIG) && post?.pageCoverThumbnail && (
<Link href={`${siteConfig('SUB_PATH', '')}/${post.slug}`} passHref legacyBehavior>
<div className="h-72 w-full relative duration-200 cursor-pointer transform overflow-hidden">
<Image

View File

@@ -13,7 +13,7 @@ import { siteConfig } from '@/lib/config'
* @returns {JSX.Element}
* @constructor
*/
const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG.POST_LIST_SUMMARY }) => {
const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = siteConfig('NEXT_POST_LIST_SUMMARY', null, CONFIG) }) => {
const postsPerPage = parseInt(siteConfig('POSTS_PER_PAGE'))
const [page, updatePage] = useState(1)
const postsToShow = getPostByPage(page, posts, postsPerPage)

View File

@@ -1,11 +1,12 @@
import { useGlobal } from '@/lib/global'
import { saveDarkModeToCookies } from '@/themes/theme'
import CONFIG from '../config'
import { siteConfig } from '@/lib/config'
export default function FloatDarkModeButton () {
const { isDarkMode, updateDarkMode } = useGlobal()
if (!CONFIG.WIDGET_DARK_MODE) {
if (!siteConfig('NEXT_WIDGET_DARK_MODE', null, CONFIG)) {
return <></>
}

View File

@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react'
import CONFIG from '../config'
import { siteConfig } from '@/lib/config'
/**
* 跳转到网页顶部
@@ -37,7 +38,7 @@ const JumpToBottomButton = ({ showPercent = false }) => {
window.scrollTo({ top: targetRef.clientHeight, behavior: 'smooth' })
}
if (!CONFIG.WIDGET_TO_BOTTOM) {
if (!siteConfig('NEXT_WIDGET_TO_BOTTOM', null, CONFIG)) {
return <></>
}

View File

@@ -1,5 +1,6 @@
import { useGlobal } from '@/lib/global'
import CONFIG from '../config'
import { siteConfig } from '@/lib/config'
/**
* 跳转到网页顶部
@@ -11,7 +12,7 @@ import CONFIG from '../config'
*/
const JumpToTopButton = ({ showPercent = true, percent }) => {
const { locale } = useGlobal()
if (!CONFIG.WIDGET_TO_TOP) {
if (!siteConfig('NEXT_WIDGET_TO_TOP', null, CONFIG)) {
return <></>
}
return (<div className='flex space-x-1 items-center transform hover:scale-105 duration-200 py-2 px-3' onClick={() => window.scrollTo({ top: 0, behavior: 'smooth' })} >

View File

@@ -11,9 +11,9 @@ export const MenuList = (props) => {
const defaultLinks = [
{ id: 1, icon: 'fas fa-home', name: locale.NAV.INDEX, to: '/' || '/', show: true },
{ id: 2, icon: 'fas fa-th', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG.MENU_CATEGORY },
{ id: 3, icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: CONFIG.MENU_TAG },
{ id: 4, icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', slot: archiveSlot, show: CONFIG.MENU_ARCHIVE }
{ id: 2, icon: 'fas fa-th', name: locale.COMMON.CATEGORY, to: '/category', show: siteConfig('NEXT_MENU_CATEGORY', null, CONFIG) },
{ id: 3, icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: siteConfig('NEXT_MENU_TAG', null, CONFIG) },
{ id: 4, icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', slot: archiveSlot, show: siteConfig('NEXT_MENU_ARCHIVE', null, CONFIG) }
]
let links = [].concat(defaultLinks)

View File

@@ -1,13 +1,14 @@
import Link from 'next/link'
import { useGlobal } from '@/lib/global'
import CONFIG from '../config'
import { siteConfig } from '@/lib/config'
/**
* 展示文章推荐
*/
const RecommendPosts = ({ recommendPosts }) => {
const { locale } = useGlobal()
if (!CONFIG.ARTICLE_RELATE_POSTS || !recommendPosts || recommendPosts.length < 1) {
if (!siteConfig('NEXT_ARTICLE_RELATE_POSTS', null, CONFIG) || !recommendPosts || recommendPosts.length < 1) {
return <></>
}

View File

@@ -33,7 +33,7 @@ const SideAreaLeft = props => {
<div className='pt-2 px-2 font-sans'>
<MenuList allowCollapse={true} {...props} />
</div>
{CONFIG.MENU_SEARCH && <div className='px-2 pt-2 font-sans'>
{siteConfig('NEXT_MENU_SEARCH', null, CONFIG) && <div className='px-2 pt-2 font-sans'>
<SearchInput {...props} />
</div>}

View File

@@ -29,7 +29,7 @@ const SideAreaRight = (props) => {
return (<aside id='right' className={(JSON.parse(siteConfig('LAYOUT_SIDEBAR_REVERSE')) ? 'mr-4' : 'ml-4') + ' space-y-4 hidden xl:block flex-col w-60 relative z-10'}>
{CONFIG.RIGHT_AD && <Card className='mb-2'>
{siteConfig('NEXT_RIGHT_AD', null, CONFIG) && <Card className='mb-2'>
{/* 展示广告 */}
<ins
className='adsbygoogle'
@@ -48,11 +48,11 @@ const SideAreaRight = (props) => {
<Announcement post={notice} />
</Card>}
{CONFIG.RIGHT_LATEST_POSTS && <Card><LatestPostsGroup latestPosts={latestPosts} /></Card>}
{siteConfig('NEXT_RIGHT_LATEST_POSTS', null, CONFIG) && <Card><LatestPostsGroup latestPosts={latestPosts} /></Card>}
{slot}
{/* 分类 */}
{CONFIG.RIGHT_CATEGORY_LIST && router.asPath !== '/category' && categoryOptions && (
{siteConfig('NEXT_RIGHT_CATEGORY_LIST', null, CONFIG) && router.asPath !== '/category' && categoryOptions && (
<Card>
<div className='text-sm px-2 flex flex-nowrap justify-between font-light'>
<div className='pb-2 text-gray-600 dark:text-gray-300'><i className='mr-2 fas fa-th-list' />{locale.COMMON.CATEGORY}</div>
@@ -69,7 +69,7 @@ const SideAreaRight = (props) => {
</Card>
)}
{CONFIG.RIGHT_TAG_LIST && router.asPath !== '/tag' && tagOptions && (
{siteConfig('NEXT_RIGHT_TAG_LIST', null, CONFIG) && router.asPath !== '/tag' && tagOptions && (
<Card>
<div className="text-sm pb-1 px-2 flex flex-nowrap justify-between font-light dark:text-gray-200">
<div className="text-gray-600 dark:text-gray-200">

View File

@@ -1,6 +1,7 @@
import throttle from 'lodash.throttle'
import { useCallback, useEffect } from 'react'
import CONFIG from '../config'
import { siteConfig } from '@/lib/config'
let windowTop = 0
@@ -13,7 +14,7 @@ let windowTop = 0
const StickyBar = ({ children }) => {
// 滚动页面时导航条样式调整
const scrollTrigger = useCallback(throttle(() => {
if (CONFIG.NAV_TYPE === 'normal') {
if (siteConfig('NEXT_NAV_TYPE', null, CONFIG) === 'normal') {
return
}
const scrollS = window.scrollY

View File

@@ -1,5 +1,6 @@
import { useGlobal } from '@/lib/global'
import CONFIG from '../config'
import { siteConfig } from '@/lib/config'
/**
* 点击召唤目录抽屉
@@ -10,7 +11,7 @@ import CONFIG from '../config'
*/
const TocDrawerButton = (props) => {
const { locale } = useGlobal()
if (!CONFIG.WIDGET_TOC) {
if (!siteConfig('NEXT_WIDGET_TOC', null, CONFIG)) {
return <></>
}
if (props?.post?.toc?.length > 1) {

View File

@@ -9,6 +9,7 @@ import { MenuList } from './MenuList'
import SearchDrawer from './SearchDrawer'
import TagGroups from './TagGroups'
import CONFIG from '../config'
import { siteConfig } from '@/lib/config'
let windowTop = 0
@@ -38,12 +39,12 @@ const TopNav = (props) => {
// 监听滚动
useEffect(() => {
if (CONFIG.NAV_TYPE === 'autoCollapse') {
if (siteConfig('NEXT_NAV_TYPE', null, CONFIG) === 'autoCollapse') {
scrollTrigger()
window.addEventListener('scroll', scrollTrigger)
}
return () => {
CONFIG.NAV_TYPE === 'autoCollapse' && window.removeEventListener('scroll', scrollTrigger)
siteConfig('NEXT_NAV_TYPE', null, CONFIG) === 'autoCollapse' && window.removeEventListener('scroll', scrollTrigger)
}
}, [])
@@ -96,7 +97,7 @@ const TopNav = (props) => {
<SearchDrawer cRef={searchDrawer} slot={searchDrawerSlot} />
{/* 导航栏 */}
<div id='sticky-nav' className={`${CONFIG.NAV_TYPE !== 'normal' ? 'fixed' : 'relative'} lg:relative w-full top-0 z-20 transform duration-500`}>
<div id='sticky-nav' className={`${siteConfig('NEXT_NAV_TYPE', null, CONFIG) !== 'normal' ? 'fixed' : 'relative'} lg:relative w-full top-0 z-20 transform duration-500`}>
<div className='w-full flex justify-between items-center p-4 bg-black dark:bg-gray-800 text-white'>
{/* 左侧LOGO 标题 */}
<div className='flex flex-none flex-grow-0'>

View File

@@ -1,38 +1,38 @@
const CONFIG = {
HOME_BANNER: true, // 首页是否显示大图及标语 [true,false]
HOME_BANNER_Strings: ['Hi我是一个程序员', 'Hi我是一个打工人', 'Hi我是一个干饭人', '欢迎来到我的博客🎉'], // 首页大图标语文字
NEXT_HOME_BANNER: true, // 首页是否显示大图及标语 [true,false]
NEXT_HOME_BANNER_STRINGS: ['Hi我是一个程序员', 'Hi我是一个打工人', 'Hi我是一个干饭人', '欢迎来到我的博客🎉'], // 首页大图标语文字
NAV_TYPE: 'normal', // ['fixed','autoCollapse','normal'] 分别是固定屏幕顶部并始终显示、固定屏幕顶部且滚动时隐藏,不固定屏幕顶部
NEXT_NAV_TYPE: 'normal', // ['fixed','autoCollapse','normal'] 分别是固定屏幕顶部并始终显示、固定屏幕顶部且滚动时隐藏,不固定屏幕顶部
POST_LIST_COVER: false, // 文章列表显示封面图
POST_LIST_PREVIEW: true, // 显示文章预览
POST_LIST_SUMMARY: false, // 显示用户自定义摘要,有预览时优先只展示预览
NEXT_POST_LIST_COVER: false, // 文章列表显示封面图
NEXT_POST_LIST_PREVIEW: true, // 显示文章预览
NEXT_POST_LIST_SUMMARY: false, // 显示用户自定义摘要,有预览时优先只展示预览
POST_HEADER_IMAGE_VISIBLE: false, // 文章详情页是否显示封面图
NEXT_POST_HEADER_IMAGE_VISIBLE: false, // 文章详情页是否显示封面图
// 右侧组件
RIGHT_BAR: true, // 是否显示右侧栏
RIGHT_LATEST_POSTS: true, // 右侧栏最新文章
RIGHT_CATEGORY_LIST: true, // 右侧边栏文章分类列表
RIGHT_TAG_LIST: true, // 右侧边栏标签分类列表
RIGHT_AD: false, // 右侧广告
NEXT_RIGHT_BAR: true, // 是否显示右侧栏
NEXT_RIGHT_LATEST_POSTS: true, // 右侧栏最新文章
NEXT_RIGHT_CATEGORY_LIST: true, // 右侧边栏文章分类列表
NEXT_RIGHT_TAG_LIST: true, // 右侧边栏标签分类列表
NEXT_RIGHT_AD: false, // 右侧广告
// 菜单
MENU_HOME: true, // 显示首页
MENU_CATEGORY: true, // 显示分类
MENU_TAG: true, // 显示标签
MENU_ARCHIVE: true, // 显示归档
MENU_SEARCH: true, // 显示搜索
NEXT_MENU_HOME: true, // 显示首页
NEXT_MENU_CATEGORY: true, // 显示分类
NEXT_MENU_TAG: true, // 显示标签
NEXT_MENU_ARCHIVE: true, // 显示归档
NEXT_MENU_SEARCH: true, // 显示搜索
WIDGET_TO_TOP: true, // 是否显示回顶
WIDGET_TO_BOTTOM: false, // 显示回底
WIDGET_DARK_MODE: false, // 显示日间/夜间模式切换
WIDGET_TOC: true, // 移动端显示悬浮目录
NEXT_WIDGET_TO_TOP: true, // 是否显示回顶
NEXT_WIDGET_TO_BOTTOM: false, // 显示回底
NEXT_WIDGET_DARK_MODE: false, // 显示日间/夜间模式切换
NEXT_WIDGET_TOC: true, // 移动端显示悬浮目录
ARTICLE_RELATE_POSTS: true, // 相关文章推荐
ARTICLE_COPYRIGHT: true, // 文章版权声明
ARTICLE_INFO: true // 显示文章信息
NEXT_ARTICLE_RELATE_POSTS: true, // 相关文章推荐
NEXT_ARTICLE_COPYRIGHT: true, // 文章版权声明
NEXT_ARTICLE_INFO: true // 显示文章信息
}

View File

@@ -88,7 +88,7 @@ const LayoutBase = (props) => {
<SideAreaLeft targetRef={targetRef} {...props} />
{/* 中央内容 */}
<section id='container-inner' className={`${CONFIG.NAV_TYPE !== 'normal' ? 'mt-24' : ''} lg:max-w-3xl xl:max-w-4xl flex-grow md:mt-0 min-h-screen w-full relative z-10`} ref={targetRef}>
<section id='container-inner' className={`${siteConfig('NEXT_NAV_TYPE', null, CONFIG) !== 'normal' ? 'mt-24' : ''} lg:max-w-3xl xl:max-w-4xl flex-grow md:mt-0 min-h-screen w-full relative z-10`} ref={targetRef}>
<Transition
show={!onLoading}
appear={true}
@@ -105,7 +105,7 @@ const LayoutBase = (props) => {
</section>
{/* 右侧栏样式 */}
{CONFIG.RIGHT_BAR && <SideAreaRight targetRef={targetRef} slot={rightAreaSlot} {...props} />}
{siteConfig('NEXT_RIGHT_BAR', null, CONFIG) && <SideAreaRight targetRef={targetRef} slot={rightAreaSlot} {...props} />}
</main>
{/* 右下角悬浮 */}