mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-04 15:10:23 +00:00
折叠菜单配置化
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
import NavPostListEmpty from './NavPostListEmpty'
|
||||
import { useRouter } from 'next/router'
|
||||
import NavPostItem from './NavPostItem'
|
||||
import CONFIG from '../config'
|
||||
import Link from 'next/link'
|
||||
|
||||
/**
|
||||
@@ -12,91 +9,31 @@ import Link from 'next/link'
|
||||
* @constructor
|
||||
*/
|
||||
const NavPostList = (props) => {
|
||||
const { customMenu, categoryOptions } = props
|
||||
// let groupedArray = categoryOptions
|
||||
// const { filteredNavPages, categoryOptions, categories } = props
|
||||
// const router = useRouter()
|
||||
// let selectedSth = false
|
||||
|
||||
// let groupedArray = categoryOptions?.map(item) => {
|
||||
// // let groups = [];
|
||||
// groupedArray.push({ category: item.name, id: item.id, count: item.count, selected: false,items: [] })
|
||||
// return groups
|
||||
// })
|
||||
|
||||
// const groupedArray = categoryOptions?.reduce((groups, item) => {
|
||||
// const categoryName = item?.name ? item?.name : '' // 将category转换为字符串
|
||||
// // let existingGroup = null
|
||||
// console.log('categoryOptions => item::')
|
||||
// console.log(item)
|
||||
// // 添加数据
|
||||
// groups.push({ category: item.name, id: item.id, count: item.count, selected: false, items: [] })
|
||||
// return groups
|
||||
// }, [])
|
||||
|
||||
// 处理是否选中
|
||||
// groupedArray?.map((group) => {
|
||||
// let groupSelected = false
|
||||
// for (const post of group?.items) {
|
||||
// if (router.asPath.split('?')[0] === '/' + post.slug) {
|
||||
// groupSelected = true
|
||||
// selectedSth = true
|
||||
// }
|
||||
// }
|
||||
// group.selected = groupSelected
|
||||
// return null
|
||||
// })
|
||||
|
||||
// 如果都没有选中默认打开第一个
|
||||
// if (!selectedSth && groupedArray && groupedArray?.length > 0) {
|
||||
// groupedArray[0].selected = true
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// console.log('groupedArray::')
|
||||
// console.log(groupedArray)
|
||||
|
||||
// 如果 开启自定义菜单,则覆盖Page生成的菜单
|
||||
// if (BLOG.CUSTOM_MENU) {
|
||||
// links = customMenu
|
||||
// }
|
||||
let links = customMenu
|
||||
return
|
||||
{links && links?.map((link, index) => <MenuItemDrop key={index} link={link} />)}
|
||||
|
||||
|
||||
console.log('categoryOptions::')
|
||||
console.log(categoryOptions)
|
||||
const { categoryOptions } = props
|
||||
if (!categoryOptions) {
|
||||
return <NavPostListEmpty />
|
||||
} else {
|
||||
return
|
||||
|
||||
<div id='category-list' className='dark:border-gray-700 flex flex-wrap mx-4'>
|
||||
{categoryOptions.map(category => {
|
||||
// const selected = currentCategory === category.name
|
||||
let selected = false
|
||||
return (
|
||||
<Link
|
||||
key={category.name}
|
||||
href={`/category/${category.name}`}
|
||||
passHref
|
||||
className={(selected
|
||||
? 'hover:text-black dark:hover:text-gray bg-indigo-600 text-black '
|
||||
: 'dark:text-gray-400 text-gray-500 hover:text-black dark:hover:text-white hover:bg-indigo-600') +
|
||||
' text-sm w-full items-center duration-300 px-2 cursor-pointer py-1 font-light'}>
|
||||
return <div id='category-list' className='dark:border-gray-700 flex flex-wrap mx-4'>
|
||||
{categoryOptions.map(category => {
|
||||
// const selected = currentCategory === category.name
|
||||
const selected = false
|
||||
return (
|
||||
<Link
|
||||
key={category.name}
|
||||
href={`/category/${category.name}`}
|
||||
passHref
|
||||
className={(selected
|
||||
? 'hover:text-black dark:hover:text-gray bg-indigo-600 text-black '
|
||||
: 'dark:text-gray-400 text-gray-500 hover:text-black dark:hover:text-white hover:bg-indigo-600') +
|
||||
' text-sm w-full items-center duration-300 px-2 cursor-pointer py-1 font-light'}>
|
||||
|
||||
<div> <i className={`mr-2 fas ${selected ? 'fa-folder-open' : 'fa-folder'}`} />{category.name}({category.count})</div>
|
||||
<div> <i className={`mr-2 fas ${selected ? 'fa-folder-open' : 'fa-folder'}`} />{category.name}({category.count})</div>
|
||||
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
export default NavPostList
|
||||
|
||||
Reference in New Issue
Block a user