fix: site 404 page
This commit is contained in:
parent
ee31be70fd
commit
e8cded0eda
|
|
@ -1,4 +1,4 @@
|
|||
import { PageContent } from "~/components/common/PageContent"
|
||||
import { Image } from "~/components/ui/Image"
|
||||
import { SITE_URL } from "~/lib/env"
|
||||
import { useTranslation } from "~/lib/i18n"
|
||||
|
||||
|
|
@ -13,16 +13,20 @@ export default async function NotFound() {
|
|||
{t("404 - Whoops, this page is gone.")}
|
||||
</h2>
|
||||
</div>
|
||||
<PageContent
|
||||
className="mt-10"
|
||||
content={`
|
||||
- [${t("Back to Home")}](/)
|
||||
- [${t("All Posts")}](/archives)
|
||||
- [${t("Search Posts")}](/search)
|
||||
|
||||
`}
|
||||
toc={true}
|
||||
></PageContent>
|
||||
<div className="mt-10 xlog-post-content prose">
|
||||
<ul>
|
||||
<li>
|
||||
<a href="/">{t("Back to Home")}</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/archives">{t("All Posts")}</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/search">{t("Search Posts")}</a>
|
||||
</li>
|
||||
<Image alt="404" src={`${SITE_URL}/assets/404.svg`} />
|
||||
</ul>
|
||||
</div>
|
||||
</article>
|
||||
</>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
import { GetServerSidePropsContext, GetServerSidePropsResult } from "next"
|
||||
|
||||
class Redirect extends Error {
|
||||
constructor(public url: string) {
|
||||
super("")
|
||||
}
|
||||
}
|
||||
|
||||
class NotFound extends Error {}
|
||||
|
||||
export const redirect = (url: string) => new Redirect(url)
|
||||
|
||||
export const notFound = (message?: string) => new NotFound(message)
|
||||
|
||||
export const isNotFoundError = (error: unknown) => error instanceof NotFound
|
||||
|
||||
export const serverSidePropsHandler = <
|
||||
TProps extends { [key: string]: any } = { [key: string]: any },
|
||||
>(
|
||||
fn: (
|
||||
ctx: GetServerSidePropsContext,
|
||||
) => Promise<{ props: TProps } | Redirect | NotFound>,
|
||||
) => {
|
||||
return async (
|
||||
ctx: GetServerSidePropsContext,
|
||||
): Promise<GetServerSidePropsResult<TProps>> => {
|
||||
try {
|
||||
const result = await fn(ctx)
|
||||
if (result instanceof Redirect) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: result.url,
|
||||
permanent: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
if (result instanceof NotFound) {
|
||||
return {
|
||||
notFound: true,
|
||||
}
|
||||
}
|
||||
return result
|
||||
} catch (error: any) {
|
||||
console.log("serverSidePropsHandler error", error)
|
||||
const actualError = error.cause || error
|
||||
if (actualError instanceof Redirect) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: actualError.url,
|
||||
permanent: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
if (actualError instanceof NotFound) {
|
||||
return {
|
||||
notFound: true,
|
||||
}
|
||||
}
|
||||
ctx.res.statusCode = 500
|
||||
return {
|
||||
props: {
|
||||
// @ts-expect-error
|
||||
error: error.message,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,6 @@ import { GeneralAccount } from "@crossbell/connect-kit"
|
|||
import { indexer } from "@crossbell/indexer"
|
||||
|
||||
import { expandCrossbellNote } from "~/lib/expand-unit"
|
||||
import { notFound } from "~/lib/server-side-props"
|
||||
import { checkSlugReservedWords } from "~/lib/slug-reserved-words"
|
||||
import { getKeys, getStorage } from "~/lib/storage"
|
||||
import { ExpandedNote, PageVisibilityEnum } from "~/lib/types"
|
||||
|
|
@ -449,10 +448,6 @@ export async function getPage<TRender extends boolean = false>(input: {
|
|||
}
|
||||
}
|
||||
|
||||
if (!expandedNote && !mustLocal) {
|
||||
throw notFound(`page ${input.slug} not found`)
|
||||
}
|
||||
|
||||
return expandedNote
|
||||
}
|
||||
|
||||
|
|
@ -496,9 +491,7 @@ export async function checkLike({
|
|||
characterId: number
|
||||
noteId: number
|
||||
}) {
|
||||
if (!account.characterId) {
|
||||
throw notFound(`character not found`)
|
||||
} else {
|
||||
if (account.characterId) {
|
||||
return indexer.link.getMany(account.characterId, {
|
||||
linkType: "like",
|
||||
toCharacterId: characterId,
|
||||
|
|
|
|||
Loading…
Reference in New Issue