chore: small improves

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

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

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

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

@ -1,7 +1,16 @@
import { SiteData } from '../../types/shared' import { SiteData } from '../../types/shared'
function findMatchRoot(route: string, roots: string[]) { 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) { for (const r of roots) {
if (route.startsWith(r)) return r if (route.startsWith(r)) return r
} }
@ -16,6 +25,7 @@ function resolveLocales<T>(
return localeRoot ? locales[localeRoot] : undefined return localeRoot ? locales[localeRoot] : undefined
} }
// this merges the locales data to the main data by the route
export function resolveSiteDataByRoute(siteData: SiteData, route: string) { export function resolveSiteDataByRoute(siteData: SiteData, route: string) {
const localeData = resolveLocales(siteData.locales || {}, route) || {} const localeData = resolveLocales(siteData.locales || {}, route) || {}
const localeThemeConfig = const localeThemeConfig =
@ -29,7 +39,10 @@ export function resolveSiteDataByRoute(siteData: SiteData, route: string) {
...localeData, ...localeData,
themeConfig: { themeConfig: {
...siteData.themeConfig, ...siteData.themeConfig,
...localeThemeConfig ...localeThemeConfig,
} // clean the locales to reduce the bundle size
locales: {}
},
locales: {}
} }
} }

Loading…
Cancel
Save