Files
StevenandGitHub 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

78 lines
2.1 KiB
TypeScript

import type { GetStaticProps, NextPage } from "next";
import Head from "next/head";
import { useRouter } from "next/router";
import Carousel from "../../components/Carousel";
import getResults from "../../utils/cachedImages";
import cloudinary from "../../utils/cloudinary";
import getBase64ImageUrl from "../../utils/generateBlurPlaceholder";
import type { ImageProps } from "../../utils/types";
const Home: NextPage = ({ currentPhoto }: { currentPhoto: ImageProps }) => {
const router = useRouter();
const { photoId } = router.query;
let index = Number(photoId);
const currentPhotoUrl = `https://res.cloudinary.com/${process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME}/image/upload/c_scale,w_2560/${currentPhoto.public_id}.${currentPhoto.format}`;
return (
<>
<Head>
<title>Next.js Conf 2022 Photos</title>
<meta property="og:image" content={currentPhotoUrl} />
<meta name="twitter:image" content={currentPhotoUrl} />
</Head>
<main className="mx-auto max-w-[1960px] p-4">
<Carousel currentPhoto={currentPhoto} index={index} />
</main>
</>
);
};
export default Home;
export const getStaticProps: GetStaticProps = async (context) => {
const results = await getResults();
let reducedResults: ImageProps[] = [];
let i = 0;
for (let result of results.resources) {
reducedResults.push({
id: i,
height: result.height,
width: result.width,
public_id: result.public_id,
format: result.format,
});
i++;
}
const currentPhoto = reducedResults.find(
(img) => img.id === Number(context.params.photoId),
);
currentPhoto.blurDataUrl = await getBase64ImageUrl(currentPhoto);
return {
props: {
currentPhoto: currentPhoto,
},
};
};
export async function getStaticPaths() {
const results = await cloudinary.v2.search
.expression(`folder:${process.env.CLOUDINARY_FOLDER}/*`)
.sort_by("public_id", "desc")
.max_results(400)
.execute();
let fullPaths = [];
for (let i = 0; i < results.resources.length; i++) {
fullPaths.push({ params: { photoId: i.toString() } });
}
return {
paths: fullPaths,
fallback: false,
};
}