Skip to content

Commit a2b3a13

Browse files
authored
fix: more docs paths (#873)
1 parent 5f207a8 commit a2b3a13

File tree

6 files changed

+78
-29
lines changed

6 files changed

+78
-29
lines changed
Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
import Image from 'next/image';
2+
import { basePath } from '@/lib/basePath';
23

34
type FeatureItemProps = {
4-
title: string;
5-
description: React.ReactNode;
6-
imageSource: string;
5+
title: string;
6+
description: React.ReactNode;
7+
imageSource: string;
78
};
89

9-
export function FeatureItem({ title, description, imageSource }: FeatureItemProps) {
10-
return (
11-
<div className="flex flex-col items-center text-center p-6">
12-
<div className="mb-6 relative w-24 h-24 sm:w-32 sm:h-32">
13-
<Image
14-
src={imageSource}
15-
alt={title}
16-
fill
17-
className="object-contain drop-shadow-md"
18-
/>
19-
</div>
20-
<h3 className="font-heading text-2xl font-bold mb-4 text-primary dark:text-white">
21-
{title}
22-
</h3>
23-
<p className="feature-description leading-relaxed max-w-sm text-lg">
24-
{description}
25-
</p>
26-
</div>
27-
);
10+
export function FeatureItem({
11+
title,
12+
description,
13+
imageSource,
14+
}: FeatureItemProps) {
15+
return (
16+
<div className="flex flex-col items-center text-center p-6">
17+
<div className="mb-6 relative w-24 h-24 sm:w-32 sm:h-32">
18+
<Image
19+
src={`${basePath}${imageSource}`}
20+
alt={title}
21+
fill
22+
className="object-contain drop-shadow-md"
23+
/>
24+
</div>
25+
<h3 className="font-heading text-2xl font-bold mb-4 text-primary dark:text-white">
26+
{title}
27+
</h3>
28+
<p className="feature-description leading-relaxed max-w-sm text-lg">
29+
{description}
30+
</p>
31+
</div>
32+
);
2833
}

docs/components/mdx/Image.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import NextImage from 'next/image';
2+
import { basePath } from '@/lib/basePath';
3+
4+
interface ImageProps {
5+
src: string;
6+
alt: string;
7+
className?: string;
8+
width?: number;
9+
height?: number;
10+
}
11+
12+
export function Image({ src, alt, className, width = 800, height = 400 }: ImageProps) {
13+
const imageSrc = src.startsWith('/') ? `${basePath}${src}` : src;
14+
15+
return (
16+
<NextImage
17+
src={imageSrc}
18+
alt={alt}
19+
width={width}
20+
height={height}
21+
className={className}
22+
style={{ width: '100%', height: 'auto' }}
23+
/>
24+
);
25+
}

docs/content/docs/introduction/quick-start.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ title: Quick Start
33
description: Getting started with React Native Quick Crypto
44
---
55

6+
import { Image } from '@/components/mdx/Image';
67

7-
<img alt="react-native-quick-crypto" src="/img/banner-light.png" className="block dark:hidden" />
8-
<img alt="react-native-quick-crypto" src="/img/banner-dark.png" className="hidden dark:block" />
8+
<Image alt="react-native-quick-crypto" src="/img/banner-light.png" className="block dark:hidden" />
9+
<Image alt="react-native-quick-crypto" src="/img/banner-dark.png" className="hidden dark:block" />
910

1011
import { Step, Steps } from 'fumadocs-ui/components/steps';
1112
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';

docs/lib/basePath.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? '';

docs/mdx-components.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,25 @@ import type { MDXComponents } from 'mdx/types';
33
import { Mermaid } from '@/components/mdx/mermaid';
44
import * as Twoslash from 'fumadocs-twoslash/ui';
55
import NextImage from 'next/image';
6+
import { basePath } from '@/lib/basePath';
67

7-
function MdxImage(props: React.ComponentProps<'img'>) {
8+
function MdxImage(
9+
props: React.ComponentProps<'img'> & { src?: string | { src: string } },
10+
) {
811
const { src, alt, className } = props;
9-
if (!src || typeof src !== 'string') return null;
12+
13+
// Handle both string src and object src (fumadocs may pass either)
14+
const srcString = typeof src === 'string' ? src : src?.src;
15+
if (!srcString) return null;
16+
17+
// Only add basePath if not already present and path is absolute
18+
const needsBasePath =
19+
basePath && srcString.startsWith('/') && !srcString.startsWith(basePath);
20+
const imageSrc = needsBasePath ? `${basePath}${srcString}` : srcString;
1021

1122
return (
1223
<NextImage
13-
src={src}
24+
src={imageSrc}
1425
alt={alt ?? ''}
1526
width={800}
1627
height={400}

docs/next.config.mjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ import { createMDX } from 'fumadocs-mdx/next';
33
const withMDX = createMDX();
44

55
const isGitHubPages = process.env.GITHUB_ACTIONS === 'true';
6+
const basePath = isGitHubPages ? '/react-native-quick-crypto' : '';
67

78
/** @type {import('next').NextConfig} */
89
const config = {
910
reactStrictMode: true,
1011
output: 'export',
11-
basePath: isGitHubPages ? '/react-native-quick-crypto' : '',
12-
assetPrefix: isGitHubPages ? '/react-native-quick-crypto/' : '',
12+
basePath,
13+
images: {
14+
unoptimized: true,
15+
},
16+
env: {
17+
NEXT_PUBLIC_BASE_PATH: basePath,
18+
},
1319
};
1420

1521
export default withMDX(config);

0 commit comments

Comments
 (0)