chore: small improves

pull/50/head
Anthony Fu 5 years ago committed by Evan You
parent 6eb5f12fc3
commit 23d3398617

@ -1,8 +1,9 @@
<template>
<div class="debug" :class="{ open }" @click="open = !open">
<pre>debug</pre>
<pre>$site {{ $site }}</pre>
<pre>$page {{ $page }}</pre>
<pre>$siteByRoute {{ $siteByRoute }}</pre>
<pre>$site {{ $site }}</pre>
</div>
</template>
@ -27,8 +28,8 @@ export default {
cursor: pointer;
bottom: 0;
right: 0;
width: 50px;
height: 20px;
width: 80px;
height: 30px;
padding: 5px;
overflow: hidden;
color: #eeeeee;
@ -40,7 +41,7 @@ export default {
width: 500px;
height: 100%;
margin-top: 0;
padding: 5px 20px;
padding: 0 0;
overflow: scroll;
}
@ -48,5 +49,7 @@ export default {
font-family: Hack, monospace;
font-size: 13px;
margin: 0;
padding: 5px 10px;
border-bottom: 1px solid #eee;
}
</style>

@ -7,6 +7,7 @@ import Debug from './components/Debug.vue'
import Theme from '/@theme/index'
import { inBrowser, pathToFile } from './utils'
import { useSiteDataByRoute } from './composables/siteDataByRoute'
import { siteDataRef } from './composables/siteData'
const NotFound = Theme.NotFound || (() => '404 Not Found')
@ -84,6 +85,11 @@ export function createApp() {
Object.defineProperties(app.config.globalProperties, {
$site: {
get() {
return siteDataRef.value
}
},
$siteByRoute: {
get() {
return siteDataByRouteRef.value
}

@ -16,5 +16,8 @@
"include": [
".",
"../../types/shared.d.ts",
],
"exclude": [
"../shared"
]
}

@ -1,7 +1,16 @@
import { SiteData } from '../../types/shared'
function findMatchRoot(route: string, roots: string[]) {
roots.sort((a, b) => b.length - a.length)
// first match to the routes with the most deep level.
roots.sort((a, b) => {
const levelDelta = b.split('/').length - a.split('/').length
if (levelDelta !== 0) {
return levelDelta
} else {
return b.length - a.length
}
})
for (const r of roots) {
if (route.startsWith(r)) return r
}
@ -16,6 +25,7 @@ function resolveLocales<T>(
return localeRoot ? locales[localeRoot] : undefined
}
// this merges the locales data to the main data by the route
export function resolveSiteDataByRoute(siteData: SiteData, route: string) {
const localeData = resolveLocales(siteData.locales || {}, route) || {}
const localeThemeConfig =
@ -29,7 +39,10 @@ export function resolveSiteDataByRoute(siteData: SiteData, route: string) {
...localeData,
themeConfig: {
...siteData.themeConfig,
...localeThemeConfig
}
...localeThemeConfig,
// clean the locales to reduce the bundle size
locales: {}
},
locales: {}
}
}

Loading…
Cancel
Save