Skip to content

Commit

Permalink
Merge pull request tangly1024#2163 from tangly1024/feat/frame-work
Browse files Browse the repository at this point in the history
frame-work lib/db
  • Loading branch information
tangly1024 authored Mar 10, 2024
2 parents de1b8fa + 1fb9ba4 commit f8a7f49
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/db/getSiteData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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实现
Expand Down
2 changes: 1 addition & 1 deletion lib/notion/getNotion.js → lib/notion/getNotionPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions pages/[prefix]/[slug]/[...suffix].js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}
}
Expand Down
5 changes: 2 additions & 3 deletions pages/[prefix]/[slug]/index.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}
}
Expand Down
5 changes: 2 additions & 3 deletions pages/[prefix]/index.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit f8a7f49

Please sign in to comment.