Skip to content

Commit

Permalink
Use nested headings in docs website
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkb committed Feb 1, 2023
1 parent 317f930 commit 50c8fbe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/iles.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default defineConfig({
jsx: 'preact',
debug: false,
modules: [
headings(),
headings({ isNested: true }),
icons(),
prism(),
lastUpdated(),
Expand Down
24 changes: 2 additions & 22 deletions docs/src/components/TableOfContents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,12 @@
import type { Heading } from '@islands/headings'
import type { SideBarItem } from '~/logic/config'
interface HeadingWithChildren extends Heading {
children?: Heading[]
}
let { meta, frontmatter } = usePage()
let level = $computed(() => frontmatter.tocLevel || (frontmatter.sidebar === 'auto' ? 3 : 2))
let headings = $computed(() => resolveHeaders(meta.headings || []))
function resolveHeaders (headings: Heading[]): SideBarItem[] {
return mapHeaders(groupHeaders(headings))
}
function groupHeaders (headings: Heading[]): HeadingWithChildren[] {
headings = headings.map(h => Object.assign({}, h))
let lastHeading: HeadingWithChildren
headings.forEach((h) => {
if (h.level === level)
lastHeading = h
else if (lastHeading)
(lastHeading.children || (lastHeading.children = [])).push(h)
})
return headings.filter(h => h.level === level)
}
let headings = $computed(() => mapHeaders((meta.headings || [])[0].children))
function mapHeaders (headings: HeadingWithChildren[]): SideBarItem[] {
function mapHeaders (headings: Heading[]): SideBarItem[] {
return headings.map(Heading => ({
text: Heading.title,
link: `#${Heading.slug}`,
Expand Down

0 comments on commit 50c8fbe

Please sign in to comment.