-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
146 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { computed } from 'vue' | ||
import { resolveSiteDataByRoute } from '/@shared/config' | ||
import { siteDataRef } from './siteData' | ||
import { useRoute } from '../router' | ||
|
||
export function useSiteDataByRoute(route = useRoute()) { | ||
return computed(() => { | ||
return resolveSiteDataByRoute(siteDataRef.value, route.path) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/node", | ||
"outDir": "../../dist", | ||
"module": "commonjs", | ||
"lib": ["ESNext", "DOM"], | ||
"sourceMap": true | ||
}, | ||
"include": [".", "../../types/shared.d.ts"] | ||
"include": [".", "../shared", "../../types/shared.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { SiteData } from '../../types/shared' | ||
|
||
function findMatchRoot(route: string, roots: string[]) { | ||
// 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 | ||
} | ||
return undefined | ||
} | ||
|
||
function resolveLocales<T>( | ||
locales: Record<string, T>, | ||
route: string | ||
): T | undefined { | ||
const localeRoot = findMatchRoot(route, Object.keys(locales)) | ||
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 = | ||
resolveLocales<any>( | ||
(siteData.themeConfig && siteData.themeConfig.locales) || {}, | ||
route | ||
) || {} | ||
|
||
return { | ||
...siteData, | ||
...localeData, | ||
themeConfig: { | ||
...siteData.themeConfig, | ||
...localeThemeConfig, | ||
// clean the locales to reduce the bundle size | ||
locales: {} | ||
}, | ||
locales: {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "../../dist/client/shared", | ||
"module": "esnext", | ||
"lib": ["ESNext", "DOM"], | ||
}, | ||
"include": [ | ||
".", | ||
"../../types/shared.d.ts", | ||
] | ||
} |
Oops, something went wrong.