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

import { useEffect, useRef } from "react";

export function GiscusComments() {
const containerRef = useRef<HTMLDivElement>(null);

useEffect(() => {
const container = containerRef.current;
if (!container) {
return;
}

const script = document.createElement("script");
script.src = "https://giscus.app/client.js";
script.async = true;
script.crossOrigin = "anonymous";
script.setAttribute("data-repo", "InvolutionHell/involutionhell.github.io");
script.setAttribute("data-repo-id", "R_kgDOPuD_8A");
script.setAttribute("data-category", "Comments");
script.setAttribute("data-category-id", "DIC_kwDOPuD_8M4Cvip8");
script.setAttribute("data-mapping", "pathname");
script.setAttribute("data-strict", "0");
script.setAttribute("data-reactions-enabled", "1");
script.setAttribute("data-emit-metadata", "0");
script.setAttribute("data-input-position", "bottom");
script.setAttribute("data-theme", "preferred_color_scheme");
script.setAttribute("data-lang", "en");

container.appendChild(script);

return () => {
while (container.firstChild) {
container.removeChild(container.firstChild);
}
};
}, []);

return <div ref={containerRef} className="giscus" />;
}
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: 1 addition & 1 deletion app/docs/ai/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ tags:
- 方法论学习:科研指南、论文阅读
- 杂项工具:开发工具、平台使用

> 注意:论文合集可邀请到 Zotero 协作;“TODO” 代表待施工项目。
> 注意:论文合集可邀请到 Zotero 协作;
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
Loading