Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 4f10571

Browse files
authored
provide a way to have start steps for guides (#648)
1 parent e26fd0d commit 4f10571

File tree

6 files changed

+54
-8
lines changed

6 files changed

+54
-8
lines changed

contentlayer.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ const Doc = defineDocumentType(() => ({
4646
},
4747
description: 'The languages of the content, used by guides',
4848
},
49+
start_steps: {
50+
type: 'markdown',
51+
description: 'The start steps of the doc, used by guides',
52+
},
4953
},
5054
computedFields: {
5155
slug: {

docs/guides/go/realtime-messaging.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ tags:
55
- Key Value Store
66
languages:
77
- go
8+
start_steps: |
9+
git clone --depth 1 https://github.com/nitrictech/examples
10+
cd examples/v1/websocket-app
11+
go mod tidy
12+
nitric start
813
---
914

1015
# Building a chat app in Go with WebSockets and Nitric

src/app/[[...slug]]/layout.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Button } from '@/components/ui/button'
77
import { GitHubIcon } from '@/components/icons/GitHubIcon'
88
import Breadcrumbs from '@/components/Breadcrumbs'
99
import FeedbackForm from '@/components/FeedbackForm'
10+
import { Code } from '@/components/mdx'
1011

1112
export default function DocLayout({
1213
children,
@@ -22,10 +23,21 @@ export default function DocLayout({
2223
return <>{children}</>
2324
}
2425

26+
const startSteps = doc.start_steps && (
27+
<Code
28+
hideBashPanel
29+
codeblock={{
30+
lang: 'bash',
31+
meta: '',
32+
value: doc.start_steps?.raw,
33+
}}
34+
/>
35+
)
36+
2537
return (
2638
<article className="mx-auto flex h-full max-w-7xl flex-col gap-y-10 px-4 pb-10 pt-16">
2739
<div className="relative grid grid-cols-1 gap-10 md:grid-cols-12">
28-
<div className="w-full flex-auto space-y-20 md:col-span-9">
40+
<div className="col-span-8 w-full flex-auto space-y-20 xl:col-span-9">
2941
<div>
3042
<Breadcrumbs doc={doc} className="mb-4" />
3143
<Prose>{children}</Prose>
@@ -55,7 +67,7 @@ export default function DocLayout({
5567
})}
5668
</div>
5769
</div>
58-
<DocToc doc={doc} />
70+
<DocToc doc={doc} startSteps={startSteps} />
5971
</div>
6072
</article>
6173
)

src/components/code/Code.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import { highlight } from './highlight'
66

77
export async function Code({
88
codeblock,
9+
hideBashPanel,
910
}: {
1011
codeblock: RawCode
1112
isPanel?: boolean
13+
hideBashPanel?: boolean
1214
}) {
1315
const highlighted = await highlight(codeblock)
1416

@@ -18,7 +20,11 @@ export async function Code({
1820

1921
return (
2022
<CodeContainer>
21-
<Pre highlighted={highlighted} showPanel={isPanel} />
23+
<Pre
24+
highlighted={highlighted}
25+
showPanel={isPanel}
26+
hideBashPanel={hideBashPanel}
27+
/>
2228
</CodeContainer>
2329
)
2430
}

src/components/code/Pre.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ type Props = {
2020
highlighted: HighlightedCode
2121
showPanel?: boolean
2222
className?: string
23+
hideBashPanel?: boolean
2324
} & HandlerProps
2425

2526
const Pre: React.FC<Props> = ({
2627
highlighted,
2728
showPanel,
29+
hideBashPanel,
2830
enableTransitions,
2931
className,
3032
}) => {
@@ -40,7 +42,7 @@ const Pre: React.FC<Props> = ({
4042

4143
const showFileNamePanel = showPanel && !!title
4244

43-
const isBash = highlighted.lang === 'shellscript'
45+
const isBash = highlighted.lang === 'shellscript' && !hideBashPanel
4446

4547
return (
4648
<>

src/components/layout/DocToC.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client'
22

33
import type { Doc } from '@/content'
4-
import { useRef, useLayoutEffect, useState, useEffect } from 'react'
4+
import { useState, useEffect } from 'react'
55
import Link from 'next/link'
66
import { DocTracingBeam } from './DocTracingBeam'
77
import { Button } from '../ui/button'
@@ -15,7 +15,13 @@ interface Toc {
1515
depth: number
1616
}
1717

18-
const DocToC = ({ doc }: { doc: Doc }) => {
18+
const DocToC = ({
19+
doc,
20+
startSteps,
21+
}: {
22+
doc: Doc
23+
startSteps?: React.JSX.Element | undefined
24+
}) => {
1925
const initial = 14
2026
const sectionSize = 28
2127
const offset = 10
@@ -58,8 +64,8 @@ const DocToC = ({ doc }: { doc: Doc }) => {
5864
}, [])
5965

6066
return (
61-
<div className="hidden h-full min-w-52 md:block">
62-
<aside className="sticky top-[calc(var(--header-height)+1px+2rem)] max-h-[calc(100vh-var(--header-height)-3rem)] min-w-40 space-y-6">
67+
<div className="hidden h-full min-w-64 md:block">
68+
<aside className="sticky top-[calc(var(--header-height)+1px+2rem)] max-h-[calc(100vh-var(--header-height)-3rem)] space-y-8">
6369
{doc.toc.length ? (
6470
<div className="relative flex flex-col">
6571
<p className="mb-2 font-mono text-sm uppercase dark:text-zinc-300">
@@ -101,6 +107,17 @@ const DocToC = ({ doc }: { doc: Doc }) => {
101107
</a>
102108
</Button>
103109
</div>
110+
{startSteps && (
111+
<div className="flex flex-col">
112+
<p className="mb-2 font-mono text-sm uppercase dark:text-zinc-300">
113+
Try this out
114+
</p>
115+
<p className="mb-2 text-2xs text-muted-foreground">
116+
Run these commands in your terminal.
117+
</p>
118+
{startSteps}
119+
</div>
120+
)}
104121
</aside>
105122
</div>
106123
)

0 commit comments

Comments
 (0)