fix: solved the problem of only-content params. (#936)
This commit is contained in:
Generated
+1
-1
@@ -1,4 +1,4 @@
|
||||
lockfileVersion: '6.0'
|
||||
lockfileVersion: '6.1'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
|
||||
@@ -13,8 +13,8 @@ import { getSiteLink } from "~/lib/helpers"
|
||||
import { getTranslation } from "~/lib/i18n"
|
||||
import { toCid, toGateway } from "~/lib/ipfs-parser"
|
||||
import { isInRN } from "~/lib/is-in-rn"
|
||||
import { isOnlyContent } from "~/lib/is-only-client"
|
||||
import getQueryClient from "~/lib/query-client"
|
||||
import { isOnlyContent } from "~/lib/search-parser"
|
||||
import { fetchGetPage, getSummary } from "~/queries/page.server"
|
||||
import { fetchGetSite } from "~/queries/site.server"
|
||||
|
||||
@@ -103,7 +103,7 @@ export default async function SitePagePage({
|
||||
}
|
||||
|
||||
const dehydratedState = dehydrate(queryClient)
|
||||
const onlyContent = isOnlyContent()
|
||||
const onlyContent = await isOnlyContent()
|
||||
|
||||
function addPageJsonLd() {
|
||||
return {
|
||||
|
||||
@@ -13,8 +13,8 @@ import { SiteHeader } from "~/components/site/SiteHeader"
|
||||
import { FABContainer } from "~/components/ui/FAB"
|
||||
import { SITE_URL } from "~/lib/env"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { isOnlyContent, searchParser } from "~/lib/is-only-client"
|
||||
import getQueryClient from "~/lib/query-client"
|
||||
import { isOnlyContent } from "~/lib/search-parser"
|
||||
import { ExpandedNote } from "~/lib/types"
|
||||
import { cn } from "~/lib/utils"
|
||||
import { fetchGetPage } from "~/queries/page.server"
|
||||
@@ -93,17 +93,21 @@ export default async function SiteLayout({
|
||||
}) {
|
||||
const queryClient = getQueryClient()
|
||||
|
||||
const search = await searchParser()
|
||||
// https://github.com/vercel/next.js/issues/46618#issuecomment-1450416633
|
||||
// Issue: The type will not be updated when the page is redirected.
|
||||
let pathname = headers().get("x-xlog-pathname")
|
||||
const onlyContent = isOnlyContent()
|
||||
const onlyContent = await isOnlyContent()
|
||||
|
||||
if (pathname && /^(\/site(?!\/.*\/preview\/).*)/.test(pathname)) {
|
||||
redirect(
|
||||
`${getSiteLink({
|
||||
subdomain: params.site,
|
||||
})}/${pathname.replace(/\/site\/(.*)\//, "")}`,
|
||||
)
|
||||
const targetPath = `${getSiteLink({
|
||||
subdomain: params.site,
|
||||
})}/${pathname.replace(/\/site\/(.*)\//, "")}`
|
||||
|
||||
const targetUrl = new URL(targetPath)
|
||||
targetUrl.search = search.toString()
|
||||
|
||||
redirect(targetUrl.toString())
|
||||
}
|
||||
|
||||
let type: string
|
||||
|
||||
@@ -2,13 +2,14 @@ import { type MutableRefObject, memo } from "react"
|
||||
|
||||
import PostActions from "~/components/site/PostActions"
|
||||
import PostToc from "~/components/site/PostToc"
|
||||
import { isOnlyContent } from "~/lib/is-only-client"
|
||||
import { ExpandedCharacter, ExpandedNote } from "~/lib/types"
|
||||
import { cn } from "~/lib/utils"
|
||||
import { renderPageContent } from "~/markdown"
|
||||
|
||||
import { PageContentContainer } from "./PageContentContainer"
|
||||
|
||||
const PageContent = memo(function PageContent({
|
||||
const PageContent = memo(async function PageContent({
|
||||
className,
|
||||
content,
|
||||
toc,
|
||||
@@ -40,6 +41,8 @@ const PageContent = memo(function PageContent({
|
||||
inParsedContent = renderPageContent(content, false, isComment)
|
||||
}
|
||||
|
||||
const onlyContent = await isOnlyContent()
|
||||
|
||||
return (
|
||||
<PageContentContainer
|
||||
className={cn("relative", className)}
|
||||
@@ -55,8 +58,10 @@ const PageContent = memo(function PageContent({
|
||||
>
|
||||
{inParsedContent?.element}
|
||||
</div>
|
||||
{toc && inParsedContent?.toc && <PostToc data={inParsedContent?.toc} />}
|
||||
{withActions && <PostActions page={page} site={site} />}
|
||||
{!onlyContent && toc && inParsedContent?.toc && (
|
||||
<PostToc data={inParsedContent?.toc} />
|
||||
)}
|
||||
{!onlyContent && withActions && <PostActions page={page} site={site} />}
|
||||
</>
|
||||
</PageContentContainer>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { isServerSide } from "./utils"
|
||||
|
||||
export const searchParser = async () => {
|
||||
let search
|
||||
if (isServerSide()) {
|
||||
const { headers } = await import("next/headers")
|
||||
search = headers().get("x-xlog-search")
|
||||
} else {
|
||||
search = window.location.search
|
||||
}
|
||||
|
||||
return new URLSearchParams(search?.substring(1) || "")
|
||||
}
|
||||
|
||||
export const isOnlyContent = async () => {
|
||||
return (await searchParser()).get("only-content")
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { headers } from "next/headers"
|
||||
|
||||
export const searchParser = () => {
|
||||
const search = headers().get("x-xlog-search")
|
||||
|
||||
return new URLSearchParams(search?.substring(1) || "")
|
||||
}
|
||||
|
||||
export const isOnlyContent = () => {
|
||||
return searchParser().get("only-content")
|
||||
}
|
||||
Reference in New Issue
Block a user