Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync #1299

Merged
merged 9 commits into from
Jan 19, 2025
Merged

Sync #1299

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 .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apps/docs/content/docs/headless/custom-source.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ description: Build your own content source

You can see examples to use Fumadocs with a CMS, which allows a nice experience on publishing content, and real-time update without re-building the app.

BaseHub: https://github.com/fuma-nama/fumadocs-basehub
Sanity: https://github.com/fuma-nama/fumadocs-sanity
- [BaseHub](https://github.com/fuma-nama/fumadocs-basehub)
- [Sanity](https://github.com/fuma-nama/fumadocs-sanity)

For a custom content source implementation, you will need:

Expand Down
20 changes: 10 additions & 10 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@radix-ui/react-popover": "^1.1.4",
"@radix-ui/react-slot": "^1.1.1",
"@radix-ui/react-tooltip": "^1.1.6",
"@shikijs/rehype": "^1.26.2",
"@shikijs/rehype": "^1.27.2",
"@theguild/remark-mermaid": "^0.2.0",
"class-variance-authority": "^0.7.1",
"fumadocs-core": "workspace:*",
Expand All @@ -30,10 +30,10 @@
"fumadocs-ui": "workspace:*",
"geist": "^1.3.1",
"hast-util-to-jsx-runtime": "^2.3.2",
"katex": "^0.16.20",
"lucide-react": "^0.471.1",
"next": "15.1.4",
"oxc-transform": "^0.46.0",
"katex": "^0.16.21",
"lucide-react": "^0.473.0",
"next": "15.1.5",
"oxc-transform": "^0.47.0",
"phenomenon": "^1.6.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
Expand All @@ -45,18 +45,18 @@
"remark-rehype": "^11.1.1",
"remark-stringify": "^11.0.0",
"scroll-into-view-if-needed": "^3.1.0",
"shiki": "^1.27.0",
"shiki": "^1.27.2",
"tailwind-merge": "^2.6.0",
"zod": "^3.24.1"
},
"devDependencies": {
"@fumadocs/cli": "workspace:*",
"@next/bundle-analyzer": "15.1.4",
"@next/env": "15.1.4",
"@next/eslint-plugin-next": "15.1.4",
"@next/bundle-analyzer": "15.1.5",
"@next/env": "15.1.5",
"@next/eslint-plugin-next": "15.1.5",
"@types/hast": "^3.0.4",
"@types/mdx": "^2.0.13",
"@types/node": "22.10.6",
"@types/node": "22.10.7",
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
"autoprefixer": "^10.4.20",
Expand Down
2 changes: 1 addition & 1 deletion examples/content-collections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@fumadocs/content-collections": "workspace:*",
"fumadocs-core": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "^15.1.4",
"next": "^15.1.5",
"react": "19.0.0",
"react-dom": "19.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"fumadocs-core": "workspace:*",
"fumadocs-mdx": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "15.1.4",
"next": "15.1.5",
"react": "19.0.0",
"react-dom": "19.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/next-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"fumadocs-core": "workspace:*",
"fumadocs-mdx": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "15.1.4",
"next": "15.1.5",
"react": "19.0.0",
"react-dom": "19.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"fumadocs-mdx": "workspace:*",
"fumadocs-openapi": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "15.1.4",
"next": "15.1.5",
"postcss": "^8.5.1",
"react": "19.0.0",
"react-dom": "19.0.0",
"shiki": "^1.27.0",
"shiki": "^1.27.2",
"tailwindcss": "^3.4.17",
"zod": "^3.24.1"
},
Expand Down
13 changes: 8 additions & 5 deletions examples/remote-mdx/app/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ export default async function Page(props: {
const page = await getPage(params.slug);
if (!page) notFound();

const { frontmatter, content, toc } = await compileMDX<Frontmatter>({
const {
frontmatter,
body: MdxContent,
toc,
} = await compileMDX<Frontmatter>({
filePath: page.path,
source: page.content,
components: {
...defaultComponents,
},
});

return (
<DocsPage toc={toc}>
<DocsTitle>{frontmatter.title}</DocsTitle>
<DocsDescription>{frontmatter.description}</DocsDescription>
<DocsBody>{content}</DocsBody>
<DocsBody>
<MdxContent components={{ ...defaultComponents }} />
</DocsBody>
</DocsPage>
);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/remote-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"fast-glob": "^3.3.3",
"fumadocs-core": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "15.1.4",
"next": "15.1.5",
"react": "19.0.0",
"react-dom": "19.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"eslint": "^9.18.0",
"eslint-plugin-react": "^7.37.4",
"eslint-plugin-react-hooks": "5.1.0",
"eslint-plugin-tailwindcss": "^3.17.5",
"eslint-plugin-tailwindcss": "^3.18.0",
"prettier": "^3.4.2",
"rimraf": "^6.0.1",
"tsup": "8.3.5",
"turbo": "2.3.3",
"typescript": "^5.7.3",
"typescript-eslint": "^8.20.0",
"vitest": "^2.1.8"
"vitest": "^3.0.2"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"devDependencies": {
"@types/cross-spawn": "^6.0.6",
"@types/node": "22.10.6",
"@types/node": "22.10.7",
"@types/react": "^19.0.7",
"eslint-config-custom": "workspace:*",
"fast-glob": "^3.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/content-collections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"devDependencies": {
"@content-collections/core": "^0.8.0",
"@content-collections/mdx": "^0.2.0",
"@types/node": "22.10.6",
"@types/node": "22.10.7",
"eslint-config-custom": "workspace:*",
"fumadocs-core": "workspace:*",
"tsconfig": "workspace:*",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# next-docs-zeta

## 14.7.5

### Patch Changes

- 777188b: [Page Tree Builder] Inline folders without children

## 14.7.4

### Patch Changes
Expand Down
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fumadocs-core",
"version": "14.7.4",
"version": "14.7.5",
"description": "The library for building a documentation website in Next.js",
"keywords": [
"NextJs",
Expand Down Expand Up @@ -86,7 +86,7 @@
"dependencies": {
"@formatjs/intl-localematcher": "^0.5.10",
"@orama/orama": "^2.1.1",
"@shikijs/rehype": "^1.26.2",
"@shikijs/rehype": "^1.27.2",
"github-slugger": "^2.0.0",
"hast-util-to-estree": "^3.1.1",
"hast-util-to-jsx-runtime": "^2.3.2",
Expand All @@ -96,7 +96,7 @@
"remark": "^15.0.0",
"remark-gfm": "^4.0.0",
"scroll-into-view-if-needed": "^3.1.0",
"shiki": "^1.27.0",
"shiki": "^1.27.2",
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
Expand All @@ -108,14 +108,14 @@
"@types/hast": "^3.0.4",
"@types/mdast": "^4.0.3",
"@types/negotiator": "^0.6.3",
"@types/node": "22.10.6",
"@types/node": "22.10.7",
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
"algoliasearch": "4.24.0",
"eslint-config-custom": "workspace:*",
"mdast-util-mdx-jsx": "^3.2.0",
"mdast-util-mdxjs-esm": "^2.0.1",
"next": "^15.1.4",
"next": "^15.1.5",
"remark-mdx": "^3.1.0",
"remark-rehype": "^11.1.1",
"shiki-transformers": "^1.0.1",
Expand Down
28 changes: 20 additions & 8 deletions packages/core/src/source/page-tree-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const rest = '...';
const extractPrefix = '...';
const excludePrefix = '!';

function isPageFile(node: Folder | File): node is PageFile {
return 'data' in node && node.format === 'page';
}

/**
* @param nodes - All nodes to be built
* @param ctx - Context
Expand All @@ -76,7 +80,7 @@ function buildAll(
for (const node of [...nodes].sort((a, b) =>
a.file.name.localeCompare(b.file.name),
)) {
if ('data' in node && node.format === 'page' && !node.file.locale) {
if (isPageFile(node) && !node.file.locale) {
const treeNode = buildFileNode(node, ctx);

if (node.file.name === 'index') {
Expand All @@ -88,7 +92,15 @@ function buildAll(
}

if ('children' in node) {
folders.push(buildFolderNode(node, false, ctx));
if (
node.children.length === 1 &&
node.children[0].file.name === 'index' &&
isPageFile(node.children[0])
) {
output.push(buildFileNode(node.children[0], ctx));
} else {
folders.push(buildFolderNode(node, false, ctx));
}
}
}

Expand All @@ -104,19 +116,19 @@ function resolveFolderItem(
): PageTree.Node[] | '...' {
if (item === rest) return '...';

const separateResult = separator.exec(item);
if (separateResult?.groups) {
let match = separator.exec(item);
if (match?.groups) {
const node: PageTree.Separator = {
type: 'separator',
name: separateResult.groups.name,
name: match.groups.name,
};

return [ctx.options.attachSeparator?.(node) ?? node];
}

const linkResult = link.exec(item);
if (linkResult?.groups) {
const { icon, url, name } = linkResult.groups;
match = link.exec(item);
if (match?.groups) {
const { icon, url, name } = match.groups;
const isRelative =
url.startsWith('/') || url.startsWith('#') || url.startsWith('.');

Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/utils/remove-undefined.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export function removeUndefined<T extends object>(value: T): T {
const obj = value as Record<string, unknown>;
Object.keys(obj).forEach((key) => {

for (const key of Object.keys(obj)) {
if (obj[key] === undefined) delete obj[key];
});
}

return value;
}
45 changes: 45 additions & 0 deletions packages/core/test/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,48 @@ test('Internationalized Routing: Hide Prefix', () => {
expect(result.getPage(['test'])?.url).toBe('/test');
expect(result.getPage(['test'], 'cn')?.url).toBe('/cn/test');
});

test('Loader: Without meta.json', () => {
const result = loader({
baseUrl: '/',
pageTree: {
noRef: true,
},
source: {
files: [
{
type: 'page',
path: 'test.mdx',
data: {
title: 'Hello',
},
},
{
type: 'page',
path: 'hello/index.mdx',
data: {
title: 'Hello',
},
},
],
},
});

expect(result.pageTree, 'Page Tree').toMatchInlineSnapshot(`
{
"children": [
{
"name": "Hello",
"type": "page",
"url": "/hello",
},
{
"name": "Hello",
"type": "page",
"url": "/test",
},
],
"name": "",
}
`);
});
4 changes: 2 additions & 2 deletions packages/create-app-versions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"@content-collections/mdx": "^0.2.0",
"@content-collections/next": "^0.2.4",
"@types/mdx": "^2.0.13",
"@types/node": "22.10.6",
"@types/node": "22.10.7",
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
"autoprefixer": "^10.4.20",
"next": "15.1.4",
"next": "15.1.5",
"postcss": "^8.5.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/create-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# create-next-docs-app

## 14.7.5

## 14.7.4

## 14.7.3
Expand Down
4 changes: 2 additions & 2 deletions packages/create-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-fumadocs-app",
"version": "14.7.4",
"version": "14.7.5",
"description": "Create a new documentation site with Fumadocs",
"keywords": [
"NextJs",
Expand Down Expand Up @@ -33,7 +33,7 @@
},
"devDependencies": {
"@types/cross-spawn": "^6.0.6",
"@types/node": "22.10.6",
"@types/node": "22.10.7",
"eslint-config-custom": "workspace:*",
"fast-glob": "^3.3.3",
"tsconfig": "workspace:*"
Expand Down
Loading
Loading