mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-22 07:26:48 +00:00
hexo主题 新增category、tag分页
This commit is contained in:
@@ -2,7 +2,13 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
||||
import React from 'react'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import * as ThemeMap from '@/themes'
|
||||
import BLOG from '@/blog.config'
|
||||
|
||||
/**
|
||||
* 分类页
|
||||
* @param {*} props
|
||||
* @returns
|
||||
*/
|
||||
export default function Category(props) {
|
||||
const { theme } = useGlobal()
|
||||
const ThemeComponents = ThemeMap[theme]
|
||||
@@ -26,12 +32,23 @@ export default function Category(props) {
|
||||
export async function getStaticProps({ params: { category } }) {
|
||||
const from = 'category-props'
|
||||
let props = await getGlobalNotionData({ from })
|
||||
const { allPages } = props
|
||||
const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
const posts = allPosts.filter(
|
||||
post => post && post.category && post.category.includes(category)
|
||||
)
|
||||
props = { ...props, posts, category }
|
||||
|
||||
// 过滤状态
|
||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
// 处理过滤
|
||||
props.posts = props.posts.filter(post => post && post.category && post.category.includes(category))
|
||||
// 处理文章页数
|
||||
props.postCount = props.posts.length
|
||||
// 处理分页
|
||||
if (BLOG.POST_LIST_STYLE === 'scroll') {
|
||||
// 滚动列表 给前端返回所有数据
|
||||
} else if (BLOG.POST_LIST_STYLE === 'page') {
|
||||
props.posts = props.posts?.slice(0, BLOG.POSTS_PER_PAGE - 1)
|
||||
}
|
||||
|
||||
delete props.allPages
|
||||
|
||||
props = { ...props, category }
|
||||
|
||||
return {
|
||||
props,
|
||||
65
pages/category/[category]/page/[page].js
Normal file
65
pages/category/[category]/page/[page].js
Normal file
@@ -0,0 +1,65 @@
|
||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
||||
import React from 'react'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import * as ThemeMap from '@/themes'
|
||||
import BLOG from '@/blog.config'
|
||||
|
||||
/**
|
||||
* 分类页
|
||||
* @param {*} props
|
||||
* @returns
|
||||
*/
|
||||
export default function Category(props) {
|
||||
const { theme } = useGlobal()
|
||||
const ThemeComponents = ThemeMap[theme]
|
||||
const { siteInfo, posts } = props
|
||||
const { locale } = useGlobal()
|
||||
if (!posts) {
|
||||
return <ThemeComponents.Layout404 {...props} />
|
||||
}
|
||||
const meta = {
|
||||
title: `${props.category} | ${locale.COMMON.CATEGORY} | ${
|
||||
siteInfo?.title || ''
|
||||
}`,
|
||||
description: siteInfo?.description,
|
||||
slug: 'category/' + props.category,
|
||||
image: siteInfo?.pageCover,
|
||||
type: 'website'
|
||||
}
|
||||
return <ThemeComponents.LayoutCategory {...props} meta={meta} />
|
||||
}
|
||||
|
||||
export async function getStaticProps({ params: { category, page } }) {
|
||||
const from = 'category-page-props'
|
||||
let props = await getGlobalNotionData({ from })
|
||||
|
||||
// 过滤状态
|
||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
// 过滤类型
|
||||
props.posts = props.posts.filter(post => post && post.category && post.category.includes(category))
|
||||
// 处理文章页数
|
||||
props.postCount = props.posts.length
|
||||
// 处理分页
|
||||
props.posts = props.posts.slice(BLOG.POSTS_PER_PAGE * (page - 1), BLOG.POSTS_PER_PAGE * page - 1)
|
||||
|
||||
delete props.allPages
|
||||
props.page = page
|
||||
|
||||
props = { ...props, category, page }
|
||||
|
||||
return {
|
||||
props,
|
||||
revalidate: 1
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const from = 'category-paths'
|
||||
const { categories } = await getGlobalNotionData({ from })
|
||||
return {
|
||||
paths: Object.keys(categories).map(category => ({
|
||||
params: { category: categories[category]?.name, page: '1' }
|
||||
})),
|
||||
fallback: true
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,11 @@ import React from 'react'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import * as ThemeMap from '@/themes'
|
||||
|
||||
/**
|
||||
* 分类首页
|
||||
* @param {*} props
|
||||
* @returns
|
||||
*/
|
||||
export default function Category(props) {
|
||||
const { theme } = useGlobal()
|
||||
const ThemeComponents = ThemeMap[theme]
|
||||
|
||||
Reference in New Issue
Block a user