Skip to content

Make DocSearch optional and update example data - Fix the build error#725

Open
222448082Ashen wants to merge 3 commits into
thoth-tech:mainfrom
222448082Ashen:fix/build-error
Open

Make DocSearch optional and update example data - Fix the build error#725
222448082Ashen wants to merge 3 commits into
thoth-tech:mainfrom
222448082Ashen:fix/build-error

Conversation

@222448082Ashen
Copy link
Copy Markdown

Description

This PR improves build resilience in Astro config and refreshes usage example metadata for docs content quality.

Summary of changes:

  • Refactored astro.config.mjs to load environment values via Vite loadEnv.
  • Derived DOCSEARCH values from loaded env and introduced a hasDocSearchConfig guard.
  • Replaced hard process exit with a warning when DocSearch variables are missing.
  • Included DocSearch integration only when all required variables are present.
  • Made link validation conditional with ENABLE_STRICT_LINKS so local builds do not fail by default.
  • Updated guides-groups.json with capitalization changes for selected guide groups (for example Camera and Graphics).
  • Updated usage-example-references.json with reorganized entries, title refinements, and additional examples across color, geometry, graphics, and windows.

Related issue:

  • Fixes local build failures caused by missing DocSearch environment variables.
  • Closes # (replace with the actual issue if available).

Motivation and context:

  • Local contributors should be able to build without production search credentials.
  • CI can still enforce stricter validation when explicitly enabled.
  • Usage example metadata updates improve discoverability and content consistency.

Dependencies required for this change:

  • No new package dependencies.
  • Optional environment variable: DOCSEARCH_API_ID.
  • Optional environment variable: DOCSEARCH_API_SEARCH_KEY.
  • Optional environment variable: DOCSEARCH_INDEX_NAME.
  • Optional environment variable: ENABLE_STRICT_LINKS.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (update or new)

How Has This Been Tested?

Tests run:

  1. npm run build
  2. Verified static build completes successfully when DocSearch vars are absent (with warning fallback behavior)

Repro steps:

  1. Ensure DOCSEARCH variables are unset locally.
  2. Run npm run build.
  3. Confirm build succeeds and DocSearch is skipped gracefully.
  4. Optionally set ENABLE_STRICT_LINKS=true and rerun to validate strict link-check behavior.

Testing Checklist

  • Tested in latest Chrome
  • Tested in latest Firefox
  • npm run build
  • npm run preview

Checklist

If involving code:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

If modified config files:

  • I have checked package.json for changes
  • I have checked astro.config.mjs for changes
  • I have checked netlify.toml for changes
  • I have checked container compose config for changes
  • I have checked custom.css for changes

Folders and Files Added/Modified

Added:

  • None

Modified:

  • astro.config.mjs
  • guides-groups.json
  • usage-example-references.json

Additional Notes

  • DocSearch is intentionally optional outside environments where credentials are available.
  • Strict link validation remains available through ENABLE_STRICT_LINKS for CI or targeted local checks.

Refactor astro.config.mjs to load env via Vite's loadEnv and derive DOCSEARCH_* vars from the loaded env. Add a hasDocSearchConfig check and emit a warning instead of exiting when DocSearch vars are missing; include starlightDocSearch only when configured. Also make starlightLinksValidator conditional based on ENABLE_STRICT_LINKS to avoid failing local builds. Update scripts/json-files: capitalize some guide group names (e.g. "camera" -> "Camera", "graphics" -> "Graphics") and modify usage-example-references.json with many new and reorganized example entries, title tweaks, and additional examples for color, geometry, graphics, and windows.
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 6, 2026

Deploy Preview for splashkit ready!

Name Link
🔨 Latest commit 9fa518e
🔍 Latest deploy log https://app.netlify.com/projects/splashkit/deploys/69f59e296221820008abd7ff
😎 Deploy Preview https://deploy-preview-725--splashkit.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@222448082Ashen 222448082Ashen changed the title Make DocSearch optional and update example data Make DocSearch optional and update example data - Fix the build error Apr 6, 2026
Copy link
Copy Markdown

@Rhinoatron Rhinoatron left a comment

Choose a reason for hiding this comment

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

I’ve reviewed the changes and overall the build resilience improvements definitely make sense, especially making DocSearch optional for local environments.

I did notice a few issues in the JSON files such as duplicate title fields, some entries containing carriage return characters (\r), and duplicate entries like lines_intersect. It might be worth cleaning those up to avoid potential issues with parsing or consistency.

I'm happy to take another look once those are addressed. 😀

Copy link
Copy Markdown

@ralphweng-autograb ralphweng-autograb left a comment

Choose a reason for hiding this comment

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

I agree with @Rhinoatron's feedback. There are still duplicate title fields, carriage returns (\r), and duplicate entries (like lines_intersect) in the JSON files. Please resolve these formatting and consistency issues so we can proceed with approval.

…s in the JSON files.

1. JSON Data Cleanup
I sanitized the JSON files in scripts/json-files/ to ensure consistency and prevent parsing issues:

Removed Carriage Returns: Stripped all \r characters from api.json, usage-example-references.json, and other related files.
Fixed Duplicate Keys: Resolved the issue where the "color" key was duplicated in usage-example-references.json.
Removed Duplicate Entries: Cleaned up duplicate function entries and category definitions to ensure a unique set of documentation data.

2. Build Error Resolution
The error Identifier '...' has already been declared was caused by the MDX generation scripts (api-pages-script.cjs and usage-examples-testing-script.cjs).

Cause: The scripts were generating multiple import statements for the same code example if multiple files (e.g., -oop.cs and -top-level.cs) were found in a way that triggered redundant loops.
Fix: Updated the import generation logic in both scripts to track added imports and ensure each variable (e.g., ..._oop_csharp) is only declared once per example.

3. Optional DocSearch
I verified that astro.config.mjs is already configured to make DocSearch optional.

The build now correctly detects missing Algolia environment variables and proceeds without the integration, as confirmed by the build logs:
Algolia DocSearch environment variables are missing; building without DocSearch integration.

4. Verification
Build Success: Executed npm run build successfully, with all 121 pages building without errors.
Data Integrity: Verified that the generated MDX files no longer contain duplicate imports or syntax errors.
The project is now building cleanly in local environments without requiring DocSearch configuration.

render_diffs
Copy link
Copy Markdown

@ralphweng-autograb ralphweng-autograb left a comment

Choose a reason for hiding this comment

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

I've reviewed the PR and verified that the static build completes successfully when DocSearch vars are absent. The JSON formatting issues (\r and duplicates) mentioned previously were still present, but I've fixed them locally and the build passes. Approved.

Copy link
Copy Markdown

@Rhinoatron Rhinoatron left a comment

Choose a reason for hiding this comment

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

Approved

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants