Skip to content

feat(API): Add API only build mode#229

Merged
dlabaj merged 2 commits intomainfrom
add-api-only-build-mode
Mar 31, 2026
Merged

feat(API): Add API only build mode#229
dlabaj merged 2 commits intomainfrom
add-api-only-build-mode

Conversation

@wise-king-sullyman
Copy link
Copy Markdown
Contributor

@wise-king-sullyman wise-king-sullyman commented Mar 27, 2026

Closes #212

Summary by CodeRabbit

Release Notes

  • New Features
    • Added a --api-only CLI flag to enable API-only mode that omits standalone content pages while keeping API routes available.
    • Site homepage now shows an API-focused notice with a link to /api when API-only mode is active.
    • 404 responses display a tailored message explaining API-only availability when API-only mode is enabled.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b3982480-8430-47e3-a4bb-b5df942709cf

📥 Commits

Reviewing files that changed from the base of the PR and between c80cf92 and 23126ca.

📒 Files selected for processing (2)
  • src/pages/[section]/[...page].astro
  • src/pages/[section]/[page]/[tab].astro
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/pages/[section]/[page]/[tab].astro
  • src/pages/[section]/[...page].astro

Walkthrough

Adds a new --api-only CLI flag that sets process.env.PF_API_ONLY = 'true' during build and start, and threads that flag into page logic so index, 404, and dynamic page routes either render API-only messages or skip static path generation.

Changes

Cohort / File(s) Summary
CLI
cli/cli.ts
Added --api-only flag and sets process.env.PF_API_ONLY = 'true' during buildProject and start command flows.
Dynamic route static paths
src/pages/[section]/[...page].astro, src/pages/[section]/[page]/[tab].astro
getStaticPaths() short-circuits and returns an empty array when PF_API_ONLY === 'true', skipping standalone page generation.
Top-level pages
src/pages/index.astro, src/pages/404.astro
Index and new 404 page read PF_API_ONLY and render API-focused messaging when enabled; otherwise render standard content.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant CLI as CLI (cli/cli.ts)
participant Runner as Build/Start Runner
participant Env as process.env.PF_API_ONLY
participant ContentGen as Content Generator (pages/getStaticPaths)
participant APIIndex as API Index Initializer
CLI->>Runner: parse args (--api-only)
CLI->>Env: set PF_API_ONLY = 'true'
Runner->>APIIndex: initialize (always, may be conditional)
Runner->>ContentGen: invoke getStaticPaths / page rendering
alt PF_API_ONLY == 'true'
ContentGen-->>Runner: return empty static paths / API-only page variants
APIIndex-->>Runner: serve API endpoints
else
ContentGen-->>Runner: generate full static pages
APIIndex-->>Runner: initialize normally
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

released

Suggested reviewers

  • dlabaj
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(API): Add API only build mode' clearly describes the main change—adding an API-only build mode feature.
Linked Issues check ✅ Passed The PR successfully implements the objective from issue #212 to build only the API portion of the site by adding an --api-only CLI flag and environment variable that controls conditional rendering and static path generation.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the API-only build mode feature. The modifications to CLI, pages, and static path generation align with the stated objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-api-only-build-mode

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 27, 2026

Deploying patternfly-doc-core with  Cloudflare Pages  Cloudflare Pages

Latest commit: 23126ca
Status: ✅  Deploy successful!
Preview URL: https://143b082c.patternfly-doc-core.pages.dev
Branch Preview URL: https://add-api-only-build-mode.patternfly-doc-core.pages.dev

View logs

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
src/pages/[section]/[page]/[tab].astro (1)

33-44: Move the apiOnly check before fetching collections to avoid unnecessary work.

When PF_API_ONLY is 'true', collections are fetched via Promise.all and then immediately discarded. Move the early return to the top of getStaticPaths() to skip the async operations entirely.

