feat: do not use SitePage on the preview page

This commit is contained in:
DIYgod
2023-05-09 23:17:51 +01:00
parent 24b4b284b3
commit 9d4b21adb9
3 changed files with 28 additions and 20 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ export default async function SitePagePage({
return (
<Hydrate state={dehydratedState}>
<SitePage page={page || undefined} site={site || undefined} t={t} />
<SitePage page={page || undefined} site={site || undefined} />
</Hydrate>
)
}
@@ -1,6 +1,6 @@
"use client"
import { SitePage } from "~/components/site/SitePage"
import { PageContent } from "~/components/common/PageContent"
import { useTranslation } from "~/lib/i18n/client"
import { useGetPage } from "~/queries/page"
import { useGetSite } from "~/queries/site"
@@ -28,10 +28,30 @@ export default function SitePreviewPage({
const { t } = useTranslation("site")
return (
<SitePage
page={page.data || undefined}
site={site.data || undefined}
t={t}
/>
<>
<div className="fixed top-0 left-0 w-full text-center text-red-500 bg-gray-100 py-2 opacity-80 text-sm z-10">
{t(
"This address is in local editing preview mode and cannot be viewed by the public.",
)}
</div>
<article>
<div>
{page.data?.metadata?.content?.tags?.includes("post") ? (
<h2 className="xlog-post-title text-4xl font-bold">
{page.data.metadata?.content?.title}
</h2>
) : (
<h2 className="xlog-post-title text-xl font-bold page-title">
{page.data?.metadata?.content?.title}
</h2>
)}
</div>
<PageContent
className="mt-10"
content={page.data?.metadata?.content?.content}
toc={true}
></PageContent>
</article>
</>
)
}
+1 -13
View File
@@ -1,4 +1,3 @@
import { TFunction } from "i18next"
import serialize from "serialize-javascript"
import { PageContent } from "~/components/common/PageContent"
@@ -10,13 +9,9 @@ import { ExpandedCharacter, ExpandedNote } from "~/lib/types"
export function SitePage({
page,
site,
preview,
t,
}: {
page?: ExpandedNote
site?: ExpandedCharacter
preview?: boolean
t: TFunction
}) {
function addPageJsonLd() {
return {
@@ -48,13 +43,6 @@ export function SitePage({
type="application/ld+json"
dangerouslySetInnerHTML={addPageJsonLd()}
/>
{preview && (
<div className="fixed top-0 left-0 w-full text-center text-red-500 bg-gray-100 py-2 opacity-80 text-sm z-10">
{t(
"This address is in local editing preview mode and cannot be viewed by the public.",
)}
</div>
)}
<article>
<div>
{page?.metadata?.content?.tags?.includes("post") ? (
@@ -66,7 +54,7 @@ export function SitePage({
{page?.metadata?.content?.title}
</h2>
)}
{page?.metadata?.content?.tags?.includes("post") && !preview && (
{page?.metadata?.content?.tags?.includes("post") && (
/* @ts-expect-error Async Server Component */
<PostMeta page={page} site={site} />
)}