rsnext/examples/blog-with-comment/pages/posts/index.tsx
Steven 4466ba436b
chore(examples): use default prettier for examples/templates (#60530)
## Description
This PR ensures that the default prettier config is used for examples
and templates.

This config is compatible with `prettier@3` as well (upgrading prettier
is bigger change that can be a future PR).

## Changes
- Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will
be needed upgrading to prettier@3)
- Added `examples/.prettierrc.json` with default config (this will
change every example)
- Added `packages/create-next-app/templates/.prettierrc.json` with
default config (this will change every template)

## Related

- Fixes #54402
- Closes #54409
2024-01-11 16:01:44 -07:00

41 lines
1.1 KiB
TypeScript

import type { InferGetStaticPropsType } from "next";
import Link from "next/link";
import Container from "../../components/container";
import distanceToNow from "../../lib/dateRelative";
import { getAllPosts } from "../../lib/getPost";
export default function NotePage({
allPosts,
}: InferGetStaticPropsType<typeof getStaticProps>) {
return (
<Container>
{allPosts.length ? (
allPosts.map((post) => (
<article key={post.slug} className="mb-10">
<Link
as={`/posts/${post.slug}`}
href="/posts/[slug]"
className="text-lg leading-6 font-bold"
>
{post.title}
</Link>
<p>{post.excerpt}</p>
<div className="text-gray-400">
<time>{distanceToNow(new Date(post.date))}</time>
</div>
</article>
))
) : (
<p>No blog posted yet :/</p>
)}
</Container>
);
}
export async function getStaticProps() {
const allPosts = getAllPosts(["slug", "title", "excerpt", "date"]);
return {
props: { allPosts },
};
}