From 00761a3aedbcf2f859523eba6895c9edbce4cd19 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 20 Feb 2024 20:48:02 +0100 Subject: [PATCH] feat: allow disabling landing --- layers/core/app/modules/content/index.ts | 11 +- layers/core/app/modules/content/landing.mjs | 3 + layers/core/app/modules/content/source.mjs | 6 + schema/config.d.ts | 29 ++-- schema/config.json | 144 +++++++++++--------- 5 files changed, 112 insertions(+), 81 deletions(-) diff --git a/layers/core/app/modules/content/index.ts b/layers/core/app/modules/content/index.ts index 4a9ebe1..d4d04e4 100644 --- a/layers/core/app/modules/content/index.ts +++ b/layers/core/app/modules/content/index.ts @@ -1,7 +1,7 @@ import { fileURLToPath } from 'node:url' import { defineNuxtModule } from 'nuxt/kit' import type { ModuleOptions as ContentOptions } from '@nuxt/content' -import type { DocsConfig } from '../../../schema' +import type { DocsConfig } from '../../../../../schema/config' export default defineNuxtModule({ setup(_, nuxt) { @@ -12,6 +12,15 @@ export default defineNuxtModule({ const contentConfig = (nuxt.options as any).content as ContentOptions const docsConfig = (nuxt.options as any).docs as DocsConfig + if (docsConfig.landing === false) { + nuxt.hooks.hook('pages:extend', (pages) => { + const index = pages.findIndex((page) => page.path === '/') + if (index !== -1) { + pages.splice(index, 1) + } + }) + } + contentConfig.sources = { ...contentConfig.sources, content: { diff --git a/layers/core/app/modules/content/landing.mjs b/layers/core/app/modules/content/landing.mjs index d7a8f35..9baf002 100644 --- a/layers/core/app/modules/content/landing.mjs +++ b/layers/core/app/modules/content/landing.mjs @@ -1,6 +1,9 @@ import defu from 'defu' export function genLanding(docsConfig) { + if (docsConfig.landing === false) { + return undefined + } const landing = defu(docsConfig.landing || {}, { // Meta navigation: false, diff --git a/layers/core/app/modules/content/source.mjs b/layers/core/app/modules/content/source.mjs index 4841d2d..d55673b 100644 --- a/layers/core/app/modules/content/source.mjs +++ b/layers/core/app/modules/content/source.mjs @@ -11,6 +11,9 @@ export default (opts) => { name: 'content', async getItem(key) { const val = await _fs.getItem(key) + if (opts.docsConfig.landing === false) { + return val + } if (!val && key === 'index.json') { return await import('./landing.mjs').then(({ genLanding }) => genLanding(opts.docsConfig)) } @@ -21,6 +24,9 @@ export default (opts) => { }, async getKeys(prefix) { const keys = await _fs.getKeys(prefix) + if (opts.docsConfig.landing === false) { + return keys + } if (!keys.some((key) => /^index\.\w+$/.test(key))) { keys.push('index.json') } diff --git a/schema/config.d.ts b/schema/config.d.ts index 41ffb67..186e3be 100644 --- a/schema/config.d.ts +++ b/schema/config.d.ts @@ -7,16 +7,21 @@ export interface DocsConfig { github?: string themeColor?: string redirects?: Record - landing?: { - title?: string - description?: string - _heroMdTitle?: string - heroTitle?: string - heroSubtitle?: string - heroDescription?: string - heroLinks?: Record - heroCode?: string | { content: string; title?: string; lang?: string } - featuresTitle?: string - features?: { title: string; description?: string; icon?: string }[] - } + landing?: + | false + | { + title?: string + description?: string + _heroMdTitle?: string + heroTitle?: string + heroSubtitle?: string + heroDescription?: string + heroLinks?: Record< + string, + string | { label?: string; icon?: string; to?: string; size?: string; order?: number } + > + heroCode?: string | { content: string; title?: string; lang?: string } + featuresTitle?: string + features?: { title: string; description?: string; icon?: string }[] + } } diff --git a/schema/config.json b/schema/config.json index 6073401..9312056 100644 --- a/schema/config.json +++ b/schema/config.json @@ -42,84 +42,92 @@ } }, "landing": { - "type": "object", - "description": "Landing page configuration", - "additionalProperties": false, - "properties": { - "description": { - "type": "string", - "description": "Page description" + "oneOf": [ + { + "type": "boolean", + "const": false }, - "features": { - "type": "array", - "description": "Features section description", - "items": { - "type": "object", - "properties": { - "description": { - "type": "string" - }, - "icon": { - "type": "string" - }, - "title": { - "type": "string" + { + "type": "object", + "description": "Landing page configuration", + "additionalProperties": false, + "properties": { + "description": { + "type": "string", + "description": "Page description" + }, + "features": { + "type": "array", + "description": "Features section description", + "items": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "icon": { + "type": "string" + }, + "title": { + "type": "string" + } + } } - } - } - }, - "featuresTitle": { - "type": "string", - "description": "Features section title" - }, - "heroCode": { - "description": "Hero Codes", - "anyOf": [ - { - "type": "string" }, - { - "type": "object", - "additionalProperties": false, - "required": ["content"], - "properties": { - "content": { - "type": "string" - }, - "lang": { + "featuresTitle": { + "type": "string", + "description": "Features section title" + }, + "heroCode": { + "description": "Hero Codes", + "anyOf": [ + { "type": "string" }, - "title": { - "type": "string" + { + "type": "object", + "additionalProperties": false, + "required": ["content"], + "properties": { + "content": { + "type": "string" + }, + "lang": { + "type": "string" + }, + "title": { + "type": "string" + } + } } + ] + }, + "heroDescription": { + "type": "string", + "description": "Additional text in hero (default is same as description)" + }, + "heroLinks": { + "description": "Hero Links", + "type": "object", + "additionalProperties": { + "type": "object" } + }, + "heroSubtitle": { + "type": "string", + "description": "second hero title (default is same as shortDescription)" + }, + "heroTitle": { + "type": "string", + "description": "main title (default is same as page title)" + }, + "title": { + "type": "string", + "description": "Page title" } - ] - }, - "heroDescription": { - "type": "string", - "description": "Additional text in hero (default is same as description)" - }, - "heroLinks": { - "description": "Hero Links", - "type": "object", - "additionalProperties": { - "type": "object" } - }, - "heroSubtitle": { - "type": "string", - "description": "second hero title (default is same as shortDescription)" - }, - "heroTitle": { - "type": "string", - "description": "main title (default is same as page title)" - }, - "title": { - "type": "string", - "description": "Page title" } - } + ] } } }