11import BLOG from '@/blog.config'
22import { siteConfig } from '@/lib/config'
33import { fetchGlobalAllData , resolvePostProps } from '@/lib/db/SiteDataApi'
4- import { checkSlugHasMorThanTwoSlash , processPostData } from '@/lib/utils/post'
5- import { idToUuid } from 'notion-utils'
4+ import { checkSlugHasMorThanTwoSlash } from '@/lib/utils/post'
65import Slug from '..'
6+ import { isExport } from '@/lib/utils/buildMode'
7+ import { getPriorityPages , prefetchAllBlockMaps } from '@/lib/build/prefetch'
78
89/**
910 * 根据notion的slug访问页面
@@ -15,32 +16,44 @@ const PrefixSlug = props => {
1516 return < Slug { ...props } />
1617}
1718
18- /**
19- * 编译渲染页面路径
20- * @returns
21- */
19+
2220export async function getStaticPaths ( ) {
23- if ( ! BLOG . isProd ) {
21+ const from = 'slug-paths'
22+ const { allPages } = await fetchGlobalAllData ( { from } )
23+
24+ // Export 模式:全量预生成
25+ if ( isExport ( ) ) {
26+ await prefetchAllBlockMaps ( allPages )
2427 return {
25- paths : [ ] ,
26- fallback : true
28+ paths : allPages
29+ ?. filter ( row => checkSlugHasMorThanTwoSlash ( row ) )
30+ . map ( row => ( {
31+ params : {
32+ prefix : row . slug . split ( '/' ) [ 0 ] ,
33+ slug : row . slug . split ( '/' ) [ 1 ] ,
34+ suffix : row . slug . split ( '/' ) . slice ( 2 )
35+ }
36+ } ) ) ,
37+ fallback : false
2738 }
2839 }
2940
30- const from = 'slug-paths'
31- const { allPages } = await fetchGlobalAllData ( { from } )
32- const paths = allPages
33- ?. filter ( row => checkSlugHasMorThanTwoSlash ( row ) )
34- . map ( row => ( {
35- params : {
36- prefix : row . slug . split ( '/' ) [ 0 ] ,
37- slug : row . slug . split ( '/' ) [ 1 ] ,
38- suffix : row . slug . split ( '/' ) . slice ( 2 )
39- }
40- } ) )
41+ // ISR 模式:预生成最新10篇(仅三段以上路径格式)
42+ const tops = getPriorityPages ( allPages )
43+
44+ await prefetchAllBlockMaps ( tops )
45+
4146 return {
42- paths : paths ,
43- fallback : true
47+ paths : tops
48+ . filter ( p => checkSlugHasMorThanTwoSlash ( p ) )
49+ . map ( row => ( {
50+ params : {
51+ prefix : row . slug . split ( '/' ) [ 0 ] ,
52+ slug : row . slug . split ( '/' ) [ 1 ] ,
53+ suffix : row . slug . split ( '/' ) . slice ( 2 )
54+ }
55+ } ) ) ,
56+ fallback : 'blocking'
4457 }
4558}
4659
@@ -53,6 +66,7 @@ export async function getStaticProps({
5366 params : { prefix, slug, suffix } ,
5467 locale
5568} ) {
69+
5670 const props = await resolvePostProps ( {
5771 prefix,
5872 slug,
@@ -62,13 +76,14 @@ export async function getStaticProps({
6276
6377 return {
6478 props,
65- revalidate : process . env . EXPORT
79+ revalidate : isExport ( )
6680 ? undefined
6781 : siteConfig (
6882 'NEXT_REVALIDATE_SECOND' ,
6983 BLOG . NEXT_REVALIDATE_SECOND ,
7084 props . NOTION_CONFIG
71- )
85+ ) ,
86+ notFound : ! props . post
7287 }
7388}
7489
0 commit comments