Fix next and prev posts

This commit is contained in:
Damillora 2022-07-24 06:08:24 +07:00
parent 4aca265fd1
commit 6c123c809a
2 changed files with 7 additions and 6 deletions

View File

@ -1,5 +1,6 @@
import GhostContentAPI from '@tryghost/content-api'; import GhostContentAPI from '@tryghost/content-api';
import dayjs from 'dayjs';
export const GHOST_URL = 'https://admin.blog.nanao.moe'; export const GHOST_URL = 'https://admin.blog.nanao.moe';
const GHOST_KEY = '8c86e852c31b39b9d4148b2088'; const GHOST_KEY = '8c86e852c31b39b9d4148b2088';
@ -16,16 +17,16 @@ export const browsePost = async (page = 1) => {
return posts return posts
} }
export const browseNextPost = async (id: string) => { export const browseNextPost = async (post: any) => {
const posts = await api.posts.browse({ limit: 1, filter: [`id:>${id}`], order: 'id ASC' }); const posts = await api.posts.browse({ limit: 1, filter: [`published_at:>'${post.published_at}'`], order: 'published_at ASC' });
if (posts.length > 0) { if (posts.length > 0) {
return posts[0]; return posts[0];
} }
return null; return null;
} }
export const browsePrevPost = async (id: string) => { export const browsePrevPost = async (post: any) => {
const posts = await api.posts.browse({ limit: 1, filter: [`id:<${id}`], order: 'id DESC' }); const posts = await api.posts.browse({ limit: 1, filter: [`published_at:<'${post.published_at}'`], order: 'published_at DESC' });
if (posts.length > 0) { if (posts.length > 0) {
return posts[0]; return posts[0];

View File

@ -8,8 +8,8 @@
error: new Error('Post not found') error: new Error('Post not found')
}; };
} }
const prevPost = await browsePrevPost(post.id); const prevPost = await browsePrevPost(post);
const nextPost = await browseNextPost(post.id); const nextPost = await browseNextPost(post);
const relatedPost = await browseRelatedPost(post.primary_tag?.slug, post.id); const relatedPost = await browseRelatedPost(post.primary_tag?.slug, post.id);
return { return {
props: { props: {