Skip to content

Commit 4bb2f0a

Browse files
authored
Merge pull request #124 from code0-tech/feat/updates
Update imports and dependencies for improved functionality
2 parents 92edeb7 + b056a20 commit 4bb2f0a

6 files changed

Lines changed: 1627 additions & 1330 deletions

File tree

app/[...slug]/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import '../global.css';
2-
import {RootProvider} from 'fumadocs-ui/provider';
2+
import {RootProvider} from 'fumadocs-ui/provider/next';
33
import {Inter} from 'next/font/google';
44
import type {ReactNode} from 'react';
55
import {source} from "@/lib/source";

app/[...slug]/page.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,28 @@ export async function generateMetadata(props: {
5656
};
5757
}
5858

59+
type InferSource = typeof source;
60+
type InferPage = NonNullable<ReturnType<typeof source.getPage>>;
61+
5962
function createRelativeLinkWithFilenameOnly(
60-
source: LoaderOutput<LoaderConfig>,
61-
page: Page,
63+
sourceInst: InferSource,
64+
page: InferPage,
6265
): FC<ComponentProps<'a'>> {
63-
return async function RelativeLink({href, ...props}) {
64-
const relativeLink = createRelativeLink(source, page)
65-
// support filename-only links
66-
if (href && (!href.startsWith('http') && href.endsWith('.md'))) {
67-
return relativeLink({href: `./${href}`, ...props});
66+
const RelativeLinkBase = createRelativeLink(sourceInst, page);
67+
68+
return function RelativeLink({ href, ...props }) {
69+
if (!href || href.startsWith('http')) {
70+
return <RelativeLinkBase {...props} href={href} />;
6871
}
69-
return relativeLink({href, ...props});
72+
73+
let finalHref = href;
74+
75+
const [path, hash] = href.split('#');
76+
77+
if (path.endsWith('.md')) {
78+
finalHref = `./${path}${hash ? `#${hash.toLowerCase()}` : ''}`;
79+
}
80+
81+
return <RelativeLinkBase {...props} href={finalHref} />;
7082
};
7183
}

lib/source.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
import {docs} from '@/.source';
1+
import {docs} from '@/.source/server';
22
import {loader} from 'fumadocs-core/source';
3+
import * as tablerIcons from '@tabler/icons-react';
4+
import { createElement } from 'react';
35

46
// See https://fumadocs.vercel.app/docs/headless/source-api for more info
57
export const source = loader({
68
// it assigns a URL to your pages
79
baseUrl: '/',
810
source: docs.toFumadocsSource(),
11+
icon(icon) {
12+
const tablerName = `${icon}`;
13+
if (tablerName in tablerIcons) {
14+
return createElement(tablerIcons[tablerName as keyof typeof tablerIcons] as any);
15+
}
16+
}
917
});

0 commit comments

Comments
 (0)