主题配置文件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'>