♻️ Proposed optimization
 export async function getStaticPaths() {
+  if (process.env.PF_API_ONLY === 'true') {
+    return []
+  }
+
   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 flatCol = collections
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/`[section]/[page]/[tab].astro around lines 33 - 44, In
getStaticPaths(), check the apiOnly flag (process.env.PF_API_ONLY === 'true')
and return [] before starting the Promise.all that maps over content and calls
getCollection; specifically move the apiOnly check to the top of the
getStaticPaths function so you avoid invoking content.map, getCollection, and
Promise.all when apiOnly is true.
src/pages/[section]/[...page].astro (1)

32-43: Move the apiOnly check before fetching collections.

Same issue as in [tab].astro — the collections are fetched before checking PF_API_ONLY, wasting async work when API-only mode is enabled.

♻️ Proposed optimization
 export async function getStaticPaths() {
+  if (process.env.PF_API_ONLY === 'true') {
+    return []
+  }
+
   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 []
-  }

   return collections.flat().map((entry) => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/`[section]/[...page].astro around lines 32 - 43, In getStaticPaths,
check PF_API_ONLY early and return if true before starting any async work: move
the apiOnly (const apiOnly = process.env.PF_API_ONLY === 'true') check to the
top of the function and return [] immediately when true so you avoid calling
getCollection or iterating over content; update references to content and
getCollection accordingly to only run when not in API-only mode.
cli/cli.ts (1)

198-198: Clarify the option description.

The description says "skip standalone content pages" but based on the implementation, ALL content pages (both [section]/[...page].astro and [section]/[page]/[tab].astro) are skipped when this flag is set. Consider updating the description to be more accurate.

📝 Suggested clarification
-program.option('--api-only', 'only build API and component pages, skip standalone content pages', false)
+program.option('--api-only', 'only build API routes, skip all content pages', false)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/cli.ts` at line 198, The --api-only option description is misleading:
update the program.option call for '--api-only' (in cli.ts where program.option
is defined) to state that it skips all content pages (both standalone and nested
content routes such as [section]/[...page].astro and
[section]/[page]/[tab].astro), not just "standalone" pages; keep the same flag
name and default value but change the human-readable description to accurately
reflect that all content pages are omitted when this flag is set.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cli/cli.ts`:
- Line 198: The --api-only option description is misleading: update the
program.option call for '--api-only' (in cli.ts where program.option is defined)
to state that it skips all content pages (both standalone and nested content
routes such as [section]/[...page].astro and [section]/[page]/[tab].astro), not
just "standalone" pages; keep the same flag name and default value but change
the human-readable description to accurately reflect that all content pages are
omitted when this flag is set.

In `@src/pages/`[section]/[...page].astro:
- Around line 32-43: In getStaticPaths, check PF_API_ONLY early and return if
true before starting any async work: move the apiOnly (const apiOnly =
process.env.PF_API_ONLY === 'true') check to the top of the function and return
[] immediately when true so you avoid calling getCollection or iterating over
content; update references to content and getCollection accordingly to only run
when not in API-only mode.

In `@src/pages/`[section]/[page]/[tab].astro:
- Around line 33-44: In getStaticPaths(), check the apiOnly flag
(process.env.PF_API_ONLY === 'true') and return [] before starting the
Promise.all that maps over content and calls getCollection; specifically move
the apiOnly check to the top of the getStaticPaths function so you avoid
invoking content.map, getCollection, and Promise.all when apiOnly is true.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: de1b334e-ff88-4b15-9053-2a4e6cb29fd2

📥 Commits

Reviewing files that changed from the base of the PR and between 53b707c and c80cf92.

📒 Files selected for processing (5)
  • cli/cli.ts
  • src/pages/404.astro
  • src/pages/[section]/[...page].astro
  • src/pages/[section]/[page]/[tab].astro
  • src/pages/index.astro

@dlabaj dlabaj merged commit 10aeffc into main Mar 31, 2026
5 checks passed
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 1.22.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add way to build only the API

2 participants