Skip to content

Commit 10aeffc

Browse files
feat(API): Add API only build mode (#229)
* feat(API): Add API only build mode * Move api only check before getting collections
1 parent 53b707c commit 10aeffc

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

cli/cli.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ async function initializeApiIndex(program: Command) {
113113
}
114114

115115
async function buildProject(program: Command): Promise<DocsConfig | undefined> {
116-
const { verbose } = program.opts()
116+
const { verbose, apiOnly } = program.opts()
117+
118+
if (apiOnly) {
119+
process.env.PF_API_ONLY = 'true'
120+
}
117121

118122
if (!config) {
119123
console.error(
@@ -191,6 +195,7 @@ program.name('pf-doc-core')
191195
program.option('--verbose', 'verbose mode', false)
192196
program.option('--props', 'generate props data', false)
193197
program.option('--dry-run', 'dry run mode', false)
198+
program.option('--api-only', 'only build API and component pages, skip standalone content pages', false)
194199

195200
program.command('setup').action(async () => {
196201
await Promise.all([
@@ -212,6 +217,10 @@ program.command('init').action(async () => {
212217
})
213218

214219
program.command('start').action(async () => {
220+
const { apiOnly } = program.opts()
221+
if (apiOnly) {
222+
process.env.PF_API_ONLY = 'true'
223+
}
215224
await updateContent(program)
216225
await initializeApiIndex(program)
217226

src/pages/404.astro

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
const apiOnly = process.env.PF_API_ONLY === 'true'
3+
---
4+
5+
<html lang="en">
6+
<head>
7+
<meta charset="utf-8" />
8+
<meta name="viewport" content="width=device-width" />
9+
<title>404 - Not Found</title>
10+
</head>
11+
<body>
12+
{apiOnly ? (
13+
<>
14+
<h1>404 - Not Found</h1>
15+
<p>This build only serves API routes. Content pages are not available.</p>
16+
<p>Available endpoints are under <a href="/api">/api</a>.</p>
17+
</>
18+
) : (
19+
<h1>404 - Page not found</h1>
20+
)}
21+
</body>
22+
</html>

src/pages/[section]/[...page].astro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ import {
3030
import DocsTables from '../../components/DocsTables.astro'
3131
3232
export async function getStaticPaths() {
33+
const apiOnly = process.env.PF_API_ONLY === 'true'
34+
35+
if (apiOnly) {
36+
return []
37+
}
38+
3339
const collections = await Promise.all(
3440
content.map(
3541
async (entry) => await getCollection(entry.name as 'textContent'),

src/pages/[section]/[page]/[tab].astro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ import DocsTables from '../../../components/DocsTables.astro'
3131
import { addDemosOrDeprecated, getDefaultTab } from '../../../utils'
3232
3333
export async function getStaticPaths() {
34+
const apiOnly = process.env.PF_API_ONLY === 'true'
35+
36+
if (apiOnly) {
37+
return []
38+
}
39+
3440
const collections = await Promise.all(
3541
content.map(
3642
async (entry) => await getCollection(entry.name as 'textContent'),

src/pages/index.astro

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
import MainLayout from '../layouts/Main.astro'
3+
4+
const apiOnly = process.env.PF_API_ONLY === 'true'
35
---
46

57
<html lang="en">
@@ -11,6 +13,14 @@ import MainLayout from '../layouts/Main.astro'
1113
<title>PatternFly</title>
1214
</head>
1315
<body>
14-
<MainLayout title="PatternFly X Astro"> Page content </MainLayout>
16+
{apiOnly ? (
17+
<>
18+
<h1>PatternFly API</h1>
19+
<p>This build only serves API routes. Content pages are not available.</p>
20+
<p>Available endpoints are under <a href="/api">/api</a>.</p>
21+
</>
22+
) : (
23+
<MainLayout title="PatternFly X Astro"> Page content </MainLayout>
24+
)}
1525
</body>
1626
</html>

0 commit comments

Comments
 (0)