Skip to content

Commit

Permalink
helper function for card title and description generation
Browse files Browse the repository at this point in the history
  • Loading branch information
simonswiss committed Jul 4, 2024
1 parent c841031 commit f175fea
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
42 changes: 24 additions & 18 deletions docs/components/docs/WalkthroughsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import { jsx } from '@emotion/react'

import { Well } from '../primitives/Well'
import { useMediaQuery } from '../../lib/media'
import { InlineCode } from '../../components/primitives/Code'
import { type DocsArray } from '../../pages/docs'
import { Markdoc } from '../Markdoc'
import { getDocsPageCardContent } from '../../lib/get-docs-page-card-content'

export function Walkthroughs ({ items }: { items: DocsArray }) {
export function Walkthroughs ({
quickstart,
lessons,
}: {
quickstart: DocsArray[number] | undefined
lessons: DocsArray
}) {
const mq = useMediaQuery()
return (
<div>
Expand All @@ -20,9 +25,14 @@ export function Walkthroughs ({ items }: { items: DocsArray }) {
margin: '0 0 var(--space-xlarge) 0',
})}
>
<Well heading="Keystone Quick Start" href="/docs/getting-started">
Take a tour of Keystone in minutes with our CLI starter project
</Well>
{quickstart && (
<Well
heading={getDocsPageCardContent(quickstart).title}
href={`/docs/${quickstart.slug}`}
>
{getDocsPageCardContent(quickstart).description}
</Well>
)}
</div>
<div
css={mq({
Expand All @@ -31,18 +41,14 @@ export function Walkthroughs ({ items }: { items: DocsArray }) {
gap: 'var(--space-xlarge)',
})}
>
{items.map((item) => (
<Well
key={item.slug}
grad="grad2"
heading={item.entry?.cardTitle || item.entry.title}
href={`/docs/${item.slug}`}
>
{item.entry.cardIntro.children?.length
? item.entry.cardIntro.children.map((child, i) => <Markdoc key={i} content={child} />)
: item.entry.description}
</Well>
))}
{lessons.map((lesson) => {
const { title, description } = getDocsPageCardContent(lesson)
return (
<Well key={lesson.slug} grad="grad2" heading={title} href={`/docs/${lesson.slug}`}>
{description}
</Well>
)
})}
</div>
</div>
)
Expand Down
11 changes: 11 additions & 0 deletions docs/lib/get-docs-page-card-content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Markdoc } from '../components/Markdoc'
import { type DocsArray } from '../pages/docs'

export function getDocsPageCardContent ({ entry }: DocsArray[number]) {
let title = entry.cardTitle || entry.title
let description = entry.cardIntro.children?.length
? entry.cardIntro.children.map((child, i) => <Markdoc key={i} content={child} />)
: entry.description

return {title, description}
}
18 changes: 12 additions & 6 deletions docs/pages/docs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ export default function Docs ({ docs }: InferGetStaticPropsType<typeof getStatic
Step-by-step instructions for getting things done with Keystone.
</Type>

<Walkthroughs items={docs.filter((doc) => doc.slug.startsWith('walkthroughs'))} />
<Walkthroughs
quickstart={docs.find(doc => doc.slug === 'getting-started')}
lessons={docs.filter(doc => doc.slug.startsWith('walkthroughs'))}
/>

<Type as="h2" look="heading30" margin="2rem 0 1rem 0">
Guides
Expand Down Expand Up @@ -351,7 +354,10 @@ export default function Docs ({ docs }: InferGetStaticPropsType<typeof getStatic

export type DocsArray = {
slug: string
entry: Omit<EntryWithResolvedLinkedFiles<typeof keystaticConfig['collections']['docs']>, 'cardIntro'> & {
entry: Omit<
EntryWithResolvedLinkedFiles<typeof keystaticConfig['collections']['docs']>,
'cardIntro'
> & {
cardIntro: Tag
}
}[]
Expand All @@ -361,13 +367,13 @@ export async function getStaticProps (): Promise<
docs: DocsArray
}>
> {
const docs = await reader.collections.docs.all({ resolveLinkedFiles: true})
const withParsedCardIntro = docs.map(doc => ({
const docs = await reader.collections.docs.all({ resolveLinkedFiles: true })
const withParsedCardIntro = docs.map((doc) => ({
...doc,
entry: {
...doc.entry,
cardIntro: transform(doc.entry.cardIntro.node, baseMarkdocConfig)
}
cardIntro: transform(doc.entry.cardIntro.node, baseMarkdocConfig),
},
}))

return {
Expand Down

0 comments on commit f175fea

Please sign in to comment.