Fix next and prev posts
This commit is contained in:
parent
4aca265fd1
commit
6c123c809a
@ -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];
|
||||
|
@ -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: {
|
||||
|
Loading…
Reference in New Issue
Block a user