Skip to content

Commit

Permalink
feat: support documentDriven mode #115
Browse files Browse the repository at this point in the history
  • Loading branch information
victorgarciaesgi committed Dec 4, 2023
1 parent 5353bb7 commit ccea8b4
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
77 changes: 75 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/core/config/moduleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface CustomNuxtConfigOptions {
srcDir?: string;
i18n?: boolean;
i18nOptions?: NuxtI18nOptions | null;
isDocumentDriven: boolean;
}

class ModuleOptionsStore {
Expand Down Expand Up @@ -54,6 +55,10 @@ class ModuleOptionsStore {
if (options.ignoreRoutes) {
this.ignoreRoutes = options.ignoreRoutes;
}

if (options.isDocumentDriven) {
this.ignoreRoutes.push('[...slug].vue');
}
}

get resolvedIgnoredRoutes(): string[] {
Expand Down
12 changes: 12 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,22 @@ export default defineNuxtModule<ModuleOptions>({
}
});

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 = {
Expand Down

0 comments on commit ccea8b4

Please sign in to comment.