Files
nocturne/app/blog/fetch_posts.ts
lumither 603dbf71a6 feat(blog) add CMS, render blog posts list
- use GitHub repo as cms, read idx.json
- blog posts list
2024-04-27 12:03:08 +08:00

20 lines
522 B
TypeScript

import { Result } from '@/app/public/type/Result';
export default async function fetch_posts(url: string): Promise<Result<JSON[], Error>> {
const response = await fetch(`${ url }/posts/idx.json`);
if (!response.ok) {
return {
ok: false,
error: new Error(response.statusText)
};
}
const res = await response.json();
const posts = res['idx'].filter((posts: { type: string }) => posts.type === 'md');
return {
ok: true,
value: posts
};
}