Skip to content

Commit d32b02f

Browse files
committed
feat(docs): Index page doc section links
1 parent 9e1c23f commit d32b02f

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

docs/src/pages/index.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import React from 'react'
22

33
import Head from '@docusaurus/Head'
4+
import Link from '@docusaurus/Link'
45
import Layout from '@theme/Layout'
56

7+
import sidebars from '../../sidebars'
8+
69
export default function Home() {
10+
console.log('main sidebar', sidebars.main)
11+
712
return (
813
<Layout
914
description={
@@ -95,8 +100,32 @@ export default function Home() {
95100

96101
<h1>Documentation</h1>
97102

98-
<a href="https://cedarjs.com/docs">https://cedarjs.com/docs</a>
103+
<ul>
104+
{sidebars.main.map((section: string | Record<string, any>) => {
105+
const linkText =
106+
typeof section === 'string' ? toTitleCase(section) : section.label
107+
const linkTarget =
108+
typeof section === 'string'
109+
? section
110+
: section.link?.slug?.replace(/^\//, '') ||
111+
section.items?.at(0)?.id
112+
113+
return (
114+
<li key={linkTarget}>
115+
<Link to={'docs/' + linkTarget}>{linkText}</Link>
116+
</li>
117+
)
118+
})}
119+
</ul>
99120
</div>
100121
</Layout>
101122
)
102123
}
124+
125+
function toTitleCase(str: string) {
126+
return str
127+
.replaceAll('-', ' ')
128+
.split(' ')
129+
.map((w) => w[0].toUpperCase() + w.substring(1))
130+
.join(' ')
131+
}

0 commit comments

Comments
 (0)