Skip to content

Commit

Permalink
feat: show memos by default in feed
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindballa committed Jan 9, 2024
1 parent 5d77982 commit 930076a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 3 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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),
Expand Down
16 changes: 9 additions & 7 deletions pages/writings/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -43,7 +44,7 @@ export default function WritingsPage({ allPosts }: { allPosts: (Post | Memo)[] }
</Link>
<Link
className={filter === 'blog' ? 'text-headings underline' : 'hover:text-headings'}
href="/writings"
href="/writings?filter=blog"
>
Blog posts
</Link>
Expand Down Expand Up @@ -92,10 +93,11 @@ export default function WritingsPage({ allPosts }: { allPosts: (Post | Memo)[] }
<span>
{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()}
</span>
<span>&middot;</span>
<Chip>Memo</Chip>
Expand Down

1 comment on commit 930076a

@vercel
Copy link

@vercel vercel bot commented on 930076a Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.