forked from apache/zookeeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
180 lines (166 loc) · 6.22 KB
/
Copy pathindex.tsx
File metadata and controls
180 lines (166 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import { docs } from "@/.source";
import { toClientRenderer } from "fumadocs-mdx/runtime/vite";
import { DocsLayout } from "@/components/docs/layout/docs";
import {
DocsBody as FumaDocsBody,
DocsDescription as FumaDocsDescription,
DocsPage as FumaDocsPage,
DocsTitle as FumaDocsTitle
} from "@/components/docs/layout/docs/page";
import defaultMdxComponents from "fumadocs-ui/mdx";
import type * as PageTree from "fumadocs-core/page-tree";
import type { BaseLayoutProps } from "fumadocs-ui/layouts/shared";
import { useParams } from "react-router";
import { getPageTreePeers } from "fumadocs-core/page-tree";
import { Card, Cards } from "fumadocs-ui/components/card";
import { Callout } from "fumadocs-ui/components/callout";
import { Step, Steps } from "fumadocs-ui/components/steps";
import { Link } from "@/components/link";
import { OlderDocsPicker } from "@/components/docs/older-docs-picker";
import type { MDXComponents } from "mdx/types";
import { getDocsBasePath, resolveDocsHref } from "@/lib/docs-paths";
import { SITE_URL } from "@/lib/site";
import { CURRENT_VERSION } from "@/lib/current-version";
// Extend default MDX components to include shared UI blocks globally.
// Note: We'll override the 'a' component in the renderer to handle route-specific logic
const baseMdxComponents: MDXComponents = {
...defaultMdxComponents,
p: (props) => <p className="wrap-anywhere" {...props} />,
h1: (props) => <h1 className="font-bold" {...props} />,
Callout,
Step,
Steps
};
export function baseOptions(): BaseLayoutProps {
return {
nav: {
// Archive docs builds run under a /doc/rX/ basename, so a bare "/" would
// resolve to the docs index rather than the site landing page. Point at
// the absolute site root there; in dev (BASE_URL === "/") an
// internal "/" already reaches the landing page.
url: import.meta.env.BASE_URL === "/" ? "/" : SITE_URL,
title: (
<div className="flex items-center gap-2">
<img
src={`${import.meta.env.BASE_URL}favicon.ico`}
alt="ZooKeeper favicon"
width={16}
height={16}
/>
<p>Apache ZooKeeper {CURRENT_VERSION}</p>
</div>
)
},
githubUrl: "https://github.com/apache/zookeeper/"
};
}
type DocsLoaderData = { path: string; url: string; tree: unknown };
const renderer = toClientRenderer(
docs.doc,
(
{
toc,
default: Mdx,
frontmatter,
pageTitle,
pageDescription
}: {
toc: any;
default: any;
frontmatter: { title?: string; description?: string };
pageTitle?: string;
pageDescription?: string;
},
{ tree }: { tree: PageTree.Root }
) => {
const route = useParams()["*"];
const baseGithubPath = "zookeeper-website/app/pages/_docs/docs/_mdx/";
const groupedRoutes = [
"developer/programmers-guide",
"admin-ops/administrators-guide"
];
const trimmedRoute = route?.endsWith("/") ? route?.slice(0, -1) : route;
const mdxFileRoute = `${trimmedRoute === "" ? "index" : trimmedRoute}.mdx`;
const isGroupedRoute =
!!trimmedRoute && groupedRoutes.includes(trimmedRoute);
const groupedRouteUrl = `${getDocsBasePath()}/${trimmedRoute}`;
const displayTitle = pageTitle ?? frontmatter.title;
const displayDescription = pageDescription ?? frontmatter.description;
// Use default Link component for all links (external links are handled by Link component)
const CustomLink = ({ href, children, ...rest }: any) => {
return (
<Link
to={typeof href === "string" ? resolveDocsHref(href) : href}
{...rest}
>
{children}
</Link>
);
};
const mdxComponents = {
...baseMdxComponents,
a: CustomLink
};
return (
<FumaDocsPage toc={toc} tableOfContent={{ style: "clerk" }}>
<title>{displayTitle + " | Zookeeper"}</title>
<meta name="description" content={displayDescription} />
<FumaDocsTitle>{displayTitle}</FumaDocsTitle>
<FumaDocsDescription>{displayDescription}</FumaDocsDescription>
<FumaDocsBody>
<Mdx components={mdxComponents} />
{route !== undefined && isGroupedRoute && (
// table of content for grouped routes
<div className="flex flex-col">
<p>In this section:</p>
<Cards>
{getPageTreePeers(tree, groupedRouteUrl).map((peer) => (
<Card key={peer.url} title={peer.name} href={peer.url}>
{peer.description}
</Card>
))}
</Cards>
</div>
)}
</FumaDocsBody>
{route !== undefined && (
<a
href={`https://github.com/apache/zookeeper/${baseGithubPath}${mdxFileRoute}`}
rel="noreferrer noopener"
target="_blank"
className="text-fd-secondary-foreground bg-fd-secondary hover:text-fd-accent-foreground hover:bg-fd-accent w-fit rounded-xl border p-2 text-sm font-medium transition-colors"
>
Edit on GitHub
</a>
)}
</FumaDocsPage>
);
}
);
export function DocsPage({ loaderData }: { loaderData: DocsLoaderData }) {
const { tree, path } = loaderData;
const Content = renderer[path];
const layoutOptions = baseOptions();
return (
<DocsLayout {...layoutOptions} tree={tree as PageTree.Root}>
<Content tree={tree as PageTree.Root} />
</DocsLayout>
);
}