this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

sort by most recent first and only display drafts in development mode

+28 -22
+28 -22
src/hooks/usePosts.hook.ts
··· 1 - import { computed } from "vue"; 1 + import { computed } from "vue" 2 2 3 3 interface Post { 4 - filename: string; 5 - lastUpdated: Date; 6 - href: string; 7 - title: string; 4 + filename: string 5 + lastUpdated: Date 6 + href: string 7 + title: string 8 + date: Date 8 9 meta: { 9 - filename: string; 10 - lastUpdated: Date; 11 - href: string; 12 - }; 10 + filename: string 11 + lastUpdated: Date 12 + href: string 13 + } 13 14 frontmatter: { 14 - title: string; 15 - publishedAt?: Date; 16 - }; 15 + title: string 16 + publishedAt?: Date 17 + } 18 + draft?: boolean 17 19 } 18 20 19 - const byDate = (a: Post, b: Post) => { 20 - if (!b.frontmatter.publishedAt) { 21 - return -1; 21 + const byMostRecentFirst = (a: Post, b: Post) => { 22 + if (!b.date) { 23 + return 1 22 24 } 23 25 24 - if (!a.frontmatter.publishedAt) { 25 - return 1; 26 + if (!a.date) { 27 + return 1 26 28 } 27 29 28 - return a.frontmatter.publishedAt <= b.frontmatter.publishedAt ? -1 : 1; 29 - }; 30 + return a.date <= b.date ? 1 : -1 31 + } 30 32 31 33 export const usePosts = () => { 32 - const posts = $(useDocuments<Post>("@/pages/posts")); 34 + const posts = $(useDocuments<Post>("@/pages/posts")) 33 35 34 - return computed(() => posts.sort(byDate)); 35 - }; 36 + return computed(() => 37 + posts 38 + .filter((post) => import.meta.env.DEV || post.draft !== true) 39 + .sort(byMostRecentFirst) 40 + ) 41 + }