diff --git a/...[[...slug]]/category-page-preview.tsx b/...[[...slug]]/category-page-preview.tsx deleted file mode 100644 index d2e8abea3..000000000 --- a/...[[...slug]]/category-page-preview.tsx +++ /dev/null @@ -1,26 +0,0 @@ -'use client' - -import PreviewBanner from 'components/ui/preview-banner' -import { usePreview } from 'lib/sanity/sanity.preview' -import CategoryPage from './category-page' - -export default function CategoryPagePreview({ - query, - queryParams, -}: { - query: string - queryParams: { - [key: string]: any - } -}) { - const data = usePreview(null, query, queryParams) - - const { title, _type } = data - - return ( - <> - - - - ) -} \ No newline at end of file diff --git a/...[[...slug]]/category-page.tsx b/...[[...slug]]/category-page.tsx deleted file mode 100644 index 46ae4b2ad..000000000 --- a/...[[...slug]]/category-page.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import { notFound } from "next/navigation"; - -interface CategoryPageProps { - data: object | any -} - -// This is a Client Component. It receives data as props and -// has access to state and effects just like Page components -// in the `pages` directory. -export default function CategoryPage({data }: CategoryPageProps) { - - if (!data) { - return notFound(); - } - - return ( -
Category: {data?.title}
- ) -} diff --git a/...[[...slug]]/home-page-preview.tsx b/...[[...slug]]/home-page-preview.tsx deleted file mode 100644 index 567f24f60..000000000 --- a/...[[...slug]]/home-page-preview.tsx +++ /dev/null @@ -1,26 +0,0 @@ -'use client' - -import PreviewBanner from 'components/ui/preview-banner' -import { usePreview } from 'lib/sanity/sanity.preview' -import HomePage from './home-page' - -export default function HomePagePreview({ - query, - queryParams, -}: { - query: string - queryParams: { - [key: string]: any - } -}) { - const data = usePreview(null, query, queryParams) - - const { title, _type } = data - - return ( - <> - - - - ) -} \ No newline at end of file diff --git a/...[[...slug]]/home-page.tsx b/...[[...slug]]/home-page.tsx deleted file mode 100644 index 8ea1be716..000000000 --- a/...[[...slug]]/home-page.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import DynamicContentManager from 'components/layout/dynamic-content-manager' - -interface HomePageProps { - data: object | any -} - -// This is a Client Component. It receives data as props and -// has access to state and effects just like Page components -// in the `pages` directory. -export default function HomePage({ data }: HomePageProps) { - return ( - - ) -} diff --git a/...[[...slug]]/page.tsx b/...[[...slug]]/page.tsx deleted file mode 100644 index af5b76004..000000000 --- a/...[[...slug]]/page.tsx +++ /dev/null @@ -1,137 +0,0 @@ -// Next -import type { Metadata } from 'next'; -import { draftMode } from 'next/headers'; -// Sanity -import PreviewSuspense from 'components/preview-suspense'; -import getQueryFromSlug from 'helpers/getQueryFromSlug'; -import { docQuery } from 'lib/sanity/queries'; -import { clientFetch } from 'lib/sanity/sanity.client'; -// Pages. -import CategoryPage from './category-page'; -import CategoryPagePreview from './category-page-preview'; -import HomePage from './home-page'; -import HomePagePreview from './home-page-preview'; -import ProductPage from './product-page'; -import ProductPagePreview from './product-page-preview'; -import SinglePage from './single-page'; -import SinglePagePreview from './single-page-preview'; -// Chrome -import Footer from 'components/layout/footer'; -import Header from 'components/layout/header'; - -/** - * Render pages depending on type. - */ -export default async function Page({ params }: { params: { slug: string[]; locale: string } }) { - const { isEnabled } = draftMode(); - - const { slug, locale } = params; - - const { query = '', queryParams, docType } = getQueryFromSlug(slug, locale); - - const pageData = await clientFetch(query, queryParams); - - const data = filterDataToSingleItem(pageData, isEnabled); - - const localeData = { - type: data._type, - locale: data.locale, - translations: data.translations - }; - - return ( -
-
-
-
- {isEnabled ? ( - - {docType === 'home' && } - {docType === 'page' && } - {docType === 'product' && ( - - )} - {docType === 'category' && ( - - )} - - ) : ( - <> - {docType === 'home' && } - {docType === 'product' && } - {docType === 'category' && } - {docType === 'page' && } - - )} -
-
-
-
- ); -} - -/** - * Get paths for each page. - */ -export async function generateStaticParams() { - const paths = await clientFetch(docQuery); - - return paths.map((path: { slug: string; locale: string }) => ({ - slug: path.slug.split('/').filter((p) => p), - locale: path.locale - })); -} - -/** - * Helper function to return the correct version of the document - * If we're in "preview mode" and have multiple documents, return the draft - */ -function filterDataToSingleItem(data: any, preview = false) { - if (!Array.isArray(data)) { - return data; - } - - if (data.length === 1) { - return data[0]; - } - - if (preview) { - return data.find((item) => item._id.startsWith(`drafts.`)) || data[0]; - } - - return data[0]; -} - -/** - * Generate metadata for each page. - */ -export async function generateMetadata({ - params -}: { - params: { slug: string[]; locale: string }; -}): Promise { - const { slug, locale } = params; - - const { query = '', queryParams } = getQueryFromSlug(slug, locale); - - const pageData = await clientFetch(query, queryParams); - - const data = filterDataToSingleItem(pageData, false); - - const { seo } = data ?? {}; - - return { - title: seo?.title ? seo?.title : data?.title, - description: seo?.description ? seo.description : 'Webb och digitalbyrå från Göteborg', - openGraph: { - images: [ - { - url: seo?.image?.asset?.url ? seo.image.asset.url : '/og-image.jpg', - width: 1200, - height: 630, - alt: seo?.coverImage?.alt ? seo.coverImage.alt : 'Kodamera AB' - } - ] - } - }; -} diff --git a/...[[...slug]]/product-page-preview.tsx b/...[[...slug]]/product-page-preview.tsx deleted file mode 100644 index 21ed044dd..000000000 --- a/...[[...slug]]/product-page-preview.tsx +++ /dev/null @@ -1,26 +0,0 @@ -'use client' - -import PreviewBanner from 'components/ui/preview-banner' -import { usePreview } from 'lib/sanity/sanity.preview' -import ProductPage from './product-page' - -export default function ProductPagePreview({ - query, - queryParams, -}: { - query: string - queryParams: { - [key: string]: any - } -}) { - const data = usePreview(null, query, queryParams) - - const { title, _type } = data - - return ( - <> - - - - ) -} \ No newline at end of file diff --git a/...[[...slug]]/product-page.tsx b/...[[...slug]]/product-page.tsx deleted file mode 100644 index 49d34df0b..000000000 --- a/...[[...slug]]/product-page.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import ProductView from 'components/product/product-view'; -import { notFound } from 'next/navigation'; - -interface ProductPageProps { - data: object | any; -} - -// This is a Client Component. It receives data as props and -// has access to state and effects just like Page components -// in the `pages` directory. -export default function ProductPage({ data }: ProductPageProps) { - if (!data) { - return notFound(); - } - - const { product } = data; - - return ; -} diff --git a/...[[...slug]]/single-page-preview.tsx b/...[[...slug]]/single-page-preview.tsx deleted file mode 100644 index c09e74193..000000000 --- a/...[[...slug]]/single-page-preview.tsx +++ /dev/null @@ -1,26 +0,0 @@ -'use client' - -import PreviewBanner from 'components/ui/preview-banner' -import { usePreview } from 'lib/sanity/sanity.preview' -import SinglePage from './single-page' - -export default function SinglePagePreview({ - query, - queryParams, -}: { - query: string - queryParams: { - [key: string]: any - } -}) { - const data = usePreview(null, query, queryParams) - - const { title, _type } = data - - return ( - <> - - - - ) -} \ No newline at end of file diff --git a/...[[...slug]]/single-page.tsx b/...[[...slug]]/single-page.tsx deleted file mode 100644 index 7a378f1ab..000000000 --- a/...[[...slug]]/single-page.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import DynamicContentManager from 'components/layout/dynamic-content-manager'; -import { notFound } from "next/navigation"; - -interface SinglePageProps { - data: object | any -} - -// This is a Client Component. It receives data as props and -// has access to state and effects just like Page components -// in the `pages` directory. -export default function SinglePage({data }: SinglePageProps) { - - if (!data) { - return notFound(); - } - - return ( - - ) -} diff --git a/app/[locale]/kategori/[slug]/page.tsx b/app/[locale]/[...slug]/components/category-page.tsx similarity index 55% rename from app/[locale]/kategori/[slug]/page.tsx rename to app/[locale]/[...slug]/components/category-page.tsx index e3be582ba..7546ee7ec 100644 --- a/app/[locale]/kategori/[slug]/page.tsx +++ b/app/[locale]/[...slug]/components/category-page.tsx @@ -1,35 +1,19 @@ import Search from '@/components/search/search'; import SearchResult from '@/components/search/search-result'; import Text from '@/components/ui/text/text'; -import { categoryQuery } from '@/lib/sanity/queries'; import { clientFetch } from '@/lib/sanity/sanity.client'; -import { Metadata } from 'next'; import { notFound } from 'next/navigation'; -export async function generateMetadata({ - params -}: { - params: { slug: string; locale: string }; -}): Promise { - const category = await clientFetch(categoryQuery, params); - - if (!category) return notFound(); - - return { - title: category.seo.title || category.title, - description: category.seo.description || category.description - }; -} - interface CategoryPageParams { - params: { - locale: string; + query: string; + queryParams: { slug: string; + locale: string; }; } -export default async function ProductPage({ params }: CategoryPageParams) { - const category = await clientFetch(categoryQuery, params); +export default async function CategoryPage({ query, queryParams }: CategoryPageParams) { + const category = await clientFetch(query, queryParams); if (!category) return notFound(); diff --git a/app/[locale]/[...slug]/components/product-page.tsx b/app/[locale]/[...slug]/components/product-page.tsx new file mode 100644 index 000000000..e98f4e21a --- /dev/null +++ b/app/[locale]/[...slug]/components/product-page.tsx @@ -0,0 +1,37 @@ +import ProductView from '@/components/product/product-view'; +import { clientFetch } from '@/lib/sanity/sanity.client'; +import { notFound } from 'next/navigation'; + +interface ProductPageParams { + query: string; + queryParams: { + slug: string; + locale: string; + }; +} + +export default async function ProductPage({ query, queryParams }: ProductPageParams) { + const product = await clientFetch(query, queryParams); + + if (!product) return notFound(); + + const productJsonLd = { + '@context': 'https://schema.org', + '@type': 'Product', + name: product.name, + description: product.description, + image: product.images[0].asset.url + }; + + return ( + <> +