From ccea8b426a8356daaa4075df6fb1fffedcaa00d5 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Mon, 4 Dec 2023 11:50:26 +0100 Subject: [PATCH] feat: support `documentDriven` mode #115 --- package.json | 1 + playground/nuxt.config.ts | 10 +++-- pnpm-lock.yaml | 77 +++++++++++++++++++++++++++++++- src/core/config/moduleOptions.ts | 5 +++ src/module.ts | 12 +++++ 5 files changed, 99 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index c148411..f23477f 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "@nuxt/test-utils": "3.8.1", "@nuxt/types": "2.17.2", "@nuxtjs/eslint-config-typescript": "12.1.0", + "@nuxt/content": "2.9.0", "@nuxtjs/i18n": "8.0.0-rc.5", "@nuxtjs/web-vitals": "0.2.6", "@types/lodash-es": "4.17.12", diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index 4486b15..5f38e4a 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -1,15 +1,17 @@ export default defineNuxtConfig({ extends: ['nuxt-seo-kit'], - /* @ts-ignore */ - modules: ['nuxt-typed-router', '@nuxtjs/i18n'], + modules: ['nuxt-typed-router', '@nuxtjs/i18n', '@nuxt/content'], devtools: { enabled: true, }, nuxtTypedRouter: { plugin: true, pathCheck: true, - experimentalRemoveNuxtDefs: true, - experimentalIgnoreRoutes: ['[...404].vue'], + removeNuxtDefs: true, + ignoreRoutes: ['[...404].vue'], + }, + content: { + documentDriven: false, }, srcDir: './src', i18n: { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5d3361c..07ffe99 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -33,6 +33,9 @@ importers: specifier: 1.1.1 version: 1.1.1 devDependencies: + '@nuxt/content': + specifier: 2.9.0 + version: 2.9.0(nuxt@3.8.2)(rollup@3.29.4)(vue@3.3.9) '@nuxt/devtools': specifier: 1.0.3 version: 1.0.3(nuxt@3.8.2)(rollup@3.29.4)(vite@4.5.0) @@ -1987,6 +1990,58 @@ packages: - vue dev: true + /@nuxt/content@2.9.0(nuxt@3.8.2)(rollup@3.29.4)(vue@3.3.9): + resolution: {integrity: sha512-//mt++/AgOmjT6TpanugNJpJfx6q8g7wV8/vnk7vSSrrgki8tG6jpupuJmxHHB8DcqqTJfuBWFIdaLhv/Z9Gzg==} + dependencies: + '@nuxt/kit': 3.8.2(rollup@3.29.4) + '@nuxtjs/mdc': 0.2.8(rollup@3.29.4) + '@vueuse/core': 10.6.1(vue@3.3.9) + '@vueuse/head': 2.0.0(vue@3.3.9) + '@vueuse/nuxt': 10.6.1(nuxt@3.8.2)(rollup@3.29.4)(vue@3.3.9) + consola: 3.2.3 + defu: 6.1.3 + destr: 2.0.2 + json5: 2.2.3 + knitwork: 1.0.0 + listhen: 1.5.5 + mdast-util-to-string: 4.0.0 + mdurl: 1.0.1 + micromark: 4.0.0 + micromark-util-sanitize-uri: 2.0.0 + micromark-util-types: 2.0.0 + minisearch: 6.3.0 + ohash: 1.1.3 + pathe: 1.1.1 + scule: 1.1.0 + shiki-es: 0.14.0 + slugify: 1.6.6 + socket.io-client: 4.7.2 + ufo: 1.3.2 + unist-util-stringify-position: 4.0.0 + unstorage: 1.10.1 + ws: 8.14.2 + transitivePeerDependencies: + - '@azure/app-configuration' + - '@azure/cosmos' + - '@azure/data-tables' + - '@azure/identity' + - '@azure/keyvault-secrets' + - '@azure/storage-blob' + - '@capacitor/preferences' + - '@netlify/blobs' + - '@planetscale/database' + - '@upstash/redis' + - '@vercel/kv' + - '@vue/composition-api' + - bufferutil + - idb-keyval + - nuxt + - rollup + - supports-color + - utf-8-validate + - vue + dev: true + /@nuxt/devalue@2.0.2: resolution: {integrity: sha512-GBzP8zOc7CGWyFQS6dv1lQz8VVpz5C2yRszbXufwG/9zhStTIH50EtD87NmWbTMwXDvZLNg8GIpb1UFdH93JCA==} dev: true @@ -4342,6 +4397,24 @@ packages: - vue dev: true + /@vueuse/nuxt@10.6.1(nuxt@3.8.2)(rollup@3.29.4)(vue@3.3.9): + resolution: {integrity: sha512-MnXg0ZviWHKcf2CsBYeHXhK9Pqn2TF7EJfaLgd+3rHEyb6XlSLUKBTPNCiO+5VH3Ck1IJAez90KS3VAdSqqs1w==} + peerDependencies: + nuxt: ^3.0.0 + dependencies: + '@nuxt/kit': 3.8.2(rollup@3.29.4) + '@vueuse/core': 10.6.1(vue@3.3.9) + '@vueuse/metadata': 10.6.1 + local-pkg: 0.5.0 + nuxt: 3.8.2(@types/node@20.10.0)(eslint@8.54.0)(rollup@3.29.4)(typescript@5.3.2)(vite@4.5.0)(vue-tsc@1.8.22) + vue-demi: 0.14.6(vue@3.3.9) + transitivePeerDependencies: + - '@vue/composition-api' + - rollup + - supports-color + - vue + dev: true + /@vueuse/shared@10.6.1(vue@3.3.9): resolution: {integrity: sha512-TECVDTIedFlL0NUfHWncf3zF9Gc4VfdxfQc8JFwoVZQmxpONhLxFrlm0eHQeidHj4rdTPL3KXJa0TZCk1wnc5Q==} dependencies: @@ -7871,7 +7944,7 @@ packages: dependencies: '@parcel/watcher': 2.3.0 '@parcel/watcher-wasm': 2.3.0 - citty: 0.1.4 + citty: 0.1.5 clipboardy: 3.0.0 consola: 3.2.3 defu: 6.1.3 @@ -7883,7 +7956,7 @@ packages: node-forge: 1.3.1 pathe: 1.1.1 std-env: 3.5.0 - ufo: 1.3.1 + ufo: 1.3.2 untun: 0.1.2 uqr: 0.1.2 dev: true diff --git a/src/core/config/moduleOptions.ts b/src/core/config/moduleOptions.ts index 5f1ae3e..72682e8 100644 --- a/src/core/config/moduleOptions.ts +++ b/src/core/config/moduleOptions.ts @@ -9,6 +9,7 @@ interface CustomNuxtConfigOptions { srcDir?: string; i18n?: boolean; i18nOptions?: NuxtI18nOptions | null; + isDocumentDriven: boolean; } class ModuleOptionsStore { @@ -54,6 +55,10 @@ class ModuleOptionsStore { if (options.ignoreRoutes) { this.ignoreRoutes = options.ignoreRoutes; } + + if (options.isDocumentDriven) { + this.ignoreRoutes.push('[...slug].vue'); + } } get resolvedIgnoredRoutes(): string[] { diff --git a/src/module.ts b/src/module.ts index 7d3b136..4648269 100644 --- a/src/module.ts +++ b/src/module.ts @@ -43,10 +43,22 @@ export default defineNuxtModule({ } }); + const isDocumentDriven = + !!nuxt.options.modules.find((mod) => { + if (Array.isArray(mod)) { + return mod[0] === '@nuxt/content'; + } else { + return mod === '@nuxt/content'; + } + }) && + 'content' in nuxt.options && + 'documentDriven' in (nuxt.options.content as any); + moduleOptionStore.updateOptions({ ...moduleOptions, i18n: hasi18nModuleRegistered, i18nOptions, + isDocumentDriven, }); nuxt.options.alias = {