@docus/base-edge
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import { themeMerger } from '../utils' | ||
import { themeMerger } from '../utils/theme' | ||
import { computed, unref, useDocusState, useRuntimeConfig } from '#imports' | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { queryNavigation } from '../utils' | ||
import { queryNavigation } from '../utils/queries' | ||
import { defineNuxtRouteMiddleware } from '#imports' | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { queryPage } from '../utils' | ||
import { queryPage } from '../utils/queries' | ||
import { defineNuxtRouteMiddleware, useNuxtApp } from '#imports' | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { queryTheme } from '../utils' | ||
import { queryTheme } from '../utils/queries' | ||
import { defineNuxtRouteMiddleware } from '#imports' | ||
@@ -3,0 +3,0 @@ |
@@ -0,5 +1,6 @@ | ||
import { resolve } from 'pathe' | ||
import { addTemplate, defineNuxtModule, logger } from '@nuxt/kit' | ||
import type { Nuxt } from '@nuxt/schema' | ||
import { greenBright } from 'chalk' | ||
import { generateTypes, resolveSchema } from 'untyped' | ||
import { resolve } from 'pathe' | ||
import { name, version } from './package.json' | ||
@@ -12,2 +13,29 @@ import type { NuxtLayer } from './utils/theme' | ||
/** | ||
* Setup theme layer. | ||
*/ | ||
const setupTheme = (nuxt: Nuxt) => { | ||
nuxt.hook('modules:done', () => { | ||
const layers = nuxt.options._layers | ||
const theme = resolveTheme(layers as NuxtLayer[]) | ||
addTemplate({ | ||
filename: 'types/theme.d.ts', | ||
getContents: () => `${generateTypes(resolveSchema(theme), { addDefaults: true, allowExtraKeys: true, interfaceName: 'DocusThemeConfig' })}\n | ||
declare module '@nuxt/schema' { | ||
interface NuxtConfig { | ||
theme: Partial<DocusThemeConfig> | ||
} | ||
}`, | ||
}) | ||
nuxt.options.runtimeConfig.public.docus.defaultThemeConfig = theme | ||
}) | ||
nuxt.hook('prepare:types', (opts) => { | ||
opts.references.push({ path: resolve(nuxt.options.buildDir, 'types/theme.d.ts') }) | ||
}) | ||
} | ||
export default defineNuxtModule({ | ||
@@ -24,25 +52,8 @@ meta: { | ||
defaults: {}, | ||
setup(moduleOptions, nuxt) { | ||
setup(_, nuxt) { | ||
// Make also VT detects it | ||
nuxt.options.runtimeConfig.public.docus = nuxt.options.runtimeConfig.public.docus || {} | ||
nuxt.hook('modules:done', () => { | ||
const layers = nuxt.options._layers | ||
setupTheme(nuxt) | ||
const theme = resolveTheme(layers as NuxtLayer[]) | ||
addTemplate({ | ||
filename: 'types/theme.d.ts', | ||
getContents: () => | ||
`${generateTypes(resolveSchema(theme), { addDefaults: true, allowExtraKeys: true, interfaceName: 'DocusThemeConfig' })}\n | ||
declare module '@nuxt/schema' { | ||
interface NuxtConfig { | ||
theme: Partial<DocusThemeConfig> | ||
} | ||
}`, | ||
}) | ||
nuxt.options.runtimeConfig.public.docus.defaultThemeConfig = theme | ||
}) | ||
nuxt.hook('modules:done', async () => { | ||
@@ -55,7 +66,3 @@ motd() | ||
}) | ||
nuxt.hook('prepare:types', (opts) => { | ||
opts.references.push({ path: resolve(nuxt.options.buildDir, 'types/theme.d.ts') }) | ||
}) | ||
}, | ||
}) |
@@ -63,3 +63,3 @@ import { fileURLToPath } from 'url' | ||
theme: 'one-dark-pro', | ||
preload: ['json', 'js', 'ts', 'html', 'css', 'vue', 'diff', 'shell', 'markdown', 'yaml', 'bash'], | ||
preload: ['json', 'js', 'ts', 'html', 'css', 'vue', 'diff', 'shell', 'markdown', 'yaml', 'bash', 'ini'], | ||
}, | ||
@@ -66,0 +66,0 @@ navigation: { |
{ | ||
"name": "@docus/base-edge", | ||
"version": "3.0.0-f68d9c2", | ||
"version": "3.0.0-ff357af", | ||
"exports": { | ||
@@ -30,9 +30,10 @@ ".": "./nuxt.config.ts", | ||
"dependencies": { | ||
"nuxt": "^3.0.0-rc.3", | ||
"defu": "^6.0.0", | ||
"@nuxt/content": "npm:@nuxt/content-edge@latest", | ||
"@nuxthq/admin": "npm:@nuxthq/admin-edge@latest", | ||
"@vueuse/core": "^8.5.0", | ||
"@vueuse/nuxt": "^8.5.0" | ||
"@vueuse/core": "^8.7.3", | ||
"@vueuse/nuxt": "^8.7.3", | ||
"defu": "^6.0.0", | ||
"nuxt": "^3.0.0-rc.4", | ||
"pkg-types": "^0.3.2" | ||
} | ||
} |
import { withoutTrailingSlash } from 'ufo' | ||
import type { NavItem, ParsedContent } from '@nuxt/content/dist/runtime/types' | ||
import type { RouteLocationNormalized, RouteLocationNormalizedLoaded } from 'vue-router' | ||
import { fetchContentNavigation, navigateTo, queryContent, useDocus, useDocusNavigation, useDocusState } from '#imports' | ||
import { fetchContentNavigation, queryContent, useDocus, useDocusHelpers, useDocusState } from '#imports' | ||
import layouts from '#build/layouts' | ||
@@ -10,9 +10,9 @@ | ||
const { layoutFromPath } = useDocusNavigation() | ||
const { navKeyFromPath } = useDocusHelpers() | ||
const layoutFromNav = layoutFromPath(page._path, navigation) | ||
const layoutFromNav = navKeyFromPath(page._path, 'layout', navigation) | ||
if (layoutFromNav) return layoutFromNav | ||
return theme.layout | ||
return 'default' | ||
} | ||
@@ -38,3 +38,5 @@ | ||
return await Promise.all([ | ||
// _page | ||
queryContent().where({ _path: path }).findOne() as Promise<ParsedContent>, | ||
// _surround | ||
queryContent() | ||
@@ -45,2 +47,5 @@ .where({ _partial: { $not: true }, navigation: { $not: false } }) | ||
.then(async ([_page, _surround]) => { | ||
// Use `redirect` key to redirect to another page | ||
if (_page?.redirect) return _page?.redirect | ||
const layoutName = findLayout(_page, theme.value, navigation.value) | ||
@@ -66,3 +71,3 @@ | ||
surround.value = undefined | ||
return navigateTo('/404') | ||
return '/404' | ||
}) | ||
@@ -102,3 +107,3 @@ } | ||
if (!_theme) { | ||
console.warn('Could not find theme configuration, create a content/_theme.yml file') | ||
theme.value = {} | ||
return | ||
@@ -105,0 +110,0 @@ } |
Sorry, the diff of this file is not supported yet
17149
-7.58%7
16.67%16
-11.11%420
-7.28%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
Updated
Updated
Updated