From c80cf92a85d214511a9be337c6a6d201af04a595 Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Fri, 27 Mar 2026 12:05:11 -0400 Subject: [PATCH 1/2] feat(API): Add API only build mode --- cli/cli.ts | 11 ++++++++++- src/pages/404.astro | 22 ++++++++++++++++++++++ src/pages/[section]/[...page].astro | 6 ++++++ src/pages/[section]/[page]/[tab].astro | 6 ++++++ src/pages/index.astro | 12 +++++++++++- 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/pages/404.astro 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..821d235 100644 --- a/src/pages/[section]/[...page].astro +++ b/src/pages/[section]/[...page].astro @@ -36,6 +36,12 @@ export async function getStaticPaths() { ), ) + const apiOnly = process.env.PF_API_ONLY === 'true' + + if (apiOnly) { + return [] + } + return collections.flat().map((entry) => { const { filePath } = entry const { tab, source, tabName } = entry.data diff --git a/src/pages/[section]/[page]/[tab].astro b/src/pages/[section]/[page]/[tab].astro index 7babde9..1bf23e4 100644 --- a/src/pages/[section]/[page]/[tab].astro +++ b/src/pages/[section]/[page]/[tab].astro @@ -37,6 +37,12 @@ export async function getStaticPaths() { ), ) + const apiOnly = process.env.PF_API_ONLY === 'true' + + if (apiOnly) { + return [] + } + const flatCol = collections .flat() .map(({ data, filePath, ...rest }) => ({ 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 + )} From 23126ca59724e461fc4f8826f0726a4b02ee1a80 Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Tue, 31 Mar 2026 09:31:13 -0400 Subject: [PATCH 2/2] Move api only check before getting collections --- src/pages/[section]/[...page].astro | 12 ++++++------ src/pages/[section]/[page]/[tab].astro | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pages/[section]/[...page].astro b/src/pages/[section]/[...page].astro index 821d235..1484c5b 100644 --- a/src/pages/[section]/[...page].astro +++ b/src/pages/[section]/[...page].astro @@ -30,17 +30,17 @@ import { import DocsTables from '../../components/DocsTables.astro' export async function getStaticPaths() { - const collections = await Promise.all( - content.map( - async (entry) => await getCollection(entry.name as 'textContent'), - ), - ) - 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'), + ), + ) return collections.flat().map((entry) => { const { filePath } = entry diff --git a/src/pages/[section]/[page]/[tab].astro b/src/pages/[section]/[page]/[tab].astro index 1bf23e4..c3d8366 100644 --- a/src/pages/[section]/[page]/[tab].astro +++ b/src/pages/[section]/[page]/[tab].astro @@ -31,17 +31,17 @@ import DocsTables from '../../../components/DocsTables.astro' import { addDemosOrDeprecated, getDefaultTab } from '../../../utils' export async function getStaticPaths() { - const collections = await Promise.all( - content.map( - async (entry) => await getCollection(entry.name as 'textContent'), - ), - ) - 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'), + ), + ) const flatCol = collections .flat()