-
-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
15 changed files
with
467 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const Container: Component = ({ children }) => { | ||
return ( | ||
<div className="container m-auto mt-[120px] max-w-6xl px-2 md:px-6 lg:p-0"> | ||
{children} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import React from 'react' | ||
import { headers } from 'next/dist/client/components/headers' | ||
import { notFound } from 'next/navigation' | ||
import type { Metadata } from 'next' | ||
|
||
import { RequestError } from '@mx-space/api-client' | ||
|
||
import { NotSupport } from '~/components/common/NotSupport' | ||
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView' | ||
import { CommentRoot } from '~/components/widgets/comment/CommentRoot' | ||
import { REQUEST_GEO } from '~/constants/system' | ||
import { attachUA } from '~/lib/attach-ua' | ||
import { getSummaryFromMd } from '~/lib/markdown' | ||
import { CurrentPageDataProvider } from '~/providers/page/CurrentPageDataProvider' | ||
import { LayoutRightSideProvider } from '~/providers/shared/LayoutRightSideProvider' | ||
import { queries } from '~/queries/definition' | ||
import { getQueryClient } from '~/utils/query-client.server' | ||
|
||
import { Container } from './Container' | ||
|
||
export const generateMetadata = async ({ | ||
params, | ||
}: { | ||
params: PageParams | ||
}): Promise<Metadata> => { | ||
const { slug } = params | ||
try { | ||
attachUA() | ||
const data = await getQueryClient().fetchQuery(queries.page.bySlug(slug)) | ||
const { title, images, text } = data | ||
const description = getSummaryFromMd(text ?? '') | ||
|
||
const ogImage = images?.length | ||
? { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
url: images[0].src!, | ||
} | ||
: undefined | ||
return { | ||
title, | ||
description, | ||
openGraph: { | ||
title, | ||
description, | ||
images: ogImage, | ||
type: 'article', | ||
}, | ||
twitter: { | ||
images: ogImage, | ||
title, | ||
description, | ||
card: 'summary_large_image', | ||
}, | ||
} satisfies Metadata | ||
} catch { | ||
return {} | ||
} | ||
} | ||
|
||
interface PageParams { | ||
slug: string | ||
} | ||
|
||
export default async (props: NextPageParams<PageParams>) => { | ||
attachUA() | ||
const { | ||
params: { slug }, | ||
} = props | ||
const query = queries.page.bySlug(slug) | ||
// const queryKey = query.queryKey | ||
const data = await getQueryClient() | ||
.fetchQuery(query) | ||
.catch((error) => { | ||
if (error instanceof RequestError && error.status === 404) { | ||
return notFound() | ||
} | ||
throw error | ||
}) | ||
const header = headers() | ||
const geo = header.get(REQUEST_GEO) | ||
|
||
const isCN = geo === 'CN' | ||
return ( | ||
<Container> | ||
<CurrentPageDataProvider data={data} /> | ||
<div className="relative flex min-h-[120px]"> | ||
<BottomToUpTransitionView className="min-w-0"> | ||
{props.children} | ||
</BottomToUpTransitionView> | ||
|
||
<LayoutRightSideProvider className="relative hidden lg:block" /> | ||
</div> | ||
{isCN ? <NotSupport /> : <CommentRoot refId={data.id} />} | ||
</Container> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Loading } from '~/components/ui/loading' | ||
|
||
export default () => ( | ||
<div className="absolute inset-0 flex h-[120px] center"> | ||
<Loading useDefaultLoadingText /> | ||
</div> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use client' | ||
|
||
import { useEffect } from 'react' | ||
import { Balancer } from 'react-wrap-balancer' | ||
import type { Image } from '@mx-space/api-client' | ||
import type { PropsWithChildren } from 'react' | ||
|
||
import { useSetHeaderMetaInfo } from '~/components/layout/header/hooks' | ||
import { Markdown } from '~/components/ui/markdown' | ||
import { TocAside, TocAutoScroll } from '~/components/widgets/toc' | ||
import { noopArr } from '~/lib/noop' | ||
import { MarkdownImageRecordProvider } from '~/providers/article/MarkdownImageRecordProvider' | ||
import { useCurrentPageDataSelector } from '~/providers/page/CurrentPageDataProvider' | ||
import { LayoutRightSidePortal } from '~/providers/shared/LayoutRightSideProvider' | ||
import { WrappedElementProvider } from '~/providers/shared/WrappedElementProvider' | ||
|
||
import Loading from './loading' | ||
|
||
const PageDetail = () => { | ||
const id = useCurrentPageDataSelector((p) => p?.id) | ||
const title = useCurrentPageDataSelector((p) => p?.title) | ||
const subtitle = useCurrentPageDataSelector((p) => p?.subtitle) | ||
if (!id) { | ||
return <Loading /> | ||
} | ||
|
||
return ( | ||
<div> | ||
<HeaderMetaInfoSetting /> | ||
<article className="prose"> | ||
<header className="mb-8"> | ||
<h1 className="text-center lg:text-left"> | ||
<Balancer>{title}</Balancer> | ||
</h1> | ||
|
||
<desc className="text-center text-lg text-gray-600/70 dark:text-neutral-400 lg:text-left"> | ||
{subtitle} | ||
</desc> | ||
</header> | ||
<WrappedElementProvider> | ||
<MarkdownImageRecordProviderInternal> | ||
<PostMarkdown /> | ||
</MarkdownImageRecordProviderInternal> | ||
|
||
<LayoutRightSidePortal> | ||
<TocAside | ||
className="sticky top-[120px] ml-4 mt-[120px]" | ||
treeClassName="max-h-[calc(100vh-6rem-4.5rem-300px)] h-[calc(100vh-6rem-4.5rem-300px)] min-h-[120px] relative" | ||
/> | ||
<TocAutoScroll /> | ||
</LayoutRightSidePortal> | ||
</WrappedElementProvider> | ||
</article> | ||
</div> | ||
) | ||
} | ||
|
||
const PostMarkdown = () => { | ||
const text = useCurrentPageDataSelector((data) => data?.text) | ||
if (!text) return null | ||
|
||
return <Markdown value={text} as="main" className="min-w-0 overflow-hidden" /> | ||
} | ||
const MarkdownImageRecordProviderInternal = (props: PropsWithChildren) => { | ||
const images = useCurrentPageDataSelector( | ||
(data) => data?.images || (noopArr as Image[]), | ||
) | ||
if (!images) return null | ||
|
||
return ( | ||
<MarkdownImageRecordProvider images={images}> | ||
{props.children} | ||
</MarkdownImageRecordProvider> | ||
) | ||
} | ||
|
||
const HeaderMetaInfoSetting = () => { | ||
const setHeaderMetaInfo = useSetHeaderMetaInfo() | ||
const meta = useCurrentPageDataSelector((data) => { | ||
if (!data) return null | ||
|
||
return { | ||
title: data.title, | ||
description: data.subtitle || '', | ||
slug: `/${data.slug}`, | ||
} | ||
}) | ||
|
||
useEffect(() => { | ||
if (meta) setHeaderMetaInfo(meta) | ||
}, [meta]) | ||
|
||
return null | ||
} | ||
|
||
export default PageDetail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use client' | ||
|
||
import React, { memo, useMemo } from 'react' | ||
import Link from 'next/link' | ||
import type { IHeaderMenu } from '../config' | ||
|
||
import { FloatPopover } from '~/components/ui/float-popover' | ||
|
||
export const MenuPopover: Component<{ | ||
subMenu: IHeaderMenu['subMenu'] | ||
}> = memo(({ children, subMenu }) => { | ||
const TriggerComponent = useMemo(() => () => children, [children]) | ||
if (!subMenu) return children | ||
return ( | ||
<FloatPopover | ||
strategy="fixed" | ||
headless | ||
placement="bottom" | ||
offset={10} | ||
popoverWrapperClassNames="z-[19] relative" | ||
popoverClassNames="rounded-xl !p-0" | ||
TriggerComponent={TriggerComponent} | ||
> | ||
{!!subMenu.length && ( | ||
<div className="relative flex w-[130px] flex-col px-4"> | ||
{subMenu.map((m) => { | ||
return ( | ||
<Link | ||
key={m.title} | ||
href={`${m.path}`} | ||
className="flex w-full items-center justify-around space-x-2 py-3 duration-200 hover:text-accent" | ||
role="button" | ||
> | ||
{!!m.icon && <span>{m.icon}</span>} | ||
<span>{m.title}</span> | ||
</Link> | ||
) | ||
})} | ||
</div> | ||
)} | ||
</FloatPopover> | ||
) | ||
}) | ||
MenuPopover.displayName = 'MenuPopover' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
98837de
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
springtide – ./
springtide.vercel.app
springtide-innei.vercel.app
innei.in
springtide-git-main-innei.vercel.app