From 930076a489b886118b272daaa8463a5406fdeed2 Mon Sep 17 00:00:00 2001 From: Aravind Balla Date: Tue, 9 Jan 2024 06:45:04 +0530 Subject: [PATCH] feat: show memos by default in feed --- pages/index.tsx | 5 +++-- pages/writings/index.tsx | 16 +++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index bbba1d5..cc0a61b 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,5 +1,5 @@ import Link from 'next/link'; -import { allPosts, Post } from 'contentlayer/generated'; +import { allMemos, allPosts, Post } from 'contentlayer/generated'; import Layout from '../components/Layout'; import ImagekitImage from '../components/ImagekitImage'; @@ -118,9 +118,10 @@ export default function Home({ allPosts }: { allPosts: Post[] }) { } export const getStaticProps = async () => { + const allItems = [...allMemos, ...allPosts]; return { props: { - allPosts: allPosts + allPosts: allItems .filter((post) => ('published' in post ? post.published : true)) .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()) .slice(0, 3), diff --git a/pages/writings/index.tsx b/pages/writings/index.tsx index 58da99d..8b03e42 100644 --- a/pages/writings/index.tsx +++ b/pages/writings/index.tsx @@ -1,7 +1,8 @@ import Link from 'next/link'; import { NextSeo } from 'next-seo'; import { allPosts, allMemos, Post, Memo } from 'contentlayer/generated'; -import { isToday, formatDistanceStrict, subDays } from 'date-fns'; +import { isToday, formatRelative } from 'date-fns'; +import { enIN } from 'date-fns/locale'; import { useSearchParams } from 'next/navigation'; import Layout from '../../components/Layout'; @@ -12,7 +13,7 @@ import Chip from 'components/Chip'; export default function WritingsPage({ allPosts }: { allPosts: (Post | Memo)[] }) { const params = useSearchParams(); - const filter = params?.get('filter') || 'blog'; + const filter = params?.get('filter') || 'all'; const postsToShow = allPosts.filter((post) => { if (filter === 'all') return true; @@ -43,7 +44,7 @@ export default function WritingsPage({ allPosts }: { allPosts: (Post | Memo)[] } Blog posts @@ -92,10 +93,11 @@ export default function WritingsPage({ allPosts }: { allPosts: (Post | Memo)[] } {isToday(new Date(post.date)) ? 'Today' - : formatDistanceStrict(new Date(post.date), subDays(new Date(), 1), { - addSuffix: true, - unit: 'day', - })} + : formatRelative(new Date(post.date), new Date(), { locale: enIN }) + .replace(/at .*/, '') + // capitalize first letter + .replace(/^\w/, (c) => c.toUpperCase()) + .trim()} · Memo