101 lines
2.9 KiB
TypeScript
101 lines
2.9 KiB
TypeScript
|
|
import GhostContentAPI from '@tryghost/content-api';
|
|
|
|
export const GHOST_URL = 'https://admin.blog.nanao.moe';
|
|
const GHOST_KEY = '8c86e852c31b39b9d4148b2088';
|
|
const GHOST_VERSION = 'v5.0';
|
|
|
|
const api = GhostContentAPI({
|
|
url: GHOST_URL,
|
|
key: GHOST_KEY,
|
|
version: GHOST_VERSION
|
|
})
|
|
|
|
export const browsePost = async (page = 1) => {
|
|
const posts = await api.posts.browse({ page: page, limit: 10, include: ['tags', 'authors'] });
|
|
|
|
return posts
|
|
}
|
|
export const browseNextPost = async (id: string) => {
|
|
const posts = await api.posts.browse({ limit: 1, filter: [`id:>${id}`], order: 'id 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' });
|
|
|
|
if (posts.length > 0) {
|
|
return posts[0];
|
|
}
|
|
return null;
|
|
}
|
|
export const browseRelatedPost = async (tag: string | undefined, id: string) => {
|
|
const tagCondition = tag ? [`tag:${tag}`] : []
|
|
const posts = await api.posts.browse({ limit: 3, filter: [...tagCondition, ...[`id:-${id}`]], order: 'published_at DESC', include: ['tags', 'authors'] });
|
|
|
|
return posts;
|
|
}
|
|
export const browseAllPost = async (page = 1) => {
|
|
const posts = await api.posts.browse({ limit: 'all' });
|
|
|
|
return posts
|
|
}
|
|
export const browsePostWithTag = async (slug: string, page = 1) => {
|
|
const posts = await api.posts.browse({ page: page, limit: 10, include: ['tags', 'authors'], filter: [`tag:${slug}`] });
|
|
|
|
return posts
|
|
}
|
|
export const browsePostWithAuthor = async (slug: string, page = 1) => {
|
|
const posts = await api.posts.browse({ page: page, limit: 10, include: ['tags', 'authors'], filter: [`author:${slug}`] });
|
|
|
|
return posts
|
|
}
|
|
export const readPost = async (slug: string) => {
|
|
try {
|
|
const post = await api.posts.read({ slug }, { include: ['tags', 'authors'] });
|
|
|
|
return post;
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export const readTag = async (slug: string) => {
|
|
try {
|
|
const tag = await api.tags.read({ slug });
|
|
|
|
return tag;
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export const readAuthor = async (slug: string) => {
|
|
try {
|
|
const author = await api.authors.read({ slug });
|
|
return author;
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export const browseLatestPost = async () => {
|
|
const post = await api.posts.browse({ limit: 1 });
|
|
|
|
return post[0];
|
|
}
|
|
export const browseLatestTag = async () => {
|
|
const tag = await api.tags.browse({ limit: 1, order: 'updated_at DESC' })
|
|
}
|
|
export const browseLatestAuthor = async () => {
|
|
const tag = await api.authors.browse({ limit: 1, order: 'updated_at DESC' })
|
|
}
|
|
export const browseSettings = async () => {
|
|
return {
|
|
codeinjection_head: `<script async defer data-domain="blog.nanao.moe" src="https://stats.nanao.moe/js/plausible.js"></script>`,
|
|
codeinjection_foot: ``,
|
|
};
|
|
} |