diff --git a/cli/cli.ts b/cli/cli.ts index 58143cc..537565b 100755 --- a/cli/cli.ts +++ b/cli/cli.ts @@ -113,7 +113,11 @@ async function initializeApiIndex(program: Command) { } async function buildProject(program: Command): Promise { - const { verbose } = program.opts() + const { verbose, apiOnly } = program.opts() + + if (apiOnly) { + process.env.PF_API_ONLY = 'true' + } if (!config) { console.error( @@ -191,6 +195,7 @@ program.name('pf-doc-core') program.option('--verbose', 'verbose mode', false) program.option('--props', 'generate props data', false) program.option('--dry-run', 'dry run mode', false) +program.option('--api-only', 'only build API and component pages, skip standalone content pages', false) program.command('setup').action(async () => { await Promise.all([ @@ -212,6 +217,10 @@ program.command('init').action(async () => { }) program.command('start').action(async () => { + const { apiOnly } = program.opts() + if (apiOnly) { + process.env.PF_API_ONLY = 'true' + } await updateContent(program) await initializeApiIndex(program) diff --git a/src/pages/404.astro b/src/pages/404.astro new file mode 100644 index 0000000..9815158 --- /dev/null +++ b/src/pages/404.astro @@ -0,0 +1,22 @@ +--- +const apiOnly = process.env.PF_API_ONLY === 'true' +--- + + + + + + 404 - Not Found + + + {apiOnly ? ( + <> +

404 - Not Found

+

This build only serves API routes. Content pages are not available.

+

Available endpoints are under /api.

+ + ) : ( +

404 - Page not found

+ )} + + diff --git a/src/pages/[section]/[...page].astro b/src/pages/[section]/[...page].astro index 4dfe257..1484c5b 100644 --- a/src/pages/[section]/[...page].astro +++ b/src/pages/[section]/[...page].astro @@ -30,6 +30,12 @@ import { import DocsTables from '../../components/DocsTables.astro' export async function getStaticPaths() { + const apiOnly = process.env.PF_API_ONLY === 'true' + + if (apiOnly) { + return [] + } + const collections = await Promise.all( content.map( async (entry) => await getCollection(entry.name as 'textContent'), diff --git a/src/pages/[section]/[page]/[tab].astro b/src/pages/[section]/[page]/[tab].astro index 7babde9..c3d8366 100644 --- a/src/pages/[section]/[page]/[tab].astro +++ b/src/pages/[section]/[page]/[tab].astro @@ -31,6 +31,12 @@ import DocsTables from '../../../components/DocsTables.astro' import { addDemosOrDeprecated, getDefaultTab } from '../../../utils' export async function getStaticPaths() { + const apiOnly = process.env.PF_API_ONLY === 'true' + + if (apiOnly) { + return [] + } + const collections = await Promise.all( content.map( async (entry) => await getCollection(entry.name as 'textContent'), diff --git a/src/pages/index.astro b/src/pages/index.astro index 361ec6b..bdcff7a 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,5 +1,7 @@ --- import MainLayout from '../layouts/Main.astro' + +const apiOnly = process.env.PF_API_ONLY === 'true' --- @@ -11,6 +13,14 @@ import MainLayout from '../layouts/Main.astro' PatternFly - Page content + {apiOnly ? ( + <> +

PatternFly API

+

This build only serves API routes. Content pages are not available.

+

Available endpoints are under /api.

+ + ) : ( + Page content + )}