fix: try to fix hydrate bug on site page
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import { Metadata } from "next"
|
||||
import { notFound } from "next/navigation"
|
||||
import serialize from "serialize-javascript"
|
||||
|
||||
import { Hydrate, dehydrate } from "@tanstack/react-query"
|
||||
|
||||
import { SitePage } from "~/components/site/SitePage"
|
||||
import { PageContent } from "~/components/common/PageContent"
|
||||
import { PostFooter } from "~/components/site/PostFooter"
|
||||
import PostMeta from "~/components/site/PostMeta"
|
||||
import { SITE_URL } from "~/lib/env"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { useTranslation } from "~/lib/i18n"
|
||||
import getQueryClient from "~/lib/query-client"
|
||||
import { fetchGetPage } from "~/queries/page.server"
|
||||
@@ -96,9 +100,61 @@ export default async function SitePagePage({
|
||||
|
||||
const { t } = await useTranslation("site")
|
||||
|
||||
function addPageJsonLd() {
|
||||
return {
|
||||
__html: serialize({
|
||||
"@context": "https://schema.org",
|
||||
"@type": "BlogPosting",
|
||||
headline: page?.metadata?.content?.title,
|
||||
...(page?.metadata?.content?.cover && {
|
||||
image: [page?.metadata?.content?.cover],
|
||||
}),
|
||||
datePublished: page?.metadata?.content?.date_published,
|
||||
dateModified: page?.updatedAt,
|
||||
author: [
|
||||
{
|
||||
"@type": "Person",
|
||||
name: site?.metadata?.content?.name,
|
||||
url: getSiteLink({
|
||||
subdomain: site?.handle || "",
|
||||
}),
|
||||
},
|
||||
],
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Hydrate state={dehydratedState}>
|
||||
<SitePage page={page || undefined} site={site || undefined} />
|
||||
</Hydrate>
|
||||
<>
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={addPageJsonLd()}
|
||||
/>
|
||||
<article>
|
||||
<div>
|
||||
{page?.metadata?.content?.tags?.includes("post") ? (
|
||||
<h2 className="xlog-post-title text-4xl font-bold">
|
||||
{page.metadata?.content?.title}
|
||||
</h2>
|
||||
) : (
|
||||
<h2 className="xlog-post-title text-xl font-bold page-title">
|
||||
{page?.metadata?.content?.title}
|
||||
</h2>
|
||||
)}
|
||||
{page?.metadata?.content?.tags?.includes("post") && (
|
||||
/* @ts-expect-error Async Server Component */
|
||||
<PostMeta page={page} site={site} />
|
||||
)}
|
||||
</div>
|
||||
<PageContent
|
||||
className="mt-10"
|
||||
content={page?.metadata?.content?.content}
|
||||
toc={true}
|
||||
></PageContent>
|
||||
</article>
|
||||
<Hydrate state={dehydratedState}>
|
||||
{page?.metadata && <PostFooter page={page} site={site} />}
|
||||
</Hydrate>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SitePage } from "~/components/site/SitePage"
|
||||
import { PageContent } from "~/components/common/PageContent"
|
||||
import { SITE_URL } from "~/lib/env"
|
||||
import { useTranslation } from "~/lib/i18n"
|
||||
|
||||
@@ -6,21 +6,23 @@ export default async function NotFound() {
|
||||
const { t } = await useTranslation("site")
|
||||
|
||||
return (
|
||||
<SitePage
|
||||
page={
|
||||
{
|
||||
metadata: {
|
||||
content: {
|
||||
title: t("404 - Whoops, this page is gone."),
|
||||
content: `
|
||||
<>
|
||||
<article>
|
||||
<div>
|
||||
<h2 className="xlog-post-title text-xl font-bold page-title">
|
||||
{t("404 - Whoops, this page is gone.")}
|
||||
</h2>
|
||||
</div>
|
||||
<PageContent
|
||||
className="mt-10"
|
||||
content={`
|
||||
- [Back to Home](/)
|
||||
- [All posts](/archives)
|
||||
|
||||
`,
|
||||
},
|
||||
},
|
||||
} as any
|
||||
}
|
||||
/>
|
||||
`}
|
||||
toc={true}
|
||||
></PageContent>
|
||||
</article>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user