format project
This commit is contained in:
parent
7651afaa0b
commit
a6d4064af8
83 changed files with 942 additions and 536 deletions
|
|
@ -1,35 +1,35 @@
|
|||
export type Categories = 'development' | 'work' | 'life';
|
||||
|
||||
export type Post = {
|
||||
title: string
|
||||
slug: string
|
||||
description: string
|
||||
image: {
|
||||
url: string;
|
||||
alt: string;
|
||||
}
|
||||
date: string
|
||||
categories: Categories[]
|
||||
published: boolean
|
||||
}
|
||||
title: string;
|
||||
slug: string;
|
||||
description: string;
|
||||
image: {
|
||||
url: string;
|
||||
alt: string;
|
||||
};
|
||||
date: string;
|
||||
categories: Categories[];
|
||||
published: boolean;
|
||||
};
|
||||
|
||||
export async function getPosts() {
|
||||
const posts: Post[] = []
|
||||
const posts: Post[] = [];
|
||||
|
||||
const paths = import.meta.glob('/src/lib/posts/*.md', { eager: true })
|
||||
const paths = import.meta.glob('/src/lib/posts/*.md', { eager: true });
|
||||
|
||||
for (const path in paths) {
|
||||
const file = paths[path]
|
||||
const slug = path.split('/').at(-1)?.replace('.md', '')
|
||||
for (const path in paths) {
|
||||
const file = paths[path];
|
||||
const slug = path.split('/').at(-1)?.replace('.md', '');
|
||||
|
||||
if (file && typeof file === 'object' && 'metadata' in file && slug) {
|
||||
const metadata = file.metadata as Omit<Post, 'slug'>
|
||||
const post = { ...metadata, slug } satisfies Post
|
||||
if (post.published) posts.push(post)
|
||||
}
|
||||
}
|
||||
if (file && typeof file === 'object' && 'metadata' in file && slug) {
|
||||
const metadata = file.metadata as Omit<Post, 'slug'>;
|
||||
const post = { ...metadata, slug } satisfies Post;
|
||||
if (post.published) posts.push(post);
|
||||
}
|
||||
}
|
||||
|
||||
return posts.sort((first, second) =>
|
||||
new Date(second.date).getTime() - new Date(first.date).getTime()
|
||||
)
|
||||
return posts.sort(
|
||||
(first, second) => new Date(second.date).getTime() - new Date(first.date).getTime()
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue