Skip to content

Commit

Permalink
Make docs page hub and sidebar navigation editable with Keystatic
Browse files Browse the repository at this point in the history
  • Loading branch information
simonswiss committed Jul 24, 2024
1 parent d46c311 commit 673b57c
Show file tree
Hide file tree
Showing 77 changed files with 2,065 additions and 978 deletions.
4 changes: 2 additions & 2 deletions docs/app/(site)/blog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const metadata: Metadata = {
title: 'Keystone Blog',
description: 'Blog posts from the team maintaining Keystone.',
openGraph: {
images: `${siteBaseUrl}/assets/blog/the-keystone-blog-cover.png`
}
images: `${siteBaseUrl}/assets/blog/the-keystone-blog-cover.png`,
},
}

export default async function Docs () {
Expand Down
9 changes: 3 additions & 6 deletions docs/app/(site)/docs/[...rest]/page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useParams } from 'next/navigation'
import { type Document } from './page'

import { extractHeadings, Markdoc } from '../../../../components/Markdoc'
import { DocsPage } from '../../../../components/Page'

import { Heading } from '../../../../components/docs/Heading'

export default function PageClient ({ document }: { document: Document }) {
Expand All @@ -17,17 +17,14 @@ export default function PageClient ({ document }: { document: Document }) {
]

return (
<DocsPage
headings={headings}
editPath={`docs/${(params?.rest as string[]).join('/')}.md`}
>
<>
<Heading level={1} id="title">
{document.title}
</Heading>

{document.content.children.map((child, i) => (
<Markdoc key={i} content={child} />
))}
</DocsPage>
</>
)
}
24 changes: 15 additions & 9 deletions docs/app/(site)/docs/[...rest]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { baseMarkdocConfig } from '../../../../markdoc/config'
import PageClient from './page-client'
import { type EntryWithResolvedLinkedFiles } from '@keystatic/core/reader'
import type keystaticConfig from '../../../../keystatic.config'
import { DocsLayout } from '../../../../components/docs/DocsLayout'
import { extractHeadings } from '../../../../components/Markdoc'

export type Document = NonNullable<
Pick<
Expand All @@ -22,16 +24,20 @@ export default async function DocPage ({ params }) {
})
if (!doc) return notFound()

const transformedDoc: Document = {
...doc,
content: transform(doc.content.node, baseMarkdocConfig) as Tag,
}

const headings = [
{ id: 'title', depth: 1, label: transformedDoc.title },
// ...extractHeadings(transformedDoc.content),
]

return (
<PageClient
document={JSON.parse(
JSON.stringify({
...doc,
// Prepare content for Markdoc renderer
content: transform(doc.content.node, baseMarkdocConfig),
})
)}
/>
<DocsLayout headings={headings} editPath={`docs/${(params?.rest as string[]).join('/')}.md`}>
<PageClient document={JSON.parse(JSON.stringify(transformedDoc))} />
</DocsLayout>
)
}

Expand Down
10 changes: 2 additions & 8 deletions docs/app/(site)/docs/config/overview/page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@
import { CommunitySlackCTA } from '../../../../../components/docs/CommunitySlackCTA'
import { Type } from '../../../../../components/primitives/Type'
import { Well } from '../../../../../components/primitives/Well'
import { DocsPage } from '../../../../../components/Page'
import { useMediaQuery } from '../../../../../lib/media'

export default function Docs () {
const mq = useMediaQuery()

return (
<DocsPage
noRightNav
noProse
isIndexPage
editPath="docs/config/overview.tsx"
>
<>
<Type as="h1" look="heading64">
Configuration Overview
</Type>
Expand Down Expand Up @@ -60,6 +54,6 @@ export default function Docs () {
and one-time authentication tokens.
</Well>
</div>
</DocsPage>
</>
)
}
7 changes: 6 additions & 1 deletion docs/app/(site)/docs/config/overview/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DocsLayout } from '../../../../../components/docs/DocsLayout'
import PageClient from './page-client'

export const metadata = {
Expand All @@ -6,5 +7,9 @@ export const metadata = {
}

export default function Docs () {
return <PageClient />
return (
<DocsLayout noRightNav noProse isIndexPage editPath="docs/config/overview.tsx">
<PageClient />
</DocsLayout>
)
}
9 changes: 2 additions & 7 deletions docs/app/(site)/docs/examples/page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import { GitHubExamplesCTA } from '../../../../components/docs/GitHubExamplesCTA'
import { Type } from '../../../../components/primitives/Type'
import { DocsPage } from '../../../../components/Page'
import { Well } from '../../../../components/primitives/Well'
import { useMediaQuery } from '../../../../lib/media'
import { InlineCode } from '../../../../components/primitives/Code'
Expand All @@ -13,11 +12,7 @@ export default function Docs () {
const mq = useMediaQuery()

return (
<DocsPage
noRightNav
noProse
editPath={'docs/examples.tsx'}
>
<>
<Type as="h1" look="heading64">
Examples
</Type>
Expand Down Expand Up @@ -307,6 +302,6 @@ export default function Docs () {
project. <strong>One-click deployment</strong> included.
</Well>
</div>
</DocsPage>
</>
)
}
7 changes: 6 additions & 1 deletion docs/app/(site)/docs/examples/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DocsLayout } from '../../../../components/docs/DocsLayout'
import PageClient from './page-client'

export const metadata = {
Expand All @@ -7,5 +8,9 @@ export const metadata = {
}

export default function Docs () {
return <PageClient />
return (
<DocsLayout noRightNav noProse editPath={'docs/examples.tsx'}>
<PageClient />
</DocsLayout>
)
}
26 changes: 3 additions & 23 deletions docs/app/(site)/docs/guides/document-field-demo/page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from 'react'

import { H1, H2 } from '../../../../../components/docs/Heading'
import { DocsPage } from '../../../../../components/Page'

import {
DocumentEditorDemo,
DocumentFeaturesProvider,
Expand All @@ -16,27 +16,7 @@ import { InlineCode } from '../../../../../components/primitives/Code'
export default function DocumentFieldDemo () {
const title = 'Document Fields Demo'
return (
<DocsPage
noProse
headings={[
{
label: 'Document Fields Demo',
id: 'title',
depth: 1,
},
{
label: 'Configure the demo',
id: 'configure-the-demo',
depth: 2,
},
{
label: 'Related resources',
depth: 2,
id: 'related-resources',
},
]}
editPath="docs/guides/document-field-demo.tsx"
>
<>
<DocumentFeaturesProvider>
<div className="prose">
<H1 id="title">{title}</H1>
Expand Down Expand Up @@ -85,6 +65,6 @@ export default function DocumentFieldDemo () {
</RelatedContent>
</div>
</DocumentFeaturesProvider>
</DocsPage>
</>
)
}
27 changes: 26 additions & 1 deletion docs/app/(site)/docs/guides/document-field-demo/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DocsLayout } from '../../../../../components/docs/DocsLayout'
import PageClient from './page-client'

export const metadata = {
Expand All @@ -7,5 +8,29 @@ export const metadata = {
}

export default function DocumentFieldDemo () {
return <PageClient />
return (
<DocsLayout
noProse
headings={[
{
label: 'Document Fields Demo',
id: 'title',
depth: 1,
},
{
label: 'Configure the demo',
id: 'configure-the-demo',
depth: 2,
},
{
label: 'Related resources',
depth: 2,
id: 'related-resources',
},
]}
editPath="docs/guides/document-field-demo.tsx"
>
<PageClient />
</DocsLayout>
)
}
10 changes: 2 additions & 8 deletions docs/app/(site)/docs/guides/overview/page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@
import { CommunitySlackCTA } from '../../../../../components/docs/CommunitySlackCTA'
import { Type } from '../../../../../components/primitives/Type'
import { Well } from '../../../../../components/primitives/Well'
import { DocsPage } from '../../../../../components/Page'
import { useMediaQuery } from '../../../../../lib/media'

export default function Docs () {
const mq = useMediaQuery()

return (
<DocsPage
noRightNav
noProse
isIndexPage
editPath="docs/guides/overview.tsx"
>
<>
<Type as="h1" look="heading64">
Keystone Guides
</Type>
Expand Down Expand Up @@ -109,6 +103,6 @@ export default function Docs () {
Learn how to add your own custom pages to Keystone’s Admin UI.
</Well>
</div>
</DocsPage>
</>
)
}
7 changes: 6 additions & 1 deletion docs/app/(site)/docs/guides/overview/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DocsLayout } from '../../../../../components/docs/DocsLayout'
import PageClient from './page-client'

export const metadata = {
Expand All @@ -7,5 +8,9 @@ export const metadata = {
}

export default function Docs () {
return <PageClient />
return (
<DocsLayout noRightNav noProse isIndexPage editPath="docs/guides/overview.tsx">
<PageClient />
</DocsLayout>
)
}
Loading

0 comments on commit 673b57c

Please sign in to comment.