|
|
@ -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: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|