Skip to content

Instantly share code, notes, and snippets.

@JEverhart383
Created June 6, 2022 19:00
Show Gist options
  • Select an option

  • Save JEverhart383/b6ae40984c0520caee84968ebb83c6dd to your computer and use it in GitHub Desktop.

Select an option

Save JEverhart383/b6ae40984c0520caee84968ebb83c6dd to your computer and use it in GitHub Desktop.
// Lives at pages/[productSlug]/index.js
import { getNextStaticProps } from '@faustjs/next';
import { client } from 'client';
import { Footer, Header, EntryHeader, Main, SEO } from 'components';
import { useRouter } from 'next/router';
import { pageTitle, is404Cpt } from 'utils';
export function ProductComponent() {
const { useQuery } = client;
const generalSettings = useQuery().generalSettings;
const { query = {} } = useRouter();
const { productSlug } = query;
console.log(productSlug);
const product = useQuery().product({
id: productSlug,
idType: 'SLUG',
});
return (
<>
<SEO
title={pageTitle(
generalSettings,
product?.name,
generalSettings?.title
)}
imageUrl={product?.image?.sourceUrl}
/>
<Header />
<Main>
<EntryHeader
title={product?.name}
date={product?.date}
image={product?.image}
/>
<div className="container">{product?.description}</div>
</Main>
<Footer />
</>
);
}
export default function Page() {
return <ProductComponent />;
}
export async function getStaticProps(context) {
const productSlug = context?.params?.productSlug;
return getNextStaticProps(context, {
Page,
client,
notFound: await is404Cpt(productSlug, 'product'),
});
}
export function getStaticPaths() {
return {
paths: [],
fallback: 'blocking',
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment