Skip to content

Commit b764324

Browse files
committed
Update codehike v1.0.0-beta.8
1 parent aedbe40 commit b764324

File tree

7 files changed

+104
-71
lines changed

7 files changed

+104
-71
lines changed

clone-shopify-api-reference/app/order/api-layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function EndpointsNav({ endpoints }: { endpoints: EndpointBlock[] }) {
5858
{endpoints.map((endpoint) => (
5959
<a
6060
key={endpoint.title}
61-
href={`#${endpoint.title.replace(/\s/g, "-")}`}
61+
href={`#${endpoint.title?.replace(/\s/g, "-")}`}
6262
className={`flex gap-3 no-underline items-start mb-1 p-2 rounded-lg`}
6363
>
6464
<Method value={endpoint.method} className="mt-0.5" />
@@ -190,7 +190,7 @@ function Endpoint({
190190
<div className="flex gap-8 flex-wrap">
191191
<div className="min-w-96 flex-1 prose-hr:my-2">
192192
<h2
193-
id={title.replace(/\s/g, "-")}
193+
id={title?.replace(/\s/g, "-")}
194194
className="flex items-center gap-3 mt-0 scroll-mt-12"
195195
>
196196
<Method value={method} />
@@ -208,7 +208,7 @@ function Endpoint({
208208
<hr />
209209
<Accordion type="single" collapsible className="w-full">
210210
{examples.map((example) => (
211-
<AccordionItem key={example.title} value={example.title}>
211+
<AccordionItem key={example.title} value={example.title!}>
212212
<AccordionTrigger className="text-base text-[#81aec4] hover:text-[#bedbeb] data-[state=open]:text-[#bedbeb]">
213213
{example.title}
214214
</AccordionTrigger>

clone-shopify-api-reference/app/order/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// @ts-ignore
2-
import { getBlocks } from "@/content/order.md"
2+
import MDX from "@/content/order.md"
33
import { parseContent } from "./schema"
44
import Link from "next/link"
55
import { Layout } from "./api-layout"
66

7-
const content = parseContent(getBlocks())
7+
const content = parseContent(MDX)
88

99
export const metadata = {
1010
title: content.intro.title,

clone-shopify-api-reference/app/order/schema.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
import { z } from "zod"
2-
import { Block, Code, parse } from "codehike/schema"
2+
import { Block, CodeBlock, parseRoot } from "codehike/blocks"
33

44
export type Content = ReturnType<typeof parseContent>
55

6-
// `content` is the object Code Hike generates from the markdown file
7-
export function parseContent(content: unknown) {
6+
export function parseContent(content: any) {
87
// if there's an error, `parse` will throw with a message specifying the section in the markdown file that caused the error
9-
return parse(
8+
return parseRoot(
109
content,
1110
Block.extend({
1211
intro: Block,
1312
resource: Block.extend({
14-
code: Code,
13+
code: CodeBlock,
1514
properties: z.array(Property),
1615
hidden: z.optional(z.array(Property)),
1716
}),
1817
endpoints: z.array(
1918
Block.extend({
2019
method: z.enum(["GET", "POST", "PUT", "DEL"]),
2120
path: z.string(),
22-
request: z.array(Code),
23-
response: Code,
21+
request: z.array(CodeBlock),
22+
response: CodeBlock,
2423
parameters: z.optional(z.array(Property)),
2524
examples: z.optional(z.array(Example)),
2625
}),
@@ -40,7 +39,7 @@ const Property = Block.extend({
4039

4140
const Example = Block.extend({
4241
path: z.optional(z.string()),
43-
pathParams: z.optional(Code),
44-
queryParams: z.optional(Code),
45-
requestBody: z.optional(Code),
42+
pathParams: z.optional(CodeBlock),
43+
queryParams: z.optional(CodeBlock),
44+
requestBody: z.optional(CodeBlock),
4645
})

clone-shopify-api-reference/components/code.tsx

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { CodeBlock, CodeContent } from "codehike"
21
import { CopyButton } from "./copy-button"
32
import {
43
LocalStoredTabs,
@@ -8,32 +7,42 @@ import {
87
TabsTrigger,
98
} from "./ui/tabs"
109
import { Method, Path } from "./ui/endpoint"
10+
import {
11+
AnnotationHandler,
12+
highlight,
13+
InnerLine,
14+
Pre,
15+
RawCode,
16+
} from "codehike/code"
1117

12-
export function ResourceCode({ codeblock }: { codeblock: CodeBlock }) {
18+
export async function ResourceCode({ codeblock }: { codeblock: RawCode }) {
19+
const highlighted = await highlight(codeblock, "dark-plus")
1320
return (
1421
<div className="border border-[#1e647a] min-w-0 flex-1 rounded-lg lg:max-w-lg lg:ml-auto overflow-hidden bg-[#184C5E]">
1522
<div className="font-mono px-4 py-1 text-[#8fbfd7] bg-[#133A48] m-0.5 rounded-lg">
1623
{"{} " + codeblock.meta}
1724
</div>
18-
<CodeContent
19-
codeblock={codeblock}
20-
config={{ theme: "dark-plus" }}
25+
<Pre
26+
code={highlighted}
2127
className="min-h-[40rem] max-h-[600px] m-0 px-0 whitespace-pre-wrap"
22-
components={{ Line }}
28+
handlers={[line]}
2329
/>
2430
</div>
2531
)
2632
}
2733

28-
export function RequestCode({
34+
export async function RequestCode({
2935
codeblocks,
3036
path,
3137
method,
3238
}: {
33-
codeblocks: CodeBlock[]
39+
codeblocks: RawCode[]
3440
method: "GET" | "POST" | "PUT" | "DEL"
3541
path: string
3642
}) {
43+
const highlighted = await Promise.all(
44+
codeblocks.map((codeblock) => highlight(codeblock, "dark-plus")),
45+
)
3746
return (
3847
<LocalStoredTabs
3948
localStorageKey="preferredLanguage"
@@ -63,21 +72,21 @@ export function RequestCode({
6372
))}
6473
</div>
6574
</div>
66-
{codeblocks.map((codeblock) => (
75+
{highlighted.map((codeblock) => (
6776
<TabsContent value={codeblock.meta!}>
68-
<CodeContent
69-
codeblock={codeblock}
70-
config={{ theme: "dark-plus" }}
77+
<Pre
78+
code={codeblock}
7179
className="max-h-[600px] m-0 px-0 whitespace-pre-wrap break-all"
72-
components={{ Line }}
80+
handlers={[line]}
7381
/>
7482
</TabsContent>
7583
))}
7684
</LocalStoredTabs>
7785
)
7886
}
7987

80-
export function ResponseCode({ codeblock }: { codeblock: CodeBlock }) {
88+
export async function ResponseCode({ codeblock }: { codeblock: RawCode }) {
89+
const highlighted = await highlight(codeblock, "dark-plus")
8190
return (
8291
<div className="border border-cyan-950 min-w-0 flex-1 rounded-lg lg:max-w-lg lg:ml-auto overflow-hidden bg-[#0A1D26]">
8392
<div className="font-mono px-4 py-1 text-[#8fbfd7] bg-[#061219] m-0.5 rounded-lg flex gap-3 items-center">
@@ -88,24 +97,23 @@ export function ResponseCode({ codeblock }: { codeblock: CodeBlock }) {
8897
</span>
8998
</div>
9099

91-
<CodeContent
92-
codeblock={codeblock}
93-
config={{ theme: "dark-plus" }}
100+
<Pre
101+
code={highlighted}
94102
className="max-h-[600px] m-0 px-0 whitespace-pre-wrap"
95-
components={{ Line }}
103+
handlers={[line]}
96104
/>
97105
</div>
98106
)
99107
}
100108

101-
// TODO better word-wrap
102-
function Line({ children, query }: any) {
103-
return (
109+
const line: AnnotationHandler = {
110+
name: "line",
111+
Line: (props) => (
104112
<div data-line="true" className="table-row px-1">
105113
<div className="pl-1 pr-4 w-[3ch] box-content !opacity-50 text-right select-none table-cell">
106-
{query}
114+
{props.lineNumber}
107115
</div>
108-
<div className="table-cell break-words">{children}</div>
116+
<InnerLine merge={props} />
109117
</div>
110-
)
118+
),
111119
}

clone-shopify-api-reference/license

Lines changed: 0 additions & 21 deletions
This file was deleted.

clone-shopify-api-reference/package-lock.json

Lines changed: 57 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clone-shopify-api-reference/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@radix-ui/react-tabs": "^1.0.4",
1717
"class-variance-authority": "^0.7.0",
1818
"clsx": "^2.1.0",
19-
"codehike": "^1.0.0-alpha.12",
19+
"codehike": "1.0.0-beta.8",
2020
"lucide-react": "^0.338.0",
2121
"next": "14.1.0",
2222
"react": "^18",

0 commit comments

Comments
 (0)