This commit is contained in:
Julien Calixte
2022-02-27 17:01:45 +01:00
parent d469314fc0
commit 632409b71a
23 changed files with 328 additions and 101 deletions

View File

@@ -0,0 +1,35 @@
import { computed } from "vue";
interface Post {
filename: string;
lastUpdated: Date;
href: string;
title: string;
meta: {
filename: string;
lastUpdated: Date;
href: string;
};
frontmatter: {
title: string;
publishedAt?: Date;
};
}
const byDate = (a: Post, b: Post) => {
if (!b.frontmatter.publishedAt) {
return -1;
}
if (!a.frontmatter.publishedAt) {
return 1;
}
return a.frontmatter.publishedAt <= b.frontmatter.publishedAt ? -1 : 1;
};
export const usePosts = () => {
const posts = $(useDocuments<Post>("@/pages/posts"));
return computed(() => posts.sort(byDate));
};