主题配置文件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,9 @@
/* eslint-disable */
import BlogPostListEmpty from './BlogPostListEmpty'
import { useRouter } from 'next/router'
import BlogPostItem from './BlogPostItem'
import { useNavGlobal } from '@/themes/nav'
import CONFIG from '../config'
import { deepClone } from '@/lib/utils'
import { useEffect, useState, createContext, useContext } from 'react'
import { siteConfig } from '@/lib/config'
/**
* 博客列表滚动分页
@@ -21,22 +20,22 @@ const BlogPostListAll = (props) => {
// const [filteredNavPages, setFilteredNavPages] = useState(allNavPages)
const { filteredNavPages, setFilteredNavPages, allNavPages } = useNavGlobal()
// const [filteredNavPages] = useState(allNavPages)
// const router = useRouter()
// 对自定义分类格式化,方便后续使用分类名称做索引,检索同步图标信息
// 目前只支持二级分类
let links = customMenu
let filterLinks = {}
const links = customMenu
const filterLinks = {}
// for循环遍历数组
links?.map((link, i) => {
let linkTitle = link.title + ''
const linkTitle = link.title + ''
// console.log('####### link')
// console.log(link)
// filterLinks[linkTitle] = link
filterLinks[linkTitle] = { title: link.title, icon: link.icon, pageIcon: link.pageIcon }
if(link?.subMenus){
filterLinks[linkTitle] = { title: link.title, icon: link.icon, pageIcon: link.pageIcon }
if (link?.subMenus) {
link.subMenus?.map((group, index) => {
let subMenuTitle = group?.title + ''
const subMenuTitle = group?.title + ''
// 自定义分类图标与post的category共用
// 判断自定义分类与Post中category同名的项将icon的值传递给post
// filterLinks[subMenuTitle] = group
@@ -44,18 +43,17 @@ const BlogPostListAll = (props) => {
})
}
})
console.log('####### filterLinks')
console.log(filterLinks)
// console.log('####### filterLinks')
// console.log(filterLinks)
let selectedSth = false
const selectedSth = false
const groupedArray = filteredNavPages?.reduce((groups, item) => {
let categoryName = item?.category ? item?.category : '' // 将category转换为字符串
let categoryIcon = filterLinks[categoryName]?.icon ? filterLinks[categoryName]?.icon : '' // 将pageIcon转换为字符串
const categoryName = item?.category ? item?.category : '' // 将category转换为字符串
const categoryIcon = filterLinks[categoryName]?.icon ? filterLinks[categoryName]?.icon : '' // 将pageIcon转换为字符串
// console.log('####### categoryName')
// console.log(categoryName)
@@ -64,7 +62,7 @@ const BlogPostListAll = (props) => {
let existingGroup = null
// 开启自动分组排序
if (JSON.parse(CONFIG.AUTO_SORT)) {
if (JSON.parse(siteConfig('NAV_AUTO_SORT', null, CONFIG))) {
existingGroup = groups.find(group => group.category === categoryName) // 搜索同名的最后一个分组
} else {
existingGroup = groups[groups.length - 1] // 获取最后一个分组
@@ -87,7 +85,7 @@ const BlogPostListAll = (props) => {
// item.icon = filterLinks[categoryName]?.icon ? filterLinks[categoryName]?.icon : ''
// console.log('####### item')
// console.log(item)
let groupSelected = false
const groupSelected = false
// for (const post of group?.items) {
// if (router.asPath.split('?')[0] === '/' + post.slug) {
// groupSelected = true
@@ -133,7 +131,6 @@ const BlogPostListAll = (props) => {
// filterPosts.push(filterGroup)
// }
// }
}
export default BlogPostListAll

View File

@@ -16,7 +16,7 @@ export default function LogoBar(props) {
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={siteInfo?.icon?.replaceAll('width=400', 'width=280')}
height='44px' alt={siteConfig('AUTHOR') + ' - ' + siteConfig('NEXT_PUBLIC_BIO')} className='md:block transition-all hover:scale-110 duration-150' placeholderSrc='' />
{CONFIG.SHOW_TITLE_TEXT && siteConfig('TITLE')}
{siteConfig('NAV_SHOW_TITLE_TEXT', null, CONFIG) && siteConfig('TITLE')}
</Link>
</div>
)

View File

@@ -14,10 +14,10 @@ export const MenuBarMobile = (props) => {
let links = [
// { name: locale.NAV.INDEX, to: '/' || '/', show: true },
{ name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG.MENU_CATEGORY },
{ name: locale.COMMON.TAGS, to: '/tag', show: CONFIG.MENU_TAG },
{ name: locale.NAV.ARCHIVE, to: '/archive', show: CONFIG.MENU_ARCHIVE }
// { name: locale.NAV.SEARCH, to: '/search', show: CONFIG.MENU_SEARCH }
{ name: locale.COMMON.CATEGORY, to: '/category', show: siteConfig('NAV_MENU_CATEGORY', null, CONFIG) },
{ name: locale.COMMON.TAGS, to: '/tag', show: siteConfig('NAV_MENU_TAG', null, CONFIG) },
{ name: locale.NAV.ARCHIVE, to: '/archive', show: siteConfig('NAV_MENU_ARCHIVE', null, CONFIG) }
// { name: locale.NAV.SEARCH, to: '/search', show: siteConfig('MENU_SEARCH', null, CONFIG) }
]
if (customNav) {

View File

@@ -1,20 +1,20 @@
const CONFIG = {
INDEX_PAGE: 'about', // 文档首页显示的文章请确此路径包含在您的notion数据库中
NAV_INDEX_PAGE: 'about', // 文档首页显示的文章请确此路径包含在您的notion数据库中
AUTO_SORT: process.env.NEXT_PUBLIC_GITBOOK_AUTO_SORT || true, // 是否自动按分类名 归组排序文章自动归组可能会打乱您Notion中的文章顺序
NAV_AUTO_SORT: process.env.NEXT_PUBLIC_GITBOOK_AUTO_SORT || true, // 是否自动按分类名 归组排序文章自动归组可能会打乱您Notion中的文章顺序
SHOW_TITLE_TEXT: false, // 标题栏显示文本
USE_CUSTOM_MENU: true, // 使用自定义菜单可支持子菜单支持自定义分类图标若为true则显示所有的category分类
NAV_SHOW_TITLE_TEXT: false, // 标题栏显示文本
NAV_USE_CUSTOM_MENU: true, // 使用自定义菜单可支持子菜单支持自定义分类图标若为true则显示所有的category分类
// 菜单
MENU_CATEGORY: true, // 显示分类
MENU_TAG: true, // 显示标签
MENU_ARCHIVE: true, // 显示归档
MENU_SEARCH: true, // 显示搜索
NAV_MENU_CATEGORY: true, // 显示分类
NAV_MENU_TAG: true, // 显示标签
NAV_MENU_ARCHIVE: true, // 显示归档
NAV_MENU_SEARCH: true, // 显示搜索
// Widget
WIDGET_REVOLVER_MAPS: process.env.NEXT_PUBLIC_WIDGET_REVOLVER_MAPS || 'false', // 地图插件
WIDGET_TO_TOP: true // 跳回顶部
NAV_WIDGET_REVOLVER_MAPS: process.env.NEXT_PUBLIC_WIDGET_REVOLVER_MAPS || 'false', // 地图插件
NAV_WIDGET_TO_TOP: true // 跳回顶部
}
export default CONFIG

View File

@@ -61,7 +61,7 @@ const LayoutBase = (props) => {
let links = customMenu
// 默认使用自定义菜单否则将遍历所有的category生成菜单
if (!CONFIG.USE_CUSTOM_MENU) {
if (!siteConfig('NAV_USE_CUSTOM_MENU', null, CONFIG)) {
links = categoryOptions && categoryOptions?.map(c => {
return { id: c.name, title: `# ${c.name}`, to: `/category/${c.name}`, show: true }
})
@@ -227,9 +227,9 @@ const LayoutSlug = (props) => {
{/* <ShareBar post={post} /> */}
{/* 文章分类和标签信息 */}
<div className='flex justify-between'>
{CONFIG.POST_DETAIL_CATEGORY && post?.category && <CategoryItem category={post.category} />}
{siteConfig('POST_DETAIL_CATEGORY', null, CONFIG) && post?.category && <CategoryItem category={post.category} />}
<div>
{CONFIG.POST_DETAIL_TAG && post?.tagItems?.map(tag => <TagItemMini key={tag.name} tag={tag} />)}
{siteConfig('POST_DETAIL_TAG', null, CONFIG) && post?.tagItems?.map(tag => <TagItemMini key={tag.name} tag={tag} />)}
</div>
</div>