|
|
@ -15,7 +15,6 @@ import { usePrefetch } from './composables/preFetch'
|
|
|
|
import { dataSymbol, initData } from './data'
|
|
|
|
import { dataSymbol, initData } from './data'
|
|
|
|
import { Content } from './components/Content'
|
|
|
|
import { Content } from './components/Content'
|
|
|
|
import { ClientOnly } from './components/ClientOnly'
|
|
|
|
import { ClientOnly } from './components/ClientOnly'
|
|
|
|
import { PageDataPayload } from '../shared'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const NotFound = Theme.NotFound || (() => '404 Not Found')
|
|
|
|
const NotFound = Theme.NotFound || (() => '404 Not Found')
|
|
|
|
|
|
|
|
|
|
|
@ -46,8 +45,6 @@ const VitePressApp = {
|
|
|
|
export function createApp() {
|
|
|
|
export function createApp() {
|
|
|
|
const router = newRouter()
|
|
|
|
const router = newRouter()
|
|
|
|
|
|
|
|
|
|
|
|
handleHMR(router)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const app = newApp()
|
|
|
|
const app = newApp()
|
|
|
|
|
|
|
|
|
|
|
|
app.provide(RouterSymbol, router)
|
|
|
|
app.provide(RouterSymbol, router)
|
|
|
@ -116,25 +113,6 @@ function newRouter(): Router {
|
|
|
|
}, NotFound)
|
|
|
|
}, NotFound)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function handleHMR(router: Router): void {
|
|
|
|
|
|
|
|
// update route.data on HMR updates of active page
|
|
|
|
|
|
|
|
if (import.meta.hot) {
|
|
|
|
|
|
|
|
// hot reload pageData
|
|
|
|
|
|
|
|
import.meta.hot!.on('vitepress:pageData', (payload: PageDataPayload) => {
|
|
|
|
|
|
|
|
if (shouldHotReload(payload)) {
|
|
|
|
|
|
|
|
router.route.data = payload.pageData
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function shouldHotReload(payload: PageDataPayload): boolean {
|
|
|
|
|
|
|
|
const payloadPath = payload.path.replace(/(\bindex)?\.md$/, '')
|
|
|
|
|
|
|
|
const locationPath = location.pathname.replace(/(\bindex)?\.html$/, '')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return payloadPath === locationPath
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (inBrowser) {
|
|
|
|
if (inBrowser) {
|
|
|
|
const { app, router, data } = createApp()
|
|
|
|
const { app, router, data } = createApp()
|
|
|
|
|
|
|
|
|
|
|
|