continue-custom/docs-site/lib/basePath.ts
Nate Sesti 0e7f91ae15
docs: fix GitHub Pages subpath base path for docs site (#12638)
The docs site is served from the /continue/ subpath on GitHub Pages but
next.config.js set no basePath, so /_next CSS/JS, the search index, and
images were requested from the domain root and 404'd (unstyled site).

- Add basePath/assetPrefix of /continue, gated on GITHUB_ACTIONS so local
  dev still serves from root
- Expose NEXT_PUBLIC_BASE_PATH and add a withBasePath helper for raw
  absolute asset paths that Next doesn't prefix automatically
- Prefix the search-index fetch, logo, and MDX doc images
- Guard against double /images/docs/ rewrite in the MDX img component

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-15 12:54:57 -07:00

18 lines
764 B
TypeScript

/**
* Base path for the deployed docs site.
*
* On GitHub Pages the site lives under `/continue/`, so raw absolute asset
* references (search index, <img> src, etc.) must be prefixed manually. Next
* applies basePath automatically to <Link>, next/image and /_next assets, but
* NOT to plain string paths, so use `withBasePath` for those.
*
* `NEXT_PUBLIC_BASE_PATH` is inlined at build time (see next.config.js) and is
* therefore safe to read in both server and client/browser code.
*/
export const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH || "";
/** Prefix an absolute (`/`-rooted) path with the deploy base path. */
export function withBasePath(path: string): string {
if (!path.startsWith("/")) return path;
return `${BASE_PATH}${path}`;
}