extract Post to module post

This commit is contained in:
Julien Calixte
2022-11-19 16:19:39 +01:00
parent 68e0ec355c
commit 0225d3076b
6 changed files with 114 additions and 28 deletions

View File

@@ -1,23 +1,6 @@
import { Post } from "@/modules/post/entities/Post"
import { computed } from "vue"
interface Post {
filename: string
lastUpdated: Date
href: string
title: string
date: Date
meta: {
filename: string
lastUpdated: Date
href: string
}
frontmatter: {
title: string
publishedAt?: Date
}
draft?: boolean
}
const byMostRecentFirst = (a: Post, b: Post) => {
if (!b.date) {
return 1
@@ -33,9 +16,5 @@ const byMostRecentFirst = (a: Post, b: Post) => {
export const usePosts = () => {
const posts = $(useDocuments<Post>("@/pages/posts"))
return computed(() =>
posts
.filter((post) => import.meta.env.DEV || post.draft !== true)
.sort(byMostRecentFirst)
)
return computed(() => posts.sort(byMostRecentFirst))
}