diff --git a/apps/core/app/[locale]/(default)/blog/[blogId]/page-data.ts b/apps/core/app/[locale]/(default)/blog/[blogId]/page-data.ts new file mode 100644 index 000000000..1be61b17f --- /dev/null +++ b/apps/core/app/[locale]/(default)/blog/[blogId]/page-data.ts @@ -0,0 +1,63 @@ +import { graphql } from 'gql.tada'; +import { cache } from 'react'; + +import { client } from '~/client'; +import { revalidate } from '~/client/revalidate-target'; + +const BlogPostPageQuery = graphql(` + query BlogPostPageQuery($entityId: Int!) { + site { + content { + blog { + isVisibleInNavigation + post(entityId: $entityId) { + author + htmlBody + id + name + publishedDate { + utc + } + tags + thumbnailImage { + altText + url: urlTemplate + } + seo { + metaKeywords + metaDescription + pageTitle + } + } + } + } + settings { + url { + vanityUrl + } + } + } + } +`); + +export const getBlogPost = cache(async ({ entityId }: { entityId: number }) => { + const response = await client.fetch({ + document: BlogPostPageQuery, + variables: { entityId }, + fetchOptions: { next: { revalidate } }, + }); + + const { blog } = response.data.site.content; + + if (!blog?.post) { + return null; + } + + const { isVisibleInNavigation, post } = blog; + + return { + ...post, + isVisibleInNavigation, + vanityUrl: response.data.site.settings?.url.vanityUrl, + }; +}); diff --git a/apps/core/app/[locale]/(default)/blog/[blogId]/page.tsx b/apps/core/app/[locale]/(default)/blog/[blogId]/page.tsx index 05a89f9b5..592bf851d 100644 --- a/apps/core/app/[locale]/(default)/blog/[blogId]/page.tsx +++ b/apps/core/app/[locale]/(default)/blog/[blogId]/page.tsx @@ -2,7 +2,6 @@ import type { Metadata } from 'next'; import { notFound } from 'next/navigation'; import { getFormatter } from 'next-intl/server'; -import { getBlogPost } from '~/client/queries/get-blog-post'; import { BcImage } from '~/components/bc-image'; import { Link } from '~/components/link'; import { SharingLinks } from '~/components/sharing-links'; @@ -16,6 +15,8 @@ import { import { Tag, TagContent } from '~/components/ui/tag'; import { LocaleType } from '~/i18n'; +import { getBlogPost } from './page-data'; + interface Props { params: { blogId: string; @@ -24,7 +25,7 @@ interface Props { } export async function generateMetadata({ params: { blogId } }: Props): Promise { - const blogPost = await getBlogPost(+blogId); + const blogPost = await getBlogPost({ entityId: Number(blogId) }); const title = blogPost?.seo.pageTitle ?? 'Blog'; @@ -35,7 +36,8 @@ export async function generateMetadata({ params: { blogId } }: Props): Promise