You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
49 lines
1.4 KiB
import { format, parseISO } from 'date-fns';
|
|
import { GetStaticProps } from 'next';
|
|
import Link from 'next/link';
|
|
import React from 'react';
|
|
import Layout from '../components/Layout';
|
|
import { getAllPosts } from '../lib/api';
|
|
import { PostType } from '../types/post';
|
|
|
|
type IndexProps = {
|
|
posts: PostType[];
|
|
};
|
|
|
|
export const Index = ({ posts }: IndexProps): JSX.Element => {
|
|
return (
|
|
<Layout>
|
|
<h1>или Учись или уходи!</h1>
|
|
{posts.map((post) => (
|
|
<article key={post.slug} className="mt-12">
|
|
<p className="mb-1 text-sm text-gray-500 dark:text-gray-400">
|
|
{format(parseISO(post.date), 'MMMM dd, yyyy')}
|
|
</p>
|
|
<h1 className="mb-2 text-xl">
|
|
<Link as={`/posts/${post.slug}`} href={`/posts/[slug]`}>
|
|
<a className="text-gray-900 dark:text-white dark:hover:text-blue-400">
|
|
{post.title}
|
|
</a>
|
|
</Link>
|
|
</h1>
|
|
<p className="mb-3">{post.description}</p>
|
|
<p>
|
|
<Link as={`/posts/${post.slug}`} href={`/posts/[slug]`}>
|
|
<a>Подробнее...</a>
|
|
</Link>
|
|
</p>
|
|
</article>
|
|
))}
|
|
</Layout>
|
|
);
|
|
};
|
|
|
|
export const getStaticProps: GetStaticProps = async () => {
|
|
const posts = getAllPosts(['date', 'description', 'slug', 'title']);
|
|
|
|
return {
|
|
props: { posts },
|
|
};
|
|
};
|
|
|
|
export default Index;
|
|
|