Merge remote-tracking branch 'upstream/main' into feat/client-only-sidabar-and-nav

pull/4663/head
Yuxuan Zhang 5 months ago
parent 46d8ccc29b
commit 289cbe615e
No known key found for this signature in database
GPG Key ID: 6910B04F3351EF7D

@ -1,2 +1,16 @@
#!/usr/bin/env node
// @ts-check
import module from 'node:module'
// https://github.com/vitejs/vite/blob/6c8a5a27e645a182f5b03a4ed6aa726eab85993f/packages/vite/bin/vite.js#L48-L63
try {
module.enableCompileCache?.()
setTimeout(() => {
try {
module.flushCompileCache?.()
} catch {}
}, 10 * 1000).unref()
} catch {}
import('../dist/node/cli.js')

@ -4,6 +4,7 @@ import {
groupIconVitePlugin,
localIconLoader
} from 'vitepress-plugin-group-icons'
import llmstxt from 'vitepress-plugin-llms'
import { search as esSearch } from './es'
import { search as faSearch } from './fa'
import { search as koSearch } from './ko'
@ -121,6 +122,10 @@ export const shared = defineConfig({
),
firebase: 'logos:firebase'
}
}),
llmstxt({
workDir: 'en',
ignoreFiles: ['index.md']
})
]
}

