Guides listing on homepage

This commit is contained in:
Kamran Ahmed
2021-08-29 16:34:00 +02:00
parent 964a87f605
commit ec0cd4692c
66 changed files with 4031 additions and 118 deletions

29
lib/guide.ts Normal file
View File

@ -0,0 +1,29 @@
import guides from '../content/guides.json';
import authors from '../content/authors.json';
import formatDate from 'date-fns/format';
export type GuideType = {
title: string;
description: string;
url: string;
fileName: string;
isPro: boolean;
author: string;
isDraft: boolean;
createdAt: string;
updatedAt: string;
formattedCreatedAt: string;
formattedUpdatedAt: string;
};
export function getAllGuides(limit: number = undefined): GuideType[] {
return (guides as GuideType[])
.filter(guide => !guide.isDraft)
.sort((a, b) => (new Date(b.updatedAt) as any) - (new Date(a.updatedAt) as any))
.map(guide => ({
...guide,
formattedCreatedAt: formatDate(new Date(guide.createdAt), 'MMMM d, yyyy'),
formattedUpdatedAt: formatDate(new Date(guide.updatedAt), 'MMMM d, yyyy')
}))
.slice(0, limit ? limit : guides.length);
}