feat: redirect site links
This commit is contained in:
parent
2b4aa1d220
commit
189140ae41
|
|
@ -1,6 +1,6 @@
|
|||
import { Metadata } from "next"
|
||||
import { headers } from "next/headers"
|
||||
import { notFound } from "next/navigation"
|
||||
import { notFound, redirect } from "next/navigation"
|
||||
|
||||
import { Hydrate, dehydrate } from "@tanstack/react-query"
|
||||
|
||||
|
|
@ -12,6 +12,7 @@ import SiteFooter from "~/components/site/SiteFooter"
|
|||
import { SiteHeader } from "~/components/site/SiteHeader"
|
||||
import { FABContainer } from "~/components/ui/FAB"
|
||||
import { SITE_URL } from "~/lib/env"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import getQueryClient from "~/lib/query-client"
|
||||
import { isOnlyContent } from "~/lib/search-parser"
|
||||
import { ExpandedNote } from "~/lib/types"
|
||||
|
|
@ -92,15 +93,17 @@ export default async function SiteLayout({
|
|||
}) {
|
||||
const queryClient = getQueryClient()
|
||||
|
||||
const site = await fetchGetSite(params.site, queryClient)
|
||||
|
||||
// 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()
|
||||
|
||||
if (pathname?.startsWith("/site/")) {
|
||||
pathname = pathname.replace(/^\/site\/[^/]*/, "")
|
||||
redirect(
|
||||
`${getSiteLink({
|
||||
subdomain: params.site,
|
||||
})}/${pathname.replace(/\/site\/(.*)\//, "")}`,
|
||||
)
|
||||
}
|
||||
|
||||
let type: string
|
||||
|
|
@ -125,6 +128,8 @@ export default async function SiteLayout({
|
|||
}
|
||||
}
|
||||
|
||||
const site = await fetchGetSite(params.site, queryClient)
|
||||
|
||||
let page: ExpandedNote | undefined | null
|
||||
if (site?.characterId) {
|
||||
await Promise.all([
|
||||
|
|
|
|||
Loading…
Reference in New Issue