Skip to content

Commit ad988d4

Browse files
committed
fix: doc links
1 parent bf63585 commit ad988d4

3 files changed

Lines changed: 41 additions & 26 deletions

File tree

apps/documentation-website/src/components/Hero.tsx

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,31 @@ import blurIndigoImage from '@/images/blur-indigo.png'
1010

1111
const codeLanguage = 'typescript'
1212

13-
const code = `// One-off wrapping — zero config
14-
const safeJSONParse = safe.wrap(JSON.parse)
15-
const [parsed, parseErr] = safeJSONParse(rawInput)
13+
const code = `// Wrap any function — zero config
14+
const safeParse = safe.wrap(JSON.parse)
15+
const [data, err] = safeParse(rawInput)
1616
17-
const fetchUserOnce = safe.wrapAsync(fetchUserAsync)
18-
const [basicUser, basicError] = await fetchUserOnce('admin-456')
19-
20-
// Configurable safety — from one function to many
17+
// Shared config for a whole domain
2118
const apiSafe = createSafe({
2219
parseError: errorParser,
23-
parseResult: resultParser,
20+
defaultError: fallbackError,
2421
onError: errorHook,
25-
onSuccess: successHook,
26-
onSettled: settledHook,
2722
})
2823
2924
const fetchUser = apiSafe.wrapAsync(fetchUserAsync)
3025
const fetchPosts = apiSafe.wrapAsync(fetchPostsAsync)
3126
32-
// Same shared config. Full type narrowing.
33-
const [user, userError] = await fetchUser('123')
34-
if (userError) return
35-
36-
const [posts, postsError] = await fetchPosts(user.id)
37-
if (postsError) return
27+
// Same config. Full type narrowing.
28+
const [user, userErr] = await fetchUser('123')
29+
if (userErr) return
3830
39-
console.log(user.name)
40-
console.log(posts.length)
41-
42-
// Add resilience — retry with backoff + auto-cancel
43-
const fetchUserRetry = apiSafe.wrapAsync(fetchUserAsync, {
44-
retry: { times: 3, waitBefore: (n) => n * 1000 },
45-
abortAfter: 5000,
46-
onRetry: (err, attempt) => console.log(\`Retry #\${attempt}...\`),
47-
})
31+
const [posts, postsErr] = await fetchPosts(user.id)
32+
console.log(user.name, posts.length)
4833
4934
// Prefer objects? One call to switch.
5035
const objSafe = withObjects(apiSafe)
5136
const fetchPostsObj = objSafe.wrapAsync(fetchPostsAsync)
52-
const { ok, data, error } = await fetchPostsObj('123')
37+
const { ok, data: posts2, error } = await fetchPostsObj('123')
5338
`
5439

5540
// const code = `import { safe } from '@cometloop/safe'
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Link from 'next/link'
2+
3+
export function MarkdocLink({
4+
href,
5+
title,
6+
children,
7+
}: {
8+
href: string
9+
title?: string
10+
children: React.ReactNode
11+
}) {
12+
if (href.startsWith('/') || href.startsWith('#')) {
13+
return (
14+
<Link href={href} title={title}>
15+
{children}
16+
</Link>
17+
)
18+
}
19+
20+
return (
21+
<a href={href} title={title}>
22+
{children}
23+
</a>
24+
)
25+
}

apps/documentation-website/src/markdoc/nodes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import yaml from 'js-yaml'
44

55
import { DocsLayout } from '@/components/DocsLayout'
66
import { Fence } from '@/components/Fence'
7+
import { MarkdocLink } from '@/components/MarkdocLink'
78

89
let documentSlugifyMap = new Map()
910

@@ -50,6 +51,10 @@ const nodes = {
5051
},
5152
},
5253
},
54+
link: {
55+
...defaultNodes.link,
56+
render: MarkdocLink,
57+
},
5358
fence: {
5459
render: Fence,
5560
attributes: {

0 commit comments

Comments
 (0)