mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
import BLOG from '@/blog.config'
|
|
import { siteConfig } from '@/lib/config'
|
|
import { getGlobalData } from '@/lib/db/getSiteData'
|
|
import { isBrowser } from '@/lib/utils'
|
|
import { formatDateFmt } from '@/lib/utils/formatDate'
|
|
import { getLayoutByTheme } from '@/themes/theme'
|
|
import { useRouter } from 'next/router'
|
|
import { useEffect } from 'react'
|
|
|
|
const ArchiveIndex = props => {
|
|
// 根据页面路径加载不同Layout文件
|
|
const Layout = getLayoutByTheme({
|
|
theme: siteConfig('THEME'),
|
|
router: useRouter()
|
|
})
|
|
|
|
useEffect(() => {
|
|
if (isBrowser) {
|
|
const anchor = window.location.hash
|
|
if (anchor) {
|
|
setTimeout(() => {
|
|
const anchorElement = document.getElementById(anchor.substring(1))
|
|
if (anchorElement) {
|
|
anchorElement.scrollIntoView({ block: 'start', behavior: 'smooth' })
|
|
}
|
|
}, 300)
|
|
}
|
|
}
|
|
}, [])
|
|
|
|
return <Layout {...props} />
|
|
}
|
|
|
|
export async function getStaticProps({ locale }) {
|
|
const props = await getGlobalData({ from: 'archive-index', locale })
|
|
// 处理分页
|
|
props.posts = props.allPages?.filter(
|
|
page => page.type === 'Post' && page.status === 'Published'
|
|
)
|
|
delete props.allPages
|
|
|
|
const postsSortByDate = Object.create(props.posts)
|
|
|
|
postsSortByDate.sort((a, b) => {
|
|
return b?.publishDate - a?.publishDate
|
|
})
|
|
|
|
const archivePosts = {}
|
|
|
|
postsSortByDate.forEach(post => {
|
|
const date = formatDateFmt(post.publishDate, 'yyyy-MM')
|
|
if (archivePosts[date]) {
|
|
archivePosts[date].push(post)
|
|
} else {
|
|
archivePosts[date] = [post]
|
|
}
|
|
})
|
|
|
|
props.archivePosts = archivePosts
|
|
delete props.allPages
|
|
|
|
return {
|
|
props,
|
|
revalidate: siteConfig(
|
|
'REVALIDATE_SECOND',
|
|
BLOG.NEXT_REVALIDATE_SECOND,
|
|
props.NOTION_CONFIG
|
|
)
|
|
}
|
|
}
|
|
|
|
export default ArchiveIndex
|