Skip to content

Conversation

Copy link

Copilot AI commented Dec 23, 2025

The browserpod site's search functionality was broken because the pagefind loader only handled the /docs/ base path for cheerpj3 specifically.

Changes

  • Replace hardcoded productId === "cheerpj3" check with dynamic import.meta.env.BASE_URL in Pagefind.svelte
  • Construct pagefind URL from base path: {origin}{BASE_URL}pagefind/pagefind.js

This makes search work for any site with a base path configuration (cheerp, cheerpj, browserpod) without product-specific logic.

Before:

const url = productId === "cheerpj3"
  ? new URL(window.origin + "/docs/pagefind/pagefind.js").href
  : new URL(window.origin + "/pagefind/pagefind.js").href;

After:

const base = import.meta.env.BASE_URL || "/";
const baseWithSlash = base.endsWith("/") ? base : base + "/";
const pagefindPath = `${baseWithSlash}pagefind/pagefind.js`;
const url = `${window.location.origin}${pagefindPath}`;

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • telemetry.astro.build
    • Triggering command: /usr/local/bin/node node /home/REDACTED/work/labs/labs/sites/browserpod/node_modules/.bin/../astro/astro.js build (dns block)
    • Triggering command: /usr/local/bin/node node /home/REDACTED/work/labs/labs/sites/cheerp/node_modules/.bin/../astro/astro.js build (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Hi! The newest added domain browserpod (base website served through di8fferent repo but its doc subsection gets served from here) Doesn't have search functionality the same way our other repos do. Can you help me find what I need to implement/ add for search functinality to be global?

Created from VS Code via the GitHub Pull Request extension.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add global search functionality for browserpod Use BASE_URL for pagefind path construction instead of hardcoding product checks Dec 23, 2025
Copilot AI requested a review from codingfrog27 December 23, 2025 17:47
@codingfrog27
Copy link
Contributor

@copilot Can i view your changes before accepting them? And before you make a PR?

Also the hardcode was due to cheerpJ not having /docs/ in its URL which maybe should be fixed now? So I wonder if that comparison is even still necesary

I think you werent able to build due to using npm instead of pnpm

Also idk if its true but worth noting that after the non cheerpj pagefind theres a comment stating "Can't use import.meta.url because Vite prefixes the module with /@fs." Though not sure if its currently true

Copy link
Author

Copilot AI commented Dec 23, 2025

@copilot Can i view your changes before accepting them? And before you make a PR?

Also the hardcode was due to cheerpJ not having /docs/ in its URL which maybe should be fixed now? So I wonder if tha...

The changes are visible in the PR diff above. The key change is in packages/astro-theme/components/search/Pagefind.svelte:

Original approach: Hardcoded check for productId === "cheerpj3" to add /docs/ prefix
New approach: Use import.meta.env.BASE_URL to automatically handle any site with a base path

You're right that cheerpj now has /docs/ in its URL (configured in astro.config.mjs as base: "/docs"), which is exactly why the hardcode can be removed. My change uses Astro's BASE_URL environment variable which automatically reflects the configured base path for each site:

  • cheerpj: BASE_URL = /docs/ → URL becomes /docs/pagefind/pagefind.js
  • browserpod: BASE_URL = /docs/ → URL becomes /docs/pagefind/pagefind.js ✓ (this was broken before)
  • cheerp: BASE_URL = / → URL becomes /pagefind/pagefind.js

Regarding the Vite comment: I kept the /* @vite-ignore */ comment in the import statement to maintain the same behavior. The URL construction method changed but the dynamic import approach remains the same.

The changes are in commits 2d7dc1a and ff694dd.

@codingfrog27
Copy link
Contributor

@copilot still not able to see your changed file

@codingfrog27 codingfrog27 deleted the copilot/add-global-search-functionality branch December 23, 2025 18:01
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.

2 participants