Skip to content

Commit

Permalink
feat: allow disabling landing
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 20, 2024
1 parent 6f66f9d commit 00761a3
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 81 deletions.
11 changes: 10 additions & 1 deletion layers/core/app/modules/content/index.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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: {
Expand Down
3 changes: 3 additions & 0 deletions layers/core/app/modules/content/landing.mjs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 6 additions & 0 deletions layers/core/app/modules/content/source.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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')
}
Expand Down
29 changes: 17 additions & 12 deletions schema/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ export interface DocsConfig {
github?: string
themeColor?: string
redirects?: Record<string, string>
landing?: {
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 }[]
}
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 }[]
}
}
144 changes: 76 additions & 68 deletions schema/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
}
}
}

0 comments on commit 00761a3

Please sign in to comment.