diff --git a/docs-site/components/docs/DocsSearch.tsx b/docs-site/components/docs/DocsSearch.tsx index ccad24674..3f9df3755 100644 --- a/docs-site/components/docs/DocsSearch.tsx +++ b/docs-site/components/docs/DocsSearch.tsx @@ -12,6 +12,7 @@ import { CommandList, } from "@/components/ui/command"; import { create, load, search, type AnyOrama } from "@orama/orama"; +import { withBasePath } from "@/lib/basePath"; interface SearchResult { title: string; @@ -44,7 +45,7 @@ export function DocsSearch({ resolve }: { resolve: (path: string) => string }) { useEffect(() => { if (!open || dbRef.current) return; setLoading(true); - fetch("/search-index.json") + fetch(withBasePath("/search-index.json")) .then((res) => res.json()) .then((data) => { const db = create({ diff --git a/docs-site/components/docs/DocsShell.tsx b/docs-site/components/docs/DocsShell.tsx index 94bee411d..44d0f2f2f 100644 --- a/docs-site/components/docs/DocsShell.tsx +++ b/docs-site/components/docs/DocsShell.tsx @@ -8,6 +8,7 @@ import { type NavGroup, type NavItem, type NavTab } from "@/config/docsNav"; import { TableOfContents } from "./TableOfContents"; import { DocsSearch } from "./DocsSearch"; import { resolveHref } from "@/lib/resolveHref"; +import { withBasePath } from "@/lib/basePath"; import type { Heading } from "@/lib/docs"; /* ------------------------------------------------------------------ */ @@ -235,7 +236,7 @@ export function DocsShell({ > Continue @@ -245,7 +246,7 @@ export function DocsShell({
Continue diff --git a/docs-site/components/docs/mdx/index.tsx b/docs-site/components/docs/mdx/index.tsx index 9f13d40b7..79a128eca 100644 --- a/docs-site/components/docs/mdx/index.tsx +++ b/docs-site/components/docs/mdx/index.tsx @@ -10,6 +10,7 @@ import { OSAutoDetect } from "./OSAutoDetect"; import { CodeBlock } from "./CodeBlock"; import { CodeGroup } from "./CodeGroup"; import { MdxLink } from "./MdxLink"; +import { withBasePath } from "@/lib/basePath"; export const mdxComponents: MDXComponents = { // Mintlify callout variants @@ -62,9 +63,13 @@ export const mdxComponents: MDXComponents = { // Rewrite image paths — images are copied to public/images/docs/ at build time img: ({ src, alt, ...props }: any) => { - if (src && src.startsWith("/images/")) { + if (src && src.startsWith("/images/") && !src.startsWith("/images/docs/")) { src = `/images/docs${src.slice("/images".length)}`; } + // Prefix the deploy base path for raw absolute asset paths (GitHub Pages). + if (src && src.startsWith("/")) { + src = withBasePath(src); + } return {alt; }, }; diff --git a/docs-site/lib/basePath.ts b/docs-site/lib/basePath.ts new file mode 100644 index 000000000..afea87186 --- /dev/null +++ b/docs-site/lib/basePath.ts @@ -0,0 +1,18 @@ +/** + * Base path for the deployed docs site. + * + * On GitHub Pages the site lives under `/continue/`, so raw absolute asset + * references (search index, src, etc.) must be prefixed manually. Next + * applies basePath automatically to , 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}`; +} diff --git a/docs-site/next.config.js b/docs-site/next.config.js index 91dc0cf32..608032591 100644 --- a/docs-site/next.config.js +++ b/docs-site/next.config.js @@ -1,6 +1,22 @@ /** @type {import('next').NextConfig} */ + +// When deploying to GitHub Pages the site is served from the `/continue/` +// subpath (https://continuedev.github.io/continue/). GitHub Actions sets +// GITHUB_ACTIONS=true, so we only apply the base path there — local dev +// (localhost:3005) keeps serving from the root. +const isGithubPages = process.env.GITHUB_ACTIONS === "true"; +const basePath = isGithubPages ? "/continue" : ""; + const nextConfig = { output: "export", + basePath, + assetPrefix: basePath || undefined, + // Expose the base path to client/runtime code so raw string asset paths + // (search index fetch, src, etc.) can be prefixed manually — Next only + // applies basePath automatically to , next/image and /_next assets. + env: { + NEXT_PUBLIC_BASE_PATH: basePath, + }, typescript: { ignoreBuildErrors: true, },