mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-23 15:09:46 +00:00
hexo主题 新增category、tag分页
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
||||
import * as ThemeMap from '@/themes'
|
||||
import BLOG from '@/blog.config'
|
||||
|
||||
const Tag = props => {
|
||||
const { theme } = useGlobal()
|
||||
@@ -23,16 +24,25 @@ const Tag = props => {
|
||||
}
|
||||
|
||||
export async function getStaticProps({ params: { tag } }) {
|
||||
const props = await getGlobalNotionData({
|
||||
from: 'tag-props',
|
||||
includePage: false,
|
||||
tagsCount: 0
|
||||
})
|
||||
const { allPages } = props
|
||||
const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
props.posts = allPosts.filter(
|
||||
post => post && post.tags && post.tags.includes(tag)
|
||||
)
|
||||
const from = 'tag-props'
|
||||
const props = await getGlobalNotionData({ from })
|
||||
|
||||
// 过滤状态
|
||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
|
||||
// 处理标签
|
||||
props.posts = props.posts.filter(post => post && post.tags && post.tags.includes(tag))
|
||||
|
||||
// 处理文章页数
|
||||
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)
|
||||
}
|
||||
|
||||
props.tag = tag
|
||||
return {
|
||||
props,
|
||||
63
pages/tag/[tag]/page/[page].js
Normal file
63
pages/tag/[tag]/page/[page].js
Normal file
@@ -0,0 +1,63 @@
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
||||
import * as ThemeMap from '@/themes'
|
||||
import BLOG from '@/blog.config'
|
||||
|
||||
const Tag = props => {
|
||||
const { theme } = useGlobal()
|
||||
const ThemeComponents = ThemeMap[theme]
|
||||
const { locale } = useGlobal()
|
||||
const { tag, siteInfo, posts } = props
|
||||
|
||||
if (!posts) {
|
||||
return <ThemeComponents.Layout404 {...props} />
|
||||
}
|
||||
|
||||
const meta = {
|
||||
title: `${tag} | ${locale.COMMON.TAGS} | ${siteInfo?.title}`,
|
||||
description: siteInfo?.description,
|
||||
image: siteInfo?.pageCover,
|
||||
slug: 'tag/' + tag,
|
||||
type: 'website'
|
||||
}
|
||||
return <ThemeComponents.LayoutTag {...props} meta={meta} />
|
||||
}
|
||||
|
||||
export async function getStaticProps({ params: { tag, page } }) {
|
||||
const from = 'tag-page-props'
|
||||
const props = await getGlobalNotionData({ from })
|
||||
// 过滤状态
|
||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
// 过滤标签
|
||||
props.posts = props.posts.filter(post => post && post.tags && post.tags.includes(tag))
|
||||
// 处理文章页数
|
||||
props.postCount = props.posts.length
|
||||
// 处理分页
|
||||
props.posts = props.posts.slice(BLOG.POSTS_PER_PAGE * (page - 1), BLOG.POSTS_PER_PAGE * page - 1)
|
||||
|
||||
props.tag = tag
|
||||
props.page = page
|
||||
|
||||
return {
|
||||
props,
|
||||
revalidate: 1
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const from = 'tag-static-path'
|
||||
const { tags } = await getGlobalNotionData({ from })
|
||||
const tagNames = []
|
||||
tags.forEach(tag => {
|
||||
tagNames.push(tag.name)
|
||||
})
|
||||
|
||||
return {
|
||||
paths: Object.keys(tagNames).map(index => ({
|
||||
params: { tag: tagNames[index], page: '1' }
|
||||
})),
|
||||
fallback: true
|
||||
}
|
||||
}
|
||||
|
||||
export default Tag
|
||||
@@ -3,6 +3,11 @@ import React from 'react'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import * as ThemeMap from '@/themes'
|
||||
|
||||
/**
|
||||
* 标签首页
|
||||
* @param {*} props
|
||||
* @returns
|
||||
*/
|
||||
const TagIndex = props => {
|
||||
const { theme } = useGlobal()
|
||||
const ThemeComponents = ThemeMap[theme]
|
||||
|
||||
Reference in New Issue
Block a user