diff options
| author | 2023-04-19 17:50:02 +0800 | |
|---|---|---|
| committer | 2023-04-19 17:50:02 +0800 | |
| commit | 56a6240bf700ac307342ed494d8bfbabe5c822dc (patch) | |
| tree | 0b1288a2ec1cbb538c11f4c122b6a97b9c55a05f /docs/composables/useDocus.ts | |
| parent | 3adc965dd09490b7efa1cce9f09b0a3b30970277 (diff) | |
| download | HydroRoll-56a6240bf700ac307342ed494d8bfbabe5c822dc.tar.gz HydroRoll-56a6240bf700ac307342ed494d8bfbabe5c822dc.zip | |
✨docs init
Diffstat (limited to 'docs/composables/useDocus.ts')
| -rw-r--r-- | docs/composables/useDocus.ts | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/docs/composables/useDocus.ts b/docs/composables/useDocus.ts deleted file mode 100644 index f86c573..0000000 --- a/docs/composables/useDocus.ts +++ /dev/null @@ -1,88 +0,0 @@ -export const useDocus = () => { - const docus = computed(() => useAppConfig()?.docus || {}) - const { navPageFromPath, navDirFromPath, navKeyFromPath } = useContentHelpers() - const { navigation, page } = useContent() - const route = useRoute() - - /** - * Returns fallbacked values for `main`, `header`, `aside` and `footer`. - * - * It allows to configure `app.config` per page/_dir. - */ - const config = computed( - () => { - const titleTemplate = docus?.value?.titleTemplate || navKeyFromPath(page?.value?._path, 'titleTemplate', navigation.value || []) || `%s · ${docus?.value?.title || 'Docus'}` - const main = docus?.value?.main || {} - const header = docus?.value?.header || {} - const aside = docus?.value?.aside || {} - const footer = docus?.value?.footer || {} - - return { - // Raw appConfig - ...docus.value, - - // Merged attributes - titleTemplate, - main: { - ...main, - ...navKeyFromPath(route.path, 'main', navigation.value || []), - ...page.value?.main - } as typeof main, - header: { - ...header, - ...navKeyFromPath(route.path, 'header', navigation.value || []), - ...page.value?.header - } as typeof header, - aside: { - ...aside, - ...navKeyFromPath(route.path, 'aside', navigation.value || []), - ...page.value?.aside - } as typeof aside, - footer: { - ...footer, - ...navKeyFromPath(route.path, 'footer', navigation.value || []), - ...page.value?.footer - } as typeof footer - } - } - ) - - /** - * Current aside tree. - */ - const tree = computed(() => { - let nav = navigation.value || [] - const _path = route.path - const level = config?.value?.aside?.level || 0 - const filtered = config?.value?.aside?.exclude || [] - - if (level) { - // Filter if `aside.level` is enabled in docus configuration - const path = _path.split('/') - - // Get level - const leveledPath = path.splice(0, 1 + level).join('/') - - nav = navDirFromPath(leveledPath, nav) || [] - - if (!Array.isArray(nav)) { nav = [nav] } - } - - // No navigation found; try to resolve page url - if (nav.length === 0) { - nav = navPageFromPath(page.value?._path || '/', navigation.value || []) - - if (!nav) { return [] } - - if (!Array.isArray(nav)) { nav = [nav] } - } - - // Filtered using `aside.exclude` in docus configuration - return nav.filter((item: any) => { - if (filtered.includes(item._path)) { return false } - return true - }) - }) - - return { tree, config } -} |
