mirror of https://github.com/vuejs/vitepress
commit
d2840dc100
@ -1,8 +1,14 @@
|
||||
export default {
|
||||
async paths() {
|
||||
return [
|
||||
{ params: { id: 'foo' }, content: `# Foo` },
|
||||
{ params: { id: 'bar' }, content: `# Bar` }
|
||||
]
|
||||
}
|
||||
import { defineRoutes } from 'vitepress'
|
||||
import paths from './paths'
|
||||
|
||||
export default defineRoutes({
|
||||
async paths(watchedFiles: string[]) {
|
||||
// console.log('watchedFiles', watchedFiles)
|
||||
return paths
|
||||
},
|
||||
watch: ['**/data-loading/**/*.json'],
|
||||
async transformPageData(pageData) {
|
||||
// console.log('transformPageData', pageData.filePath)
|
||||
pageData.title += ' - transformed'
|
||||
}
|
||||
})
|
||||
|
@ -0,0 +1,4 @@
|
||||
export default [
|
||||
{ params: { id: 'foo' }, content: `# Foo` },
|
||||
{ params: { id: 'bar' }, content: `# Bar` }
|
||||
]
|
@ -0,0 +1,27 @@
|
||||
# header 1
|
||||
|
||||
header 1 content
|
||||
|
||||
## header 1.1
|
||||
|
||||
header 1.1 content
|
||||
|
||||
### header 1.1.1
|
||||
|
||||
header 1.1.1 content
|
||||
|
||||
### header 1.1.2
|
||||
|
||||
header 1.1.2 content
|
||||
|
||||
## header 1.2
|
||||
|
||||
header 1.2 content
|
||||
|
||||
### header 1.2.1
|
||||
|
||||
header 1.2.1 content
|
||||
|
||||
### header 1.2.2
|
||||
|
||||
header 1.2.2 content
|
@ -0,0 +1,72 @@
|
||||
import { ModuleGraph } from 'node/utils/moduleGraph'
|
||||
|
||||
describe('node/utils/moduleGraph', () => {
|
||||
let graph: ModuleGraph
|
||||
|
||||
beforeEach(() => {
|
||||
graph = new ModuleGraph()
|
||||
})
|
||||
|
||||
it('should correctly delete a module and its dependents', () => {
|
||||
graph.add('A', ['B', 'C'])
|
||||
graph.add('B', ['D'])
|
||||
graph.add('C', [])
|
||||
graph.add('D', [])
|
||||
|
||||
expect(graph.delete('D')).toEqual(new Set(['D', 'B', 'A']))
|
||||
})
|
||||
|
||||
it('should handle shared dependencies correctly', () => {
|
||||
graph.add('A', ['B', 'C'])
|
||||
graph.add('B', ['D'])
|
||||
graph.add('C', ['D']) // Shared dependency
|
||||
graph.add('D', [])
|
||||
|
||||
expect(graph.delete('D')).toEqual(new Set(['A', 'B', 'C', 'D']))
|
||||
})
|
||||
|
||||
it('merges dependencies correctly', () => {
|
||||
// Add module A with dependency B
|
||||
graph.add('A', ['B'])
|
||||
// Merge new dependency C into module A (B should remain)
|
||||
graph.add('A', ['C'])
|
||||
|
||||
// Deleting B should remove A as well, since A depends on B.
|
||||
expect(graph.delete('B')).toEqual(new Set(['B', 'A']))
|
||||
})
|
||||
|
||||
it('handles cycles gracefully', () => {
|
||||
// Create a cycle: A -> B, B -> C, C -> A.
|
||||
graph.add('A', ['B'])
|
||||
graph.add('B', ['C'])
|
||||
graph.add('C', ['A'])
|
||||
|
||||
// Deleting any module in the cycle should delete all modules in the cycle.
|
||||
expect(graph.delete('A')).toEqual(new Set(['A', 'B', 'C']))
|
||||
})
|
||||
|
||||
it('cleans up dependencies when deletion', () => {
|
||||
// Setup A -> B relationship.
|
||||
graph.add('A', ['B'])
|
||||
graph.add('B', [])
|
||||
|
||||
// Deleting B should remove both B and A from the graph.
|
||||
expect(graph.delete('B')).toEqual(new Set(['B', 'A']))
|
||||
|
||||
// After deletion, add modules again.
|
||||
graph.add('C', [])
|
||||
graph.add('A', ['C']) // Now A depends only on C.
|
||||
|
||||
expect(graph.delete('C')).toEqual(new Set(['C', 'A']))
|
||||
})
|
||||
|
||||
it('handles independent modules', () => {
|
||||
// Modules with no dependencies.
|
||||
graph.add('X', [])
|
||||
graph.add('Y', [])
|
||||
|
||||
// Deletion of one should only remove that module.
|
||||
expect(graph.delete('X')).toEqual(new Set(['X']))
|
||||
expect(graph.delete('Y')).toEqual(new Set(['Y']))
|
||||
})
|
||||
})
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
@ -0,0 +1 @@
|
||||
../../art/vitepress-logo.svg
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 33 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 33 B |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,85 @@
|
||||
import { useMediaQuery } from '@vueuse/core'
|
||||
import { onContentUpdated, useRoute } from 'vitepress'
|
||||
import type { DefaultTheme } from 'vitepress/theme'
|
||||
import { computed, shallowRef, watch } from 'vue'
|
||||
import { getSidebar, getSidebarGroups } from '../support/sidebar'
|
||||
import { useData } from './data'
|
||||
import { getHeaders } from './outline'
|
||||
import { useCloseSidebarOnEscape } from './sidebar'
|
||||
|
||||
const headers = shallowRef<DefaultTheme.OutlineItem[]>([])
|
||||
|
||||
export function useLayout() {
|
||||
const { frontmatter, page, theme } = useData()
|
||||
const is960 = useMediaQuery('(min-width: 960px)')
|
||||
|
||||
const isHome = computed(() => {
|
||||
return !!(frontmatter.value.isHome ?? frontmatter.value.layout === 'home')
|
||||
})
|
||||
|
||||
const sidebar = computed(() => {
|
||||
const sidebarConfig = theme.value.sidebar
|
||||
const relativePath = page.value.relativePath
|
||||
return sidebarConfig ? getSidebar(sidebarConfig, relativePath) : []
|
||||
})
|
||||
|
||||
const hasSidebar = computed(() => {
|
||||
return (
|
||||
frontmatter.value.sidebar !== false &&
|
||||
sidebar.value.length > 0 &&
|
||||
!isHome.value
|
||||
)
|
||||
})
|
||||
|
||||
const isSidebarEnabled = computed(() => hasSidebar.value && is960.value)
|
||||
|
||||
const sidebarGroups = computed(() => {
|
||||
return hasSidebar.value ? getSidebarGroups(sidebar.value) : []
|
||||
})
|
||||
|
||||
const hasAside = computed(() => {
|
||||
if (isHome.value) return false
|
||||
if (frontmatter.value.aside != null) return !!frontmatter.value.aside
|
||||
return theme.value.aside !== false
|
||||
})
|
||||
|
||||
const leftAside = computed(() => {
|
||||
if (!hasAside.value) return false
|
||||
return frontmatter.value.aside == null
|
||||
? theme.value.aside === 'left'
|
||||
: frontmatter.value.aside === 'left'
|
||||
})
|
||||
|
||||
const hasLocalNav = computed(() => {
|
||||
return headers.value.length > 0
|
||||
})
|
||||
|
||||
return {
|
||||
isHome,
|
||||
sidebar,
|
||||
sidebarGroups,
|
||||
hasSidebar,
|
||||
isSidebarEnabled,
|
||||
hasAside,
|
||||
leftAside,
|
||||
headers,
|
||||
hasLocalNav
|
||||
}
|
||||
}
|
||||
|
||||
interface RegisterWatchersOptions {
|
||||
closeSidebar: () => void
|
||||
}
|
||||
|
||||
export function registerWatchers({ closeSidebar }: RegisterWatchersOptions) {
|
||||
const { frontmatter, theme } = useData()
|
||||
|
||||
onContentUpdated(() => {
|
||||
headers.value = getHeaders(frontmatter.value.outline ?? theme.value.outline)
|
||||
})
|
||||
|
||||
const route = useRoute()
|
||||
watch(() => route.path, closeSidebar)
|
||||
|
||||
useCloseSidebarOnEscape(closeSidebar)
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
import { onContentUpdated } from 'vitepress'
|
||||
import type { DefaultTheme } from 'vitepress/theme'
|
||||
import { computed, shallowRef } from 'vue'
|
||||
import { getHeaders, type MenuItem } from '../composables/outline'
|
||||
import { useData } from './data'
|
||||
|
||||
export function useLocalNav(): DefaultTheme.DocLocalNav {
|
||||
const { theme, frontmatter } = useData()
|
||||
|
||||
const headers = shallowRef<MenuItem[]>([])
|
||||
|
||||
const hasLocalNav = computed(() => {
|
||||
return headers.value.length > 0
|
||||
})
|
||||
|
||||
onContentUpdated(() => {
|
||||
headers.value = getHeaders(frontmatter.value.outline ?? theme.value.outline)
|
||||
})
|
||||
|
||||
return {
|
||||
headers,
|
||||
hasLocalNav
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
.dark .vp-code span {
|
||||
.dark .shiki span {
|
||||
color: var(--shiki-dark, inherit);
|
||||
}
|
||||
|
||||
html:not(.dark) .vp-code span {
|
||||
html:not(.dark) .shiki span {
|
||||
color: var(--shiki-light, inherit);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue