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
28 changes: 28 additions & 0 deletions app/components/GiscusComments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use client';

import Giscus from '@giscus/react';

interface GiscusCommentsProps {
className?: string;
}

export function GiscusComments({ className }: GiscusCommentsProps) {
return (
<div className={className}>
<Giscus
repo="InvolutionHell/involutionhell.github.io"
repoId="R_kgDOPuD_8A"
category="Comments"
categoryId="DIC_kwDOPuD_8M4Cvip8"
mapping="pathname"
strict="0"
reactionsEnabled="1"
emitMetadata="0"
inputPosition="top"
theme="preferred_color_scheme"
lang="zh-CN"
loading="lazy"
/>
</div>
);
}
4 changes: 4 additions & 0 deletions app/docs/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DocsPage, DocsBody } from "fumadocs-ui/page";
import { notFound } from "next/navigation";
import type { Metadata } from "next";
import { getMDXComponents } from "@/mdx-components";
import { GiscusComments } from "@/app/components/GiscusComments";

interface Param {
params: Promise<{
Expand All @@ -27,6 +28,9 @@ export default async function DocPage({ params }: Param) {
{page.data.title}
</h1>
<Mdx components={getMDXComponents()} />
<section className="mt-16">
<GiscusComments />
</section>
</DocsBody>
</DocsPage>
);
Expand Down
2 changes: 0 additions & 2 deletions app/docs/ai/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,3 @@ tags:
- 生成模型:Diffusion Models
- 方法论学习:科研指南、论文阅读
- 杂项工具:开发工具、平台使用

> 注意:论文合集可邀请到 Zotero 协作;“TODO” 代表待施工项目。
53 changes: 51 additions & 2 deletions app/docs/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,66 @@ import { DocsLayout } from "fumadocs-ui/layouts/docs";
import { baseOptions } from "@/lib/layout.shared";
import type { ReactNode } from "react";
import { DocsRouteFlag } from "@/app/components/RouteFlags";
import type { PageTree } from "fumadocs-core/server";

function pruneEmptyFolders(root: PageTree.Root): PageTree.Root {
const transformNode = (node: PageTree.Node): PageTree.Node | null => {
if (node.type === "folder") {
const transformedChildren = node.children
.map(transformNode)
.filter((child): child is PageTree.Node => child !== null);

const index = node.index ? { ...node.index } : undefined;

if (transformedChildren.length > 0) {
return {
...node,
index,
children: transformedChildren,
};
}

if (index) {
return { ...index };
}

return null;
}

if (node.type === "separator") {
return { ...node };
}

return { ...node };
};

const transformRoot = (node: PageTree.Root): PageTree.Root => {
const children = node.children
.map(transformNode)
.filter((child): child is PageTree.Node => child !== null);

return {
...node,
children,
fallback: node.fallback ? transformRoot(node.fallback) : undefined,
};
};

return transformRoot(root);
}

export default function Layout({ children }: { children: ReactNode }) {
const tree = pruneEmptyFolders(source.pageTree);

return (
<>
{/* Add a class on <html> while in docs to adjust global backgrounds */}
<DocsRouteFlag />
<DocsLayout
tree={source.pageTree}
tree={tree}
{...baseOptions()}
sidebar={{
// 第一屏仅显示目录,不展开子目录
// Only show top-level items on first load
defaultOpenLevel: 0,
}}
>
Expand Down
Loading