diff --git a/src/lib/content/contentApi.ts b/src/lib/content/contentApi.ts index 342be2d..baf5bea 100644 --- a/src/lib/content/contentApi.ts +++ b/src/lib/content/contentApi.ts @@ -1,5 +1,6 @@ import GhostContentAPI from '@tryghost/content-api'; +import dayjs from 'dayjs'; export const GHOST_URL = 'https://admin.blog.nanao.moe'; const GHOST_KEY = '8c86e852c31b39b9d4148b2088'; @@ -16,16 +17,16 @@ export const browsePost = async (page = 1) => { return posts } -export const browseNextPost = async (id: string) => { - const posts = await api.posts.browse({ limit: 1, filter: [`id:>${id}`], order: 'id ASC' }); +export const browseNextPost = async (post: any) => { + const posts = await api.posts.browse({ limit: 1, filter: [`published_at:>'${post.published_at}'`], order: 'published_at ASC' }); if (posts.length > 0) { return posts[0]; } return null; } -export const browsePrevPost = async (id: string) => { - const posts = await api.posts.browse({ limit: 1, filter: [`id:<${id}`], order: 'id DESC' }); +export const browsePrevPost = async (post: any) => { + const posts = await api.posts.browse({ limit: 1, filter: [`published_at:<'${post.published_at}'`], order: 'published_at DESC' }); if (posts.length > 0) { return posts[0]; diff --git a/src/routes/[tag]/[slug].svelte b/src/routes/[tag]/[slug].svelte index b212e2c..b6ff777 100644 --- a/src/routes/[tag]/[slug].svelte +++ b/src/routes/[tag]/[slug].svelte @@ -8,8 +8,8 @@ error: new Error('Post not found') }; } - const prevPost = await browsePrevPost(post.id); - const nextPost = await browseNextPost(post.id); + const prevPost = await browsePrevPost(post); + const nextPost = await browseNextPost(post); const relatedPost = await browseRelatedPost(post.primary_tag?.slug, post.id); return { props: {