@ -466,7 +466,7 @@ Returns layout-related data. The returned object has the following type:
interface {
isHome: ComputedRef<boolean>
sidebar: ComputedRef<DefaultTheme.SidebarItem[]>
sidebar: Readonly<ShallowRef<DefaultTheme.SidebarItem[]>>
sidebarGroups: ComputedRef<DefaultTheme.SidebarItem[]>
hasSidebar: ComputedRef<boolean>
isSidebarEnabled: ComputedRef<boolean>
@ -474,7 +474,7 @@ interface {
hasAside: ComputedRef<boolean>
leftAside: ComputedRef<boolean>
headers: ShallowRef<DefaultTheme.OutlineItem[]>
headers: Readonly<ShallowRef<DefaultTheme.OutlineItem[]>>
hasLocalNav: ComputedRef<boolean>
}
```

@ -13,8 +13,9 @@
"@lunariajs/core": "^0.1.1",
"markdown-it-mathjax3": "^4.3.2",
"open-cli": "^8.0.0",
"postcss-rtlcss": "^5.6.0",
"postcss-rtlcss": "^5.7.0",
"vitepress": "workspace:*",
"vitepress-plugin-group-icons": "^1.3.8"
"vitepress-plugin-group-icons": "^1.4.1",
"vitepress-plugin-llms": "^1.1.0"
}
}

@ -97,33 +97,33 @@
"dependencies": {
"@docsearch/css": "^3.9.0",
"@docsearch/js": "^3.9.0",
"@iconify-json/simple-icons": "^1.2.30",
"@shikijs/core": "^3.2.1",
"@shikijs/transformers": "^3.2.1",
"@shikijs/types": "^3.2.1",
"@iconify-json/simple-icons": "^1.2.31",
"@shikijs/core": "^3.2.2",
"@shikijs/transformers": "^3.2.2",
"@shikijs/types": "^3.2.2",
"@vitejs/plugin-vue": "^5.2.3",
"@vue/devtools-api": "^7.7.2",
"@vue/shared": "^3.5.13",
"@vueuse/core": "^13.0.0",
"@vueuse/integrations": "^13.0.0",
"@vueuse/core": "^13.1.0",
"@vueuse/integrations": "^13.1.0",
"focus-trap": "^7.6.4",
"living-object": "0.0.3",
"mark.js": "8.11.1",
"minisearch": "^7.1.2",
"shiki": "^3.2.1",
"vite": "^6.2.5",
"shiki": "^3.2.2",
"vite": "^6.2.6",
"vue": "^3.5.13"
},
"devDependencies": {
"@clack/prompts": "^0.10.0",
"@clack/prompts": "^0.10.1",
"@iconify/utils": "^2.3.0",
"@mdit-vue/plugin-component": "^2.1.3",
"@mdit-vue/plugin-frontmatter": "^2.1.3",
"@mdit-vue/plugin-headers": "^2.1.3",
"@mdit-vue/plugin-sfc": "^2.1.3",
"@mdit-vue/plugin-title": "^2.1.3",
"@mdit-vue/plugin-toc": "^2.1.3",
"@mdit-vue/shared": "^2.1.3",
"@mdit-vue/plugin-component": "^2.1.4",
"@mdit-vue/plugin-frontmatter": "^2.1.4",
"@mdit-vue/plugin-headers": "^2.1.4",
"@mdit-vue/plugin-sfc": "^2.1.4",
"@mdit-vue/plugin-title": "^2.1.4",
"@mdit-vue/plugin-toc": "^2.1.4",
"@mdit-vue/shared": "^2.1.4",
"@polka/compression": "^1.0.0-next.28",
"@rollup/plugin-alias": "^5.1.1",
"@rollup/plugin-commonjs": "^28.0.3",

File diff suppressed because it is too large Load Diff

@ -1,7 +1,6 @@
import { useMediaQuery } from '@vueuse/core'
import { onContentUpdated, useRoute } from 'vitepress'
import type { DefaultTheme } from 'vitepress/theme'
import { computed, shallowRef, watch } from 'vue'
import { inBrowser, onContentUpdated, useRoute } from 'vitepress'
import type { DefaultTheme, useLayout as expected } from 'vitepress/theme'
import { computed, shallowReadonly, shallowRef, watch } from 'vue'
import { getSidebar, getSidebarGroups } from '../support/sidebar'
import { useData } from './data'
import { getHeaders } from './outline'
@ -9,21 +8,17 @@ import { useCloseSidebarOnEscape } from './sidebar'
import { isClientOnly } from '../../shared'
const headers = shallowRef<DefaultTheme.OutlineItem[]>([])
const sidebar = shallowRef<DefaultTheme.SidebarItem[]>([])
export function useLayout() {
const { frontmatter, page, theme } = useData()
const is960 = useMediaQuery('(min-width: 960px)')
const is960 = shallowRef(false)
export function useLayout(): ReturnType<typeof expected> {
const { frontmatter, theme } = useData()
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 &&
@ -61,14 +56,14 @@ export function useLayout() {
return {
isHome,
sidebar,
sidebar: shallowReadonly(sidebar),
sidebarGroups,
hasSidebar,
isSidebarEnabled,
isSidebarClientOnly,
hasAside,
leftAside,
headers,
headers: shallowReadonly(headers),
hasLocalNav
}
}
@ -78,12 +73,36 @@ interface RegisterWatchersOptions {
}
export function registerWatchers({ closeSidebar }: RegisterWatchersOptions) {
const { frontmatter, theme } = useData()
const { frontmatter, page, theme } = useData()
watch(
() => [page.value.relativePath, theme.value.sidebar] as const,
([relativePath, sidebarConfig]) => {
const newSidebar = sidebarConfig
? getSidebar(sidebarConfig, relativePath)
: []
if (JSON.stringify(newSidebar) !== JSON.stringify(sidebar.value)) {
sidebar.value = newSidebar
}
},
{ immediate: true, deep: true, flush: 'sync' }
)
onContentUpdated(() => {
headers.value = getHeaders(frontmatter.value.outline ?? theme.value.outline)
})
if (inBrowser) {
is960.value = window.innerWidth >= 960
window.addEventListener(
'resize',
() => {
is960.value = window.innerWidth >= 960
},
{ passive: true }
)
}
const route = useRoute()
watch(() => route.path, closeSidebar)

4
theme.d.ts vendored

@ -16,7 +16,7 @@ export default theme
export declare const useLayout: () => {
isHome: ComputedRef<boolean>
sidebar: ComputedRef<DefaultTheme.SidebarItem[]>
sidebar: Readonly<ShallowRef<DefaultTheme.SidebarItem[]>>
sidebarGroups: ComputedRef<DefaultTheme.SidebarItem[]>
hasSidebar: ComputedRef<boolean>
isSidebarEnabled: ComputedRef<boolean>
@ -27,7 +27,7 @@ export declare const useLayout: () => {
/**
* The outline headers of the current page.
*/
headers: ShallowRef<DefaultTheme.OutlineItem[]>
headers: Readonly<ShallowRef<DefaultTheme.OutlineItem[]>>
/**
* Whether the current page has a local nav. Local nav is shown when the
* "outline" is present in the page. However, note that the actual

Loading…
Cancel
Save