Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const config = {
unoptimized: true,
},
basePath: BASE_PATH,
assetPrefix: BASE_PATH,
env: {
NEXT_PUBLIC_BASE_PATH: BASE_PATH,
},
Expand Down
14 changes: 13 additions & 1 deletion public/_redirects
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/app/robots.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
2 changes: 1 addition & 1 deletion src/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
4 changes: 2 additions & 2 deletions src/lib/base-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}`;
}
3 changes: 2 additions & 1 deletion src/lib/source.ts
Original file line number Diff line number Diff line change
@@ -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: "/",
Expand All @@ -12,7 +13,7 @@ export function getPageImage(page: InferPageType<typeof source>) {

return {
segments,
url: `/og/${segments.join("/")}`,
url: assetPath(`/og/${segments.join("/")}`),
};
}

Expand Down
9 changes: 6 additions & 3 deletions src/mdx-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -11,9 +12,11 @@ export function getMDXComponents(components?: MDXComponents): MDXComponents {
<Pre>{props.children}</Pre>
</CodeBlock>
),
img: (props: React.ComponentProps<typeof ImageZoom>) => (
<ImageZoom {...props} />
),
img: (props: React.ComponentProps<typeof ImageZoom>) => {
const src =
typeof props.src === "string" ? assetPath(props.src) : props.src;
return <ImageZoom {...props} src={src} />;
},
...components,
};
}
Loading