Skip to content

Commit da0747a

Browse files
committed
Add documentation routing and layout for Roam and Obsidian (#928)
- Introduced a new `docsRouteMap.ts` file to manage documentation sections and redirects for Roam and Obsidian platforms. - Updated `next.config.ts` to include dynamic redirects based on the new route map. - Refactored the layout components for documentation pages to utilize a consistent theme layout. - Removed outdated `page.tsx` files for Roam and Obsidian, replacing them with new landing pages that leverage Nextra for content rendering. - Added new metadata and content files for various documentation sections, enhancing the overall documentation structure and accessibility.
1 parent 69bf42c commit da0747a

78 files changed

Lines changed: 2419 additions & 169 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { getPageMap } from "nextra/page-map";
2+
import DocsThemeLayout from "../_components/DocsThemeLayout";
3+
import "../../../(nextra)/nextra-css.css";
4+
import "nextra-theme-docs/style-prefixed.css";
5+
6+
type DocsLandingLayoutProps = {
7+
children: React.ReactNode;
8+
};
9+
10+
const DocsLandingLayout = async ({
11+
children,
12+
}: DocsLandingLayoutProps): Promise<React.ReactElement> => {
13+
const pageMap = await getPageMap("/docs");
14+
15+
return <DocsThemeLayout pageMap={pageMap}>{children}</DocsThemeLayout>;
16+
};
17+
18+
export default DocsLandingLayout;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { Metadata } from "next";
2+
import { notFound } from "next/navigation";
3+
import { importPage } from "nextra/pages";
4+
import { useMDXComponents } from "../../../../mdx-components";
5+
6+
type ImportedPage = Awaited<ReturnType<typeof importPage>>;
7+
8+
const { wrapper } = useMDXComponents();
9+
10+
const Wrapper = wrapper as React.ComponentType<{
11+
children: React.ReactNode;
12+
metadata: ImportedPage["metadata"];
13+
toc: ImportedPage["toc"];
14+
}>;
15+
16+
const loadPage = async (): Promise<ImportedPage> => importPage([]);
17+
18+
const Page = async (): Promise<React.ReactElement> => {
19+
try {
20+
const { default: MDXContent, metadata, toc } = await loadPage();
21+
22+
return (
23+
<Wrapper metadata={metadata} toc={toc}>
24+
<MDXContent params={{ mdxPath: [] }} />
25+
</Wrapper>
26+
);
27+
} catch (error) {
28+
console.error("Error rendering docs landing page:", error);
29+
notFound();
30+
}
31+
};
32+
33+
export const generateMetadata = async (): Promise<Metadata> => {
34+
try {
35+
const { metadata } = await loadPage();
36+
37+
return metadata;
38+
} catch (error) {
39+
console.error("Error generating docs landing metadata:", error);
40+
41+
return {
42+
title: "Docs",
43+
};
44+
}
45+
};
46+
47+
export default Page;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { PageMapItem } from "nextra";
2+
import { Footer, Layout, Navbar } from "nextra-theme-docs";
3+
import { Logo } from "~/components/Logo";
4+
5+
type DocsThemeLayoutProps = {
6+
children: React.ReactNode;
7+
pageMap: PageMapItem[];
8+
};
9+
10+
const DocsThemeLayout = ({
11+
children,
12+
pageMap,
13+
}: DocsThemeLayoutProps): React.ReactElement => {
14+
return (
15+
<div className="nextra-reset">
16+
<Layout
17+
editLink={null}
18+
feedback={{ content: null }}
19+
footer={
20+
<Footer>
21+
Apache 2.0 {new Date().getFullYear()} (c) Discourse Graphs.
22+
</Footer>
23+
}
24+
navbar={
25+
<Navbar
26+
logo={<Logo linked={false} textClassName="text-inherit" />}
27+
projectLink="https://github.com/DiscourseGraphs/discourse-graph"
28+
/>
29+
}
30+
pageMap={pageMap}
31+
sidebar={{
32+
defaultMenuCollapseLevel: 1,
33+
}}
34+
toc={{
35+
backToTop: "Back to top",
36+
}}
37+
>
38+
{children}
39+
</Layout>
40+
</div>
41+
);
42+
};
43+
44+
export default DocsThemeLayout;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import type { Metadata } from "next";
2+
import { notFound } from "next/navigation";
3+
import { generateStaticParamsFor, importPage } from "nextra/pages";
4+
import { useMDXComponents } from "../../../../../mdx-components";
5+
6+
type DocsPageProps = {
7+
params: Promise<{
8+
mdxPath?: string[];
9+
}>;
10+
};
11+
12+
type ImportedPage = Awaited<ReturnType<typeof importPage>>;
13+
14+
const { wrapper } = useMDXComponents();
15+
16+
const Wrapper = wrapper as React.ComponentType<{
17+
children: React.ReactNode;
18+
metadata: ImportedPage["metadata"];
19+
toc: ImportedPage["toc"];
20+
}>;
21+
22+
const generateAllStaticParams = generateStaticParamsFor("mdxPath");
23+
24+
const loadPage = async (mdxPath?: string[]): Promise<ImportedPage> =>
25+
importPage(["obsidian", ...(mdxPath ?? [])]);
26+
27+
export const generateStaticParams = async (): Promise<
28+
Array<{ mdxPath?: string[] }>
29+
> => {
30+
const staticParams = await generateAllStaticParams();
31+
32+
return staticParams.flatMap(({ mdxPath }) => {
33+
if (!Array.isArray(mdxPath) || mdxPath[0] !== "obsidian") {
34+
return [];
35+
}
36+
37+
const platformPath = mdxPath.slice(1);
38+
39+
return platformPath.length ? [{ mdxPath: platformPath }] : [{}];
40+
});
41+
};
42+
43+
const Page = async ({ params }: DocsPageProps): Promise<React.ReactElement> => {
44+
try {
45+
const { mdxPath } = await params;
46+
const { default: MDXContent, metadata, toc } = await loadPage(mdxPath);
47+
48+
return (
49+
<Wrapper metadata={metadata} toc={toc}>
50+
<MDXContent params={{ mdxPath: mdxPath ?? [] }} />
51+
</Wrapper>
52+
);
53+
} catch (error) {
54+
console.error("Error rendering Obsidian docs page:", error);
55+
notFound();
56+
}
57+
};
58+
59+
export const generateMetadata = async ({
60+
params,
61+
}: DocsPageProps): Promise<Metadata> => {
62+
try {
63+
const { mdxPath } = await params;
64+
const { metadata } = await loadPage(mdxPath);
65+
66+
return metadata;
67+
} catch (error) {
68+
console.error("Error generating Obsidian docs metadata:", error);
69+
70+
return {
71+
title: "Obsidian docs",
72+
};
73+
}
74+
};
75+
76+
export default Page;

apps/website/app/(docs)/docs/obsidian/[slug]/page.tsx

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
import { navigation } from "./navigation";
2-
import { Layout } from "~/components/DocsLayout";
1+
import { getPageMap } from "nextra/page-map";
2+
import DocsThemeLayout from "../_components/DocsThemeLayout";
3+
import "../../../(nextra)/nextra-css.css";
4+
import "nextra-theme-docs/style-prefixed.css";
35

4-
export default function RootLayout({
5-
children,
6-
}: {
6+
type ObsidianDocsLayoutProps = {
77
children: React.ReactNode;
8-
}) {
9-
return <Layout navigationList={navigation}>{children}</Layout>;
10-
}
8+
};
9+
10+
const ObsidianDocsLayout = async ({
11+
children,
12+
}: ObsidianDocsLayoutProps): Promise<React.ReactElement> => {
13+
const pageMap = await getPageMap("/docs/obsidian");
14+
15+
return <DocsThemeLayout pageMap={pageMap}>{children}</DocsThemeLayout>;
16+
};
17+
18+
export default ObsidianDocsLayout;

apps/website/app/(docs)/docs/obsidian/page.tsx

Lines changed: 0 additions & 6 deletions
This file was deleted.

apps/website/app/(docs)/docs/page.tsx

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import type { Metadata } from "next";
2+
import { notFound } from "next/navigation";
3+
import { generateStaticParamsFor, importPage } from "nextra/pages";
4+
import { useMDXComponents } from "../../../../../mdx-components";
5+
6+
type DocsPageProps = {
7+
params: Promise<{
8+
mdxPath?: string[];
9+
}>;
10+
};
11+
12+
type ImportedPage = Awaited<ReturnType<typeof importPage>>;
13+
14+
const { wrapper } = useMDXComponents();
15+
16+
const Wrapper = wrapper as React.ComponentType<{
17+
children: React.ReactNode;
18+
metadata: ImportedPage["metadata"];
19+
toc: ImportedPage["toc"];
20+
}>;
21+
22+
const generateAllStaticParams = generateStaticParamsFor("mdxPath");
23+
24+
const loadPage = async (mdxPath?: string[]): Promise<ImportedPage> =>
25+
importPage(["roam", ...(mdxPath ?? [])]);
26+
27+
export const generateStaticParams = async (): Promise<
28+
Array<{ mdxPath?: string[] }>
29+
> => {
30+
const staticParams = await generateAllStaticParams();
31+
32+
return staticParams.flatMap(({ mdxPath }) => {
33+
if (!Array.isArray(mdxPath) || mdxPath[0] !== "roam") {
34+
return [];
35+
}
36+
37+
const platformPath = mdxPath.slice(1);
38+
39+
return platformPath.length ? [{ mdxPath: platformPath }] : [{}];
40+
});
41+
};
42+
43+
const Page = async ({ params }: DocsPageProps): Promise<React.ReactElement> => {
44+
try {
45+
const { mdxPath } = await params;
46+
const { default: MDXContent, metadata, toc } = await loadPage(mdxPath);
47+
48+
return (
49+
<Wrapper metadata={metadata} toc={toc}>
50+
<MDXContent params={{ mdxPath: mdxPath ?? [] }} />
51+
</Wrapper>
52+
);
53+
} catch (error) {
54+
console.error("Error rendering Roam docs page:", error);
55+
notFound();
56+
}
57+
};
58+
59+
export const generateMetadata = async ({
60+
params,
61+
}: DocsPageProps): Promise<Metadata> => {
62+
try {
63+
const { mdxPath } = await params;
64+
const { metadata } = await loadPage(mdxPath);
65+
66+
return metadata;
67+
} catch (error) {
68+
console.error("Error generating Roam docs metadata:", error);
69+
70+
return {
71+
title: "Roam docs",
72+
};
73+
}
74+
};
75+
76+
export default Page;

0 commit comments

Comments
 (0)