-
-
Notifications
You must be signed in to change notification settings - Fork 17
feat: new blocks page #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ea383ac
690feed
cbb899f
f3a2232
cb89da7
52582ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import type { Metadata } from "next" | ||
|
|
||
| import { CodeBlock, Pre } from "fumadocs-ui/components/codeblock" | ||
| import { DocsLayout } from "fumadocs-ui/layouts/docs" | ||
| import { notFound } from "next/navigation" | ||
|
|
||
| import { BlockInfoPane } from "@/components/blocks/block-info-pane" | ||
| import { BlockPreviewPane } from "@/components/blocks/block-preview-pane" | ||
| import { getMDXComponents } from "@/components/mdx-components" | ||
| import { | ||
| ResizableHandle, | ||
| ResizablePanel, | ||
| ResizablePanelGroup, | ||
| } from "@/components/ui/resizable" | ||
| import { getBlockShowcase } from "@/lib/block-showcase" | ||
| import { blocksSource } from "@/lib/blocks-source" | ||
|
|
||
| export const revalidate = false | ||
| export const dynamic = "force-static" | ||
| export const dynamicParams = false | ||
|
|
||
| type BlockPageProps = { | ||
| params: Promise<{ slug?: string[] }> | ||
| } | ||
|
|
||
| export default async function BlockPage(props: BlockPageProps) { | ||
| const params = await props.params | ||
| const slug = params.slug ?? [] | ||
| const page = blocksSource.getPage(slug) | ||
|
|
||
| if (!page) { | ||
| notFound() | ||
| } | ||
|
|
||
| const showcase = getBlockShowcase(page.data.preview) | ||
|
|
||
| const MDXContent = page.data.body | ||
| const PreviewComponent = showcase.component | ||
| const content = ( | ||
|
Comment on lines
+35
to
+39
|
||
| <MDXContent | ||
| components={getMDXComponents({ | ||
| pre: ({ ref: _ref, ...props }) => ( | ||
| <CodeBlock {...props} keepBackground> | ||
| <Pre>{props.children}</Pre> | ||
| </CodeBlock> | ||
| ), | ||
| })} | ||
| /> | ||
| ) | ||
|
|
||
| return ( | ||
| <div className="w-full"> | ||
| <DocsLayout | ||
| sidebar={{ | ||
| enabled: false, | ||
| }} | ||
| tree={blocksSource.getPageTree()} | ||
| > | ||
| <main className="relative min-h-screen bg-background"> | ||
| <div className="flex h-full w-full"> | ||
| <div | ||
| className={` | ||
| w-full | ||
| lg:hidden | ||
| `} | ||
| > | ||
| <BlockPreviewPane> | ||
| <PreviewComponent /> | ||
| </BlockPreviewPane> | ||
| <BlockInfoPane | ||
| content={content} | ||
| description={page.data.description} | ||
| title={page.data.title} | ||
| url={page.url} | ||
| /> | ||
| </div> | ||
|
|
||
| <div | ||
| className={` | ||
| hidden h-screen w-full | ||
| lg:block | ||
| `} | ||
| > | ||
| <ResizablePanelGroup> | ||
| <ResizablePanel defaultSize="35%"> | ||
| <BlockInfoPane | ||
| content={content} | ||
| description={page.data.description} | ||
| title={page.data.title} | ||
| url={page.url} | ||
| /> | ||
| </ResizablePanel> | ||
| <ResizableHandle className="z-20" withHandle /> | ||
| <ResizablePanel defaultSize="65%"> | ||
| <BlockPreviewPane> | ||
| <PreviewComponent /> | ||
| </BlockPreviewPane> | ||
| </ResizablePanel> | ||
| </ResizablePanelGroup> | ||
| </div> | ||
| </div> | ||
| </main> | ||
| </DocsLayout> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export async function generateMetadata( | ||
| props: BlockPageProps | ||
| ): Promise<Metadata> { | ||
| const params = await props.params | ||
|
|
||
| if (!params.slug?.length) { | ||
| return { | ||
| title: "Blocks", | ||
| } | ||
| } | ||
|
|
||
| const page = blocksSource.getPage(params.slug) | ||
|
|
||
| if (!page) notFound() | ||
|
|
||
| return { | ||
| description: page.data.description, | ||
| title: `${page.data.title} Block`, | ||
| } | ||
| } | ||
|
|
||
| export function generateStaticParams() { | ||
| return blocksSource.generateParams() | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,7 @@ | ||||
| @import "tailwindcss"; | ||||
|
||||
| @import "tailwindcss"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import type { ReactNode } from "react" | ||
|
|
||
| import { RootProvider } from "fumadocs-ui/provider/next" | ||
|
|
||
| import { BlocksSidebar } from "@/components/blocks/blocks-sidebar" | ||
| import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar" | ||
| import { blocksSource } from "@/lib/blocks-source" | ||
|
|
||
| import "./blocks.css" | ||
|
|
||
| export default function BlocksLayout({ children }: { children: ReactNode }) { | ||
| const items = blocksSource.getPages().map((page) => ({ | ||
| description: page.data.description, | ||
| href: page.url, | ||
| status: page.data.status, | ||
| title: page.data.title, | ||
| })) | ||
|
|
||
| return ( | ||
| <RootProvider | ||
| theme={{ | ||
| forcedTheme: "light", | ||
| }} | ||
| > | ||
| <SidebarProvider | ||
| defaultOpen={false} | ||
| style={ | ||
| { | ||
| "--sidebar-width": "20rem", | ||
| "--sidebar-width-mobile": "20rem", | ||
| } as React.CSSProperties | ||
| } | ||
| > | ||
| <BlocksSidebar items={items} /> | ||
| <SidebarInset>{children}</SidebarInset> | ||
| </SidebarProvider> | ||
| </RootProvider> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| @import "tailwindcss"; | ||
|
|
||
| :root { | ||
| --lp-timeline-track-height: 4px; | ||
| --lp-timeline-track-height-active: 7px; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,3 @@ | ||
| @import "tailwindcss"; | ||
| @import "tw-animate-css"; | ||
|
|
||
| @custom-variant dark (&:is(.dark *)); | ||
|
|
||
| @theme inline { | ||
|
|
||
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.
slugdefaults to[], which means the route/blockswill callblocksSource.getPage([])and likely 404 unless there is an index page incontent/docs/blocks. If/blocksis intended to be a valid landing page, handle the empty-slug case explicitly (redirect to a default block or render an index/list page).