|
1 | 1 | import { useThrottleFn } from '@vueuse/core' |
2 | | -import { getScrollOffset } from 'vitepress' |
3 | | -import { onMounted, onUnmounted, onUpdated, ref } from 'vue' |
| 2 | +import { getScrollOffset, useData } from 'vitepress' |
| 3 | +import { computed, onMounted, onUnmounted, onUpdated, ref } from 'vue' |
| 4 | +import type { NimiqVitepressThemeConfig } from '../types' |
4 | 5 |
|
5 | 6 | export interface HeadingItem { |
6 | 7 | hashPath: string |
@@ -41,7 +42,7 @@ function getAbsoluteTop(element: HTMLElement): number { |
41 | 42 | return offsetTop |
42 | 43 | } |
43 | 44 |
|
44 | | -export function useOutline() { |
| 45 | +export function useSecondarySidebar() { |
45 | 46 | const headingTree = ref<HeadingTree[]>([]) |
46 | 47 | const activeHeadingIds = ref<string[]>([]) |
47 | 48 |
|
@@ -133,7 +134,33 @@ export function useOutline() { |
133 | 134 | window.removeEventListener('scroll', onScroll) |
134 | 135 | }) |
135 | 136 |
|
| 137 | + const { frontmatter } = useData<NimiqVitepressThemeConfig>() |
| 138 | + const showOutline = computed(() => { |
| 139 | + // Explicit setting in frontmatter takes precedence |
| 140 | + if (frontmatter.value.outline !== undefined) |
| 141 | + return !!frontmatter.value.outline |
| 142 | + // Default: show if there are headings |
| 143 | + return headingTree.value.length > 0 |
| 144 | + }) |
| 145 | + |
| 146 | + const showWidget = computed(() => frontmatter.value.widget !== false) |
| 147 | + |
| 148 | + const showSecondarySidebar = computed(() => { |
| 149 | + const { secondarySidebar } = frontmatter.value |
| 150 | + |
| 151 | + // Explicit setting in frontmatter takes precedence |
| 152 | + if (secondarySidebar !== undefined) |
| 153 | + return !!secondarySidebar |
| 154 | + // Default: show if there are headings |
| 155 | + return showOutline.value || showWidget.value |
| 156 | + }) |
| 157 | + |
| 158 | + |
| 159 | + |
136 | 160 | return { |
| 161 | + showSecondarySidebar, |
| 162 | + showOutline, |
| 163 | + showWidget, |
137 | 164 | headingTree, |
138 | 165 | activeHeadingIds, |
139 | 166 | isHeadingActive: (hashPath: string) => activeHeadingIds.value.includes(hashPath), |
|
0 commit comments