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
2 changes: 1 addition & 1 deletion app/[...slug]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '../global.css';
import {RootProvider} from 'fumadocs-ui/provider';
import {RootProvider} from 'fumadocs-ui/provider/next';
import {Inter} from 'next/font/google';
import type {ReactNode} from 'react';
import {source} from "@/lib/source";
Expand Down
28 changes: 20 additions & 8 deletions app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,28 @@ export async function generateMetadata(props: {
};
}

type InferSource = typeof source;
type InferPage = NonNullable<ReturnType<typeof source.getPage>>;

function createRelativeLinkWithFilenameOnly(
source: LoaderOutput<LoaderConfig>,
page: Page,
sourceInst: InferSource,
page: InferPage,
): FC<ComponentProps<'a'>> {
return async function RelativeLink({href, ...props}) {
const relativeLink = createRelativeLink(source, page)
// support filename-only links
if (href && (!href.startsWith('http') && href.endsWith('.md'))) {
return relativeLink({href: `./${href}`, ...props});
const RelativeLinkBase = createRelativeLink(sourceInst, page);

return function RelativeLink({ href, ...props }) {
if (!href || href.startsWith('http')) {
return <RelativeLinkBase {...props} href={href} />;
}
return relativeLink({href, ...props});

let finalHref = href;

const [path, hash] = href.split('#');

if (path.endsWith('.md')) {
finalHref = `./${path}${hash ? `#${hash.toLowerCase()}` : ''}`;
}

return <RelativeLinkBase {...props} href={finalHref} />;
};
}
10 changes: 9 additions & 1 deletion lib/source.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import {docs} from '@/.source';
import {docs} from '@/.source/server';
import {loader} from 'fumadocs-core/source';
import * as tablerIcons from '@tabler/icons-react';
import { createElement } from 'react';

// See https://fumadocs.vercel.app/docs/headless/source-api for more info
export const source = loader({
// it assigns a URL to your pages
baseUrl: '/',
source: docs.toFumadocsSource(),
icon(icon) {
const tablerName = `${icon}`;
if (tablerName in tablerIcons) {
return createElement(tablerIcons[tablerName as keyof typeof tablerIcons] as any);
}
}
});
Loading