Skip to content

Commit 1fb9ba4

Browse files
committed
frame-work lib/db
1 parent 11d9eca commit 1fb9ba4

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

lib/db/getSiteData.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { getConfigMapFromConfigPage } from '@/lib/notion/getNotionConfig'
1212

1313
export { getAllTags } from '../notion/getAllTags'
1414
export { getPostBlocks } from '../notion/getPostBlocks'
15+
export { getPost } from '../notion/getNotionPost'
1516

1617
/**
1718
* 获取博客数据; 基于Notion实现

lib/notion/getNotion.js lib/notion/getNotionPost.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { defaultMapImageUrl } from 'react-notion-x'
99
* @param {*} pageId
1010
* @returns
1111
*/
12-
export async function getNotion(pageId) {
12+
export async function getPost(pageId) {
1313
const blockMap = await getPostBlocks(pageId, 'slug')
1414
if (!blockMap) {
1515
return null

pages/[prefix]/[slug]/[...suffix].js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import BLOG from '@/blog.config'
2-
import { getGlobalData, getPostBlocks } from '@/lib/db/getSiteData'
2+
import { getGlobalData, getPostBlocks, getPost } from '@/lib/db/getSiteData'
33
import { idToUuid } from 'notion-utils'
4-
import { getNotion } from '@/lib/notion/getNotion'
54
import Slug, { getRecommendPost } from '..'
65
import { uploadDataToAlgolia } from '@/lib/plugins/algolia'
76
import { checkContainHttp } from '@/lib/utils'
@@ -61,7 +60,7 @@ export async function getStaticProps({ params: { prefix, slug, suffix } }) {
6160
if (!props?.post) {
6261
const pageId = fullSlug.slice(-1)[0]
6362
if (pageId.length >= 32) {
64-
const post = await getNotion(pageId)
63+
const post = await getPost(pageId)
6564
props.post = post
6665
}
6766
}

pages/[prefix]/[slug]/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import BLOG from '@/blog.config'
2-
import { getGlobalData, getPostBlocks } from '@/lib/db/getSiteData'
2+
import { getGlobalData, getPostBlocks, getPost } from '@/lib/db/getSiteData'
33
import { idToUuid } from 'notion-utils'
4-
import { getNotion } from '@/lib/notion/getNotion'
54
import Slug, { getRecommendPost } from '..'
65
import { uploadDataToAlgolia } from '@/lib/plugins/algolia'
76
import { checkContainHttp } from '@/lib/utils'
@@ -52,7 +51,7 @@ export async function getStaticProps({ params: { prefix, slug } }) {
5251
if (!props?.post) {
5352
const pageId = slug.slice(-1)[0]
5453
if (pageId.length >= 32) {
55-
const post = await getNotion(pageId)
54+
const post = await getPost(pageId)
5655
props.post = post
5756
}
5857
}

pages/[prefix]/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import BLOG from '@/blog.config'
2-
import { getGlobalData, getPostBlocks } from '@/lib/db/getSiteData'
2+
import { getGlobalData, getPostBlocks, getPost } from '@/lib/db/getSiteData'
33
import { useEffect, useState } from 'react'
44
import { idToUuid } from 'notion-utils'
55
import { useRouter } from 'next/router'
6-
import { getNotion } from '@/lib/notion/getNotion'
76
import { getPageTableOfContents } from '@/lib/notion/getPageTableOfContents'
87
import { getLayoutByTheme } from '@/themes/theme'
98
import md5 from 'js-md5'
@@ -92,7 +91,7 @@ export async function getStaticProps({ params: { prefix } }) {
9291
if (!props?.post) {
9392
const pageId = prefix
9493
if (pageId.length >= 32) {
95-
const post = await getNotion(pageId)
94+
const post = await getPost(pageId)
9695
props.post = post
9796
}
9897
}

0 commit comments

Comments
 (0)