mirror of https://github.com/vuejs/vitepress
parent
9d6b8cadcc
commit
776d8014a2
@ -1,8 +1,11 @@
|
|||||||
import { computed } from 'vue'
|
import { Ref, computed } from 'vue'
|
||||||
import { useRoute } from '../router'
|
import { PageData } from '/@types/shared'
|
||||||
|
import { Route, useRoute } from '../router'
|
||||||
|
|
||||||
export function usePageData() {
|
export type PageDataRef = Ref<PageData>
|
||||||
const route = useRoute()
|
|
||||||
|
|
||||||
return computed(() => route.data)
|
export function usePageData(route?: Route) {
|
||||||
|
const r = route || useRoute()
|
||||||
|
|
||||||
|
return computed(() => r.data)
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { resolveSiteDataByRoute } from '/@shared/config'
|
import { resolveSiteDataByRoute } from '/@shared/config'
|
||||||
import { siteDataRef } from './siteData'
|
import { siteDataRef } from './siteData'
|
||||||
import { useRoute } from '../router'
|
import { Route, useRoute } from '../router'
|
||||||
|
|
||||||
|
export function useSiteDataByRoute(route?: Route) {
|
||||||
|
const r = route || useRoute()
|
||||||
|
|
||||||
export function useSiteDataByRoute(route = useRoute()) {
|
|
||||||
return computed(() => {
|
return computed(() => {
|
||||||
return resolveSiteDataByRoute(siteDataRef.value, route.path)
|
return resolveSiteDataByRoute(siteDataRef.value, r.path)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
import { App } from 'vue'
|
||||||
|
import { SiteDataRef } from './composables/siteData'
|
||||||
|
import { PageDataRef } from './composables/PageData'
|
||||||
|
import { Content } from './components/Content'
|
||||||
|
import Debug from './components/Debug.vue'
|
||||||
|
|
||||||
|
export function mixinGlobalComputed(
|
||||||
|
app: App,
|
||||||
|
site: SiteDataRef,
|
||||||
|
siteByRoute: SiteDataRef,
|
||||||
|
page: PageDataRef
|
||||||
|
): void {
|
||||||
|
Object.defineProperties(app.config.globalProperties, {
|
||||||
|
$site: {
|
||||||
|
get() {
|
||||||
|
return site.value
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
$siteByRoute: {
|
||||||
|
get() {
|
||||||
|
return siteByRoute.value
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
$themeConfig: {
|
||||||
|
get() {
|
||||||
|
return siteByRoute.value.themeConfig
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
$page: {
|
||||||
|
get() {
|
||||||
|
return page
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
$frontmatter: {
|
||||||
|
get() {
|
||||||
|
return page.value.frontmatter
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
$title: {
|
||||||
|
get() {
|
||||||
|
return page.value.title || siteByRoute.value.title
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
$description: {
|
||||||
|
get() {
|
||||||
|
return page.value.description || siteByRoute.value.description
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function mixinGlobalComponents(app: App) {
|
||||||
|
const isProd = process.env.NODE_ENV === 'production'
|
||||||
|
|
||||||
|
app.component('Content', Content)
|
||||||
|
|
||||||
|
app.component('Debug', isProd ? () => null : Debug)
|
||||||
|
}
|
Loading…
Reference in new issue