mirror of
https://github.com/lbr77/blog-astro.git
synced 2026-04-09 00:19:12 +00:00
feat: new
This commit is contained in:
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user