Files
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

83 lines
2.1 KiB
TypeScript

import { useRouter } from "next/router";
import Head from "next/head";
import ErrorPage from "next/error";
import Container from "@components/container";
import MoreStories from "@components/more-stories";
import Header from "@components/header";
import PostHeader from "@components/post-header";
import PostBody from "@components/post-body";
import SectionSeparator from "@components/section-separator";
import Layout from "@components/layout";
import PostTitle from "@components/post-title";
import { CMS_NAME } from "@lib/constants";
import { getAllPostsWithSlug, getPostAndMorePosts } from "@lib/api";
export default function Post({ post, morePosts, preview }) {
const router = useRouter();
if (!router.isFallback && !post) {
return <ErrorPage statusCode={404} />;
}
const title = `${
post?.title || "dotcms"
} | Next.js Blog Example with ${CMS_NAME}`;
return (
<Layout preview={preview}>
<Container>
<Header />
{router.isFallback ? (
<PostTitle>Loading…</PostTitle>
) : (
<>
<article>
<Head>
<title>{title}</title>
<meta
property="og:image"
content={`${process.env.NEXT_PUBLIC_DOTCMS_HOST}${post.image.idPath}`}
/>
</Head>
<PostHeader
title={post.title}
coverImage={post.image}
author={post.author}
/>
<PostBody content={post} />
</article>
<SectionSeparator />
{morePosts && morePosts.length > 0 && (
<MoreStories posts={morePosts} />
)}
</>
)}
</Container>
</Layout>
);
}
export async function getStaticProps({ params, preview = false }) {
const data = await getPostAndMorePosts(params.slug, preview);
return {
props: {
preview,
...data,
},
};
}
export async function getStaticPaths() {
const allPosts = await getAllPostsWithSlug();
return {
paths: allPosts?.map((post) => `/posts/${post.urlTitle}`) || [],
fallback: true,
};
}