parent
5edb358a04
commit
63775bf2f5
|
|
@ -5,7 +5,7 @@
|
|||
"list": [
|
||||
10, 30, 12, 32022, 32179, 45, 19, 4583, 4381, 32168, 33446, 33492, 52055,
|
||||
153, 50143, 51470, 31132, 45089, 50351, 52343, 5825, 51406, 53864, 43086,
|
||||
47393, 54315, 50131, 54939, 55096, 55081, 45828, 55343
|
||||
47393, 54315, 50131, 54939, 55096, 55081, 45828
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
import { Metadata } from "next"
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { Hydrate, dehydrate } from "@tanstack/react-query"
|
||||
|
||||
import { SitePage } from "~/components/site/SitePage"
|
||||
import { SITE_URL } from "~/lib/env"
|
||||
import { useTranslation } from "~/lib/i18n"
|
||||
import getQueryClient from "~/lib/query-client"
|
||||
import { fetchGetPage } from "~/queries/page.server"
|
||||
import { fetchGetSite } from "~/queries/site.server"
|
||||
|
|
@ -68,10 +72,33 @@ export default async function SitePagePage({
|
|||
slug: string
|
||||
}
|
||||
}) {
|
||||
const queryClient = getQueryClient()
|
||||
|
||||
const site = await fetchGetSite(params.site, queryClient)
|
||||
|
||||
const page = await fetchGetPage(
|
||||
{
|
||||
characterId: site?.characterId,
|
||||
slug: params.slug,
|
||||
useStat: true,
|
||||
},
|
||||
queryClient,
|
||||
)
|
||||
|
||||
if (
|
||||
!page ||
|
||||
new Date(page!.metadata?.content?.date_published || "") > new Date()
|
||||
) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
const dehydratedState = dehydrate(queryClient)
|
||||
|
||||
const { t } = await useTranslation("site")
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* @ts-expect-error Async Server Component */}
|
||||
<SitePage params={params} />
|
||||
</>
|
||||
<Hydrate state={dehydratedState}>
|
||||
<SitePage page={page || undefined} site={site || undefined} />
|
||||
</Hydrate>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,26 @@
|
|||
import { SitePage } from "~/components/site/SitePage"
|
||||
import { SITE_URL } from "~/lib/env"
|
||||
import { useTranslation } from "~/lib/i18n"
|
||||
|
||||
export default async function NotFound() {
|
||||
const { t } = await useTranslation("site")
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* @ts-expect-error Async Server Component */}
|
||||
<SitePage />
|
||||
</>
|
||||
<SitePage
|
||||
page={
|
||||
{
|
||||
metadata: {
|
||||
content: {
|
||||
title: t("404 - Whoops, this page is gone."),
|
||||
content: `
|
||||
- [Back to Home](/)
|
||||
- [All posts](/archives)
|
||||
|
||||
`,
|
||||
},
|
||||
},
|
||||
} as any
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,67 +1,18 @@
|
|||
import { notFound } from "next/navigation"
|
||||
import serialize from "serialize-javascript"
|
||||
|
||||
import { Hydrate, dehydrate } from "@tanstack/react-query"
|
||||
|
||||
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 { ExpandedCharacter, ExpandedNote } from "~/lib/types"
|
||||
import { fetchGetPage } from "~/queries/page.server"
|
||||
import { fetchGetSite } from "~/queries/site.server"
|
||||
|
||||
export async function SitePage({
|
||||
params,
|
||||
export function SitePage({
|
||||
page,
|
||||
site,
|
||||
}: {
|
||||
params?: {
|
||||
site: string
|
||||
slug: string
|
||||
}
|
||||
page?: ExpandedNote
|
||||
site?: ExpandedCharacter
|
||||
}) {
|
||||
const { t } = await useTranslation("site")
|
||||
|
||||
const queryClient = getQueryClient()
|
||||
|
||||
let site: ExpandedCharacter | undefined | null
|
||||
let page: ExpandedNote | undefined | null
|
||||
if (params) {
|
||||
site = await fetchGetSite(params.site, queryClient)
|
||||
page = await fetchGetPage(
|
||||
{
|
||||
characterId: site?.characterId,
|
||||
slug: params.slug,
|
||||
useStat: true,
|
||||
},
|
||||
queryClient,
|
||||
)
|
||||
} else {
|
||||
page = {
|
||||
metadata: {
|
||||
content: {
|
||||
title: t("404 - Whoops, this page is gone."),
|
||||
content: `
|
||||
- [Back to Home](/)
|
||||
- [All posts](/archives)
|
||||
|
||||
`,
|
||||
},
|
||||
},
|
||||
} as ExpandedNote
|
||||
}
|
||||
|
||||
if (
|
||||
!page ||
|
||||
new Date(page!.metadata?.content?.date_published || "") > new Date()
|
||||
) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
const dehydratedState = dehydrate(queryClient)
|
||||
|
||||
function addPageJsonLd() {
|
||||
return {
|
||||
__html: serialize({
|
||||
|
|
@ -114,11 +65,7 @@ export async function SitePage({
|
|||
toc={true}
|
||||
></PageContent>
|
||||
</article>
|
||||
{page?.metadata && (
|
||||
<Hydrate state={dehydratedState}>
|
||||
<PostFooter page={page} site={site || undefined} />
|
||||
</Hydrate>
|
||||
)}
|
||||
{page?.metadata && <PostFooter page={page} site={site} />}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue