diff --git a/next.config.mjs b/next.config.mjs index 9cbf23f..acac2c3 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -13,6 +13,7 @@ const config = { unoptimized: true, }, basePath: BASE_PATH, + assetPrefix: BASE_PATH, env: { NEXT_PUBLIC_BASE_PATH: BASE_PATH, }, diff --git a/public/_redirects b/public/_redirects index b4ce86e..684b19d 100644 --- a/public/_redirects +++ b/public/_redirects @@ -1,3 +1,15 @@ / /docs/hardware/ 301 +/docs/hardware /docs/hardware/ 301 + +/docs/hardware/ / 200 /docs/hardware/_next/* /_next/:splat 200 -/docs/hardware/* /:splat 200 +/docs/hardware/api/search /api/search 200 +/docs/hardware/og/* /og/:splat 200 +/docs/hardware/:file.:ext /:file.:ext 200 +/docs/hardware/* /:splat/ 200 + +/api/search /api/search 200 +/og/* /og/:splat 200 +/_next/* /_next/:splat 200 +/:file.:ext /:file.:ext 200 +/* /:splat/ 200 diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 1106c6e..7ccda23 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -15,7 +15,7 @@ const rubik = Rubik({ }); const baseUrl = - process.env.NEXT_PUBLIC_BASE_URL || "https://absmach.eu/docs/hardware"; + process.env.NEXT_PUBLIC_BASE_URL || "https://www.absmach.eu/docs/hardware"; export const metadata: Metadata = { metadataBase: new URL(baseUrl), diff --git a/src/app/robots.ts b/src/app/robots.ts index 63dc46a..89471fd 100644 --- a/src/app/robots.ts +++ b/src/app/robots.ts @@ -1,7 +1,7 @@ import type { MetadataRoute } from "next"; const baseUrl = - process.env.NEXT_PUBLIC_BASE_URL || "https://absmach.eu/docs/hardware"; + process.env.NEXT_PUBLIC_BASE_URL || "https://www.absmach.eu/docs/hardware"; export const dynamic = "force-static"; diff --git a/src/app/sitemap.ts b/src/app/sitemap.ts index 1af7d59..4654ad5 100644 --- a/src/app/sitemap.ts +++ b/src/app/sitemap.ts @@ -2,7 +2,7 @@ import type { MetadataRoute } from "next"; import { source } from "@/lib/source"; const baseUrl = - process.env.NEXT_PUBLIC_BASE_URL || "https://absmach.eu/docs/hardware"; + process.env.NEXT_PUBLIC_BASE_URL || "https://www.absmach.eu/docs/hardware"; export const dynamic = "force-static"; diff --git a/src/lib/base-path.ts b/src/lib/base-path.ts index d431dba..3bc11b0 100644 --- a/src/lib/base-path.ts +++ b/src/lib/base-path.ts @@ -5,7 +5,7 @@ * During build time (SSG), we use the environment variable * For runtime, this will be baked into the bundle */ -const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH || ""; +const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH || "/docs/hardware"; /** * Get the base path @@ -19,7 +19,7 @@ export function getBasePath(): string { * This works for both build-time and runtime */ export function assetPath(path: string): string { - // Ensure path starts with / + if (BASE_PATH && path.startsWith(BASE_PATH)) return path; const normalizedPath = path.startsWith("/") ? path : `/${path}`; return `${BASE_PATH}${normalizedPath}`; } diff --git a/src/lib/source.ts b/src/lib/source.ts index 5231595..b724890 100644 --- a/src/lib/source.ts +++ b/src/lib/source.ts @@ -1,5 +1,6 @@ import { docs } from "fumadocs-mdx:collections/server"; import { type InferPageType, loader } from "fumadocs-core/source"; +import { assetPath } from "./base-path"; export const source = loader({ baseUrl: "/", @@ -12,7 +13,7 @@ export function getPageImage(page: InferPageType) { return { segments, - url: `/og/${segments.join("/")}`, + url: assetPath(`/og/${segments.join("/")}`), }; } diff --git a/src/mdx-components.tsx b/src/mdx-components.tsx index 13cb3fd..3902aff 100644 --- a/src/mdx-components.tsx +++ b/src/mdx-components.tsx @@ -2,6 +2,7 @@ import { CodeBlock, Pre } from "fumadocs-ui/components/codeblock"; import { ImageZoom } from "fumadocs-ui/components/image-zoom"; import defaultMdxComponents from "fumadocs-ui/mdx"; import type { MDXComponents } from "mdx/types"; +import { assetPath } from "@/lib/base-path"; export function getMDXComponents(components?: MDXComponents): MDXComponents { return { @@ -11,9 +12,11 @@ export function getMDXComponents(components?: MDXComponents): MDXComponents {
{props.children}
), - img: (props: React.ComponentProps) => ( - - ), + img: (props: React.ComponentProps) => { + const src = + typeof props.src === "string" ? assetPath(props.src) : props.src; + return ; + }, ...components, }; }