-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
116 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,15 @@ | ||
"use client"; | ||
import { ReactNode } from "react"; | ||
|
||
import { ReactNode, useEffect } from "react"; | ||
import { PythonProvider } from "react-py"; | ||
|
||
import { useNavStyleStore } from "@/stores/use-nav-style-store"; | ||
import { sidebarLinks } from "@/constants/sidebar-links"; | ||
|
||
import DocsWrapper from "@/components/docs-wrapper"; | ||
import Sidebar from "@/components/sidebar"; | ||
|
||
export default function MdxLayout({ children }: { children: ReactNode }) { | ||
const { setDocsStyle } = useNavStyleStore(); | ||
const packages = { | ||
micropip: ["OpenSeriesBellshade"] | ||
}; | ||
|
||
useEffect(() => { | ||
setDocsStyle(); | ||
}, [setDocsStyle]); | ||
|
||
export default async function MdxLayout({ children }: { children: ReactNode }) { | ||
return ( | ||
<PythonProvider packages={packages}> | ||
<Sidebar /> | ||
<main className="prose prose-indigo max-w-none overflow-y-auto rounded-xl p-8 dark:prose-invert prose-pre:border prose-img:w-full prose-img:rounded-xl dark:prose-h1:bg-clip-text dark:prose-h1:font-bold dark:prose-pre:border-zinc-700 lg:pl-80"> | ||
{children} | ||
</main> | ||
</PythonProvider> | ||
<> | ||
<Sidebar sidebarLinks={sidebarLinks} /> | ||
<DocsWrapper>{children}</DocsWrapper> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use client"; | ||
|
||
import { ReactNode, useEffect } from "react"; | ||
import { PythonProvider } from "react-py"; | ||
|
||
import { useNavStyleStore } from "@/stores/use-nav-style-store"; | ||
|
||
export default function DocsWrapper({ children }: { children: ReactNode }) { | ||
const { setDocsStyle } = useNavStyleStore(); | ||
const packages = { | ||
micropip: ["OpenSeriesBellshade"] | ||
}; | ||
|
||
useEffect(() => { | ||
setDocsStyle(); | ||
}, [setDocsStyle]); | ||
|
||
return ( | ||
<PythonProvider packages={packages}> | ||
<main className="prose prose-indigo max-w-none overflow-y-auto rounded-xl p-8 dark:prose-invert prose-pre:border prose-img:w-full prose-img:rounded-xl dark:prose-h1:bg-clip-text dark:prose-h1:font-bold dark:prose-pre:border-zinc-700 lg:pl-[21rem]"> | ||
{children} | ||
</main> | ||
</PythonProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { getDocs } from "@/utils/get-docs"; | ||
|
||
export const sidebarLinks = getDocs({ "get started": ["tentang"] }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { globSync } from "fast-glob"; | ||
|
||
export type DocumentGroup = { | ||
[key: string]: { | ||
title: string; | ||
link: string; | ||
}[]; | ||
}; | ||
|
||
type PrioritizedCategories = { | ||
[category: string]: string[]; | ||
}; | ||
|
||
export const getDocs = (prioritizedCategories: PrioritizedCategories) => { | ||
const documentPaths = getDocumentPaths(); | ||
const documentGroup = groupDocumentsByCategory(documentPaths); | ||
const sortedDocuments = prioritizeAndSortDocuments(documentGroup, prioritizedCategories); | ||
return sortedDocuments; | ||
}; | ||
|
||
const getDocumentPaths = () => globSync("app/docs/**/**/*.mdx"); | ||
|
||
const groupDocumentsByCategory = (documentPaths: string[]): DocumentGroup => { | ||
const documentGroup: DocumentGroup = {}; | ||
documentPaths.forEach((path) => { | ||
const match = path.match(/app\/docs\/([\w-]+)\/([\w-]+)\/page\.mdx/); | ||
if (!match || match.length < 3) return; | ||
|
||
const [, category, title] = match; | ||
const formattedCategory = category.replace(/-/g, " "); | ||
const formattedTitle = title.replace(/-/g, " "); | ||
const link = `/docs/${category}/${title}`; | ||
|
||
const categoryKey = formattedCategory.toUpperCase(); | ||
documentGroup[categoryKey] = [...(documentGroup[categoryKey] || []), { title: formattedTitle, link }]; | ||
}); | ||
return documentGroup; | ||
}; | ||
|
||
const prioritizeAndSortDocuments = ( | ||
documentGroup: DocumentGroup, | ||
prioritizedCategories: PrioritizedCategories | ||
): DocumentGroup => { | ||
const sortedDocuments: DocumentGroup = {}; | ||
|
||
Object.entries(prioritizedCategories).forEach(([category, links]) => { | ||
const categoryKey = category.toUpperCase(); | ||
if (documentGroup[categoryKey]) { | ||
sortedDocuments[categoryKey] = documentGroup[categoryKey].sort((a, b) => | ||
links.includes(a.title.toLowerCase()) ? -1 : links.includes(b.title.toLowerCase()) ? 1 : 0 | ||
); | ||
delete documentGroup[categoryKey]; | ||
} | ||
}); | ||
|
||
Object.assign(sortedDocuments, documentGroup); | ||
|
||
return sortedDocuments; | ||
}; |