Skip to content

Commit

Permalink
feat: add tutorials page
Browse files Browse the repository at this point in the history
  • Loading branch information
HamzaAmar committed Oct 17, 2023
1 parent a870121 commit b119136
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
43 changes: 43 additions & 0 deletions apps/docs/src/pages/docs/tutorials/[slug].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ParsedUrlQuery } from 'querystring'
import { useMDXComponent } from 'next-contentlayer/hooks'
import { GetStaticProps } from 'next'
import { allTutorials } from 'contentlayer/generated'
import type { Tutorials } from 'contentlayer/generated'
import { DocsLayout, mdxComponents } from '../../../component/common'
import { DocHeader } from '../../../component/core'

interface Params extends ParsedUrlQuery {
slug: string
}

export const getStaticProps: GetStaticProps = async ({ params }) => {
const { slug } = params as Params

const post = allTutorials.find((component) => slug === component.slug)

return { props: { post } }
}

export function getStaticPaths() {
return {
paths: allTutorials.map(({ slug }) => ({
params: {
slug,
},
})),

fallback: false,
}
}

export default function Components({ post }: { post: Tutorials }) {
const { body, ...rest } = post
const Component = useMDXComponent(body.code)

return (
<DocsLayout {...rest}>
<DocHeader {...rest} />
<Component components={mdxComponents} />
</DocsLayout>
)
}
29 changes: 29 additions & 0 deletions apps/docs/src/pages/docs/tutorials/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react'
import { allTutorials } from 'contentlayer/generated'
import type { Tutorials } from 'contentlayer/generated'
import { Paper, Grid, Text } from '@pillar-ui/core'
import { Layout } from '../../../component/common'
import Link from 'next/link'

export async function getStaticProps() {
return { props: { tutorials: allTutorials } }
}

export default function Blog({ tutorials }: { tutorials: Tutorials[] }) {
// components.forEach((com) => console.log(com.slug, com.title))
return (
<Layout>
<Paper as={Grid} m="md" grid="repeat(4, 1fr)" gap="sm">
{tutorials.map((tutorial) => (
<Link href={`utils/${tutorial.slug}`} key={tutorial.slug}>
<Paper height="5rem" corner="sm" background="surface-3" padding="xl" className="u_center">
<Text size="lg" weight="medium" color="surface">
{tutorial.title}
</Text>
</Paper>
</Link>
))}
</Paper>
</Layout>
)
}
8 changes: 4 additions & 4 deletions apps/docs/src/pages/docs/utils/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react'
import { allUtils } from 'contentlayer/generated'
import type { Utils } from 'contentlayer/generated'
import { allTutorials } from 'contentlayer/generated'
import type { Tutorials } from 'contentlayer/generated'
import { Paper, Grid, Text } from '@pillar-ui/core'
import Link from 'next/link'
import { Layout } from '../../../component/common'

export async function getStaticProps() {
return { props: { utils: allUtils } }
return { props: { utils: allTutorials } }
}

export default function utils({ utils }: { utils: Utils[] }) {
export default function utils({ utils }: { utils: Tutorials[] }) {
return (
<Layout>
<Paper as={Grid} m="md" grid="repeat(4, 1fr)" gap="sm">
Expand Down

0 comments on commit b119136

Please sign in to comment.