frame-work lib/db

This commit is contained in:
tangly1024
2024-03-10 14:07:06 +08:00
parent 11d9eca881
commit 1fb9ba4abf
5 changed files with 8 additions and 10 deletions

View File

@@ -12,6 +12,7 @@ import { getConfigMapFromConfigPage } from '@/lib/notion/getNotionConfig'
export { getAllTags } from '../notion/getAllTags'
export { getPostBlocks } from '../notion/getPostBlocks'
export { getPost } from '../notion/getNotionPost'
/**
* 获取博客数据; 基于Notion实现

View File

@@ -9,7 +9,7 @@ import { defaultMapImageUrl } from 'react-notion-x'
* @param {*} pageId
* @returns
*/
export async function getNotion(pageId) {
export async function getPost(pageId) {
const blockMap = await getPostBlocks(pageId, 'slug')
if (!blockMap) {
return null

View File

@@ -1,7 +1,6 @@
import BLOG from '@/blog.config'
import { getGlobalData, getPostBlocks } from '@/lib/db/getSiteData'
import { getGlobalData, getPostBlocks, getPost } from '@/lib/db/getSiteData'
import { idToUuid } from 'notion-utils'
import { getNotion } from '@/lib/notion/getNotion'
import Slug, { getRecommendPost } from '..'
import { uploadDataToAlgolia } from '@/lib/plugins/algolia'
import { checkContainHttp } from '@/lib/utils'
@@ -61,7 +60,7 @@ export async function getStaticProps({ params: { prefix, slug, suffix } }) {
if (!props?.post) {
const pageId = fullSlug.slice(-1)[0]
if (pageId.length >= 32) {
const post = await getNotion(pageId)
const post = await getPost(pageId)
props.post = post
}
}

View File

@@ -1,7 +1,6 @@
import BLOG from '@/blog.config'
import { getGlobalData, getPostBlocks } from '@/lib/db/getSiteData'
import { getGlobalData, getPostBlocks, getPost } from '@/lib/db/getSiteData'
import { idToUuid } from 'notion-utils'
import { getNotion } from '@/lib/notion/getNotion'
import Slug, { getRecommendPost } from '..'
import { uploadDataToAlgolia } from '@/lib/plugins/algolia'
import { checkContainHttp } from '@/lib/utils'
@@ -52,7 +51,7 @@ export async function getStaticProps({ params: { prefix, slug } }) {
if (!props?.post) {
const pageId = slug.slice(-1)[0]
if (pageId.length >= 32) {
const post = await getNotion(pageId)
const post = await getPost(pageId)
props.post = post
}
}

View File

@@ -1,9 +1,8 @@
import BLOG from '@/blog.config'
import { getGlobalData, getPostBlocks } from '@/lib/db/getSiteData'
import { getGlobalData, getPostBlocks, getPost } from '@/lib/db/getSiteData'
import { useEffect, useState } from 'react'
import { idToUuid } from 'notion-utils'
import { useRouter } from 'next/router'
import { getNotion } from '@/lib/notion/getNotion'
import { getPageTableOfContents } from '@/lib/notion/getPageTableOfContents'
import { getLayoutByTheme } from '@/themes/theme'
import md5 from 'js-md5'
@@ -92,7 +91,7 @@ export async function getStaticProps({ params: { prefix } }) {
if (!props?.post) {
const pageId = prefix
if (pageId.length >= 32) {
const post = await getNotion(pageId)
const post = await getPost(pageId)
props.post = post
}
}