feat: new

This commit is contained in:
2025-11-28 20:22:33 +08:00
parent 7cffbaaacf
commit 9a93e8060c
6 changed files with 50 additions and 26 deletions

View File

@@ -94,16 +94,16 @@ export function normalizePost(post: NotionPost): CollectionEntry<'blog'> {
}
}
export async function getAllPosts(): Promise<CollectionEntry<'blog'>[]> {
export async function getAllPosts(page?: Number, size?: Number): Promise<CollectionEntry<'blog'>[]> {
try {
const res = await fetch("https://notion-api.nvme0n1p.dev/v2/posts")
const res = await fetch(`https://notion-api.nvme0n1p.dev/v2/posts?page=${page ?? 1}&length=${size ?? 1000}`)
if (!res.ok) throw new Error(`Failed to fetch posts: ${res.status}`)
const payload = (await res.json()) as { posts?: NotionPost[] }
const payload = (await res.json()) as { posts?: NotionPost[], length?: number }
const posts = (payload.posts ?? []).filter(
(post) => post.Published ?? true,
)
const length = payload.length;
const normalized = posts.map(normalizePost)
return normalized
@@ -545,7 +545,6 @@ function buildBlocks(
i++
continue
}
if (current.type === 'bulleted_list' || current.type === 'numbered_list') {
const listItems: Block[] = []
const targetType = current.type
@@ -748,7 +747,7 @@ function convertBlock(
}
case 'bookmark': {
const url =
block.properties?.link_url?.[0]?.[0] ||
block.properties?.link?.[0]?.[0] ||
block.properties?.source?.[0]?.[0] ||
block.properties?.title?.[0]?.[0] ||
''
@@ -758,7 +757,7 @@ function convertBlock(
Type: 'bookmark',
HasChildren: false,
Bookmark: {
Caption: parseRichTexts(block.properties?.caption),
Caption: parseRichTexts(block.properties?.title),
Url: url,
},
}