diff --git a/documentation/landing.md b/documentation/landing.md index 5f8a39c..34b1be0 100644 --- a/documentation/landing.md +++ b/documentation/landing.md @@ -1,11 +1,15 @@ --- -title: +title: Minecraft Utilities Documentation +description: Welcome to the Minecraft Utilities documentation! Here you can find information on how to use the various features of the plugin. --- -# Minecraft Utilities Documentation +# Getting Started -Welcome to the Minecraft Utilities documentation! Here you can find information on how to use the various features of the plugin. +This is still a work in progress, so please be patient as we continue to add more documentation. -## Getting Started +## Libraries -This is still a work in progress, so please be patient as we continue to add more documentation. \ No newline at end of file +We offer a few different libraries for different languages to help you get started with the Minecraft Utilities plugin. + +- [Java](/documentation/libraries/java) +- [JavaScript](/documentation/libraries/javascript) \ No newline at end of file diff --git a/documentation/libraries/java.md b/documentation/libraries/java.md new file mode 100644 index 0000000..a7943d2 --- /dev/null +++ b/documentation/libraries/java.md @@ -0,0 +1,42 @@ +--- +title: Java Library +description: The Java library for Minecraft Utilities is a simple way to interact with the plugin from using Java! +--- + +# Java Library + +This is the Java library for Minecraft Utilities. + +## Installation + +To use the Java library, you can add the following to your `pom.xml` file: + +```xml + + + fascinated-repo-public + Fascinated's Repository + https://repo.fascinated.cc/public + + + + + + xyz.mcutils + mcutils-java-library + 1.1.1 + + +``` + +## Usage + +This is a simple example of how to use the Java library to get a player's information. + +```java +public class Main { + public static void main(String[] args) { + System.out.println(McUtilsAPI.getPlayer("Notch")); + } +} +``` \ No newline at end of file diff --git a/documentation/libraries/javascript.md b/documentation/libraries/javascript.md new file mode 100644 index 0000000..0243ab3 --- /dev/null +++ b/documentation/libraries/javascript.md @@ -0,0 +1,28 @@ +--- +title: Javascript Library +description: The Javascript library for Minecraft Utilities is a simple way to interact with the plugin from using Javascript! +--- + +# Javascript Library + +This is the Javascript library for Minecraft Utilities. + +## Installation + +To use the Javascript library, you can run the following command: + +```bash +npm install mcutils-library +``` + +## Usage + +This is a simple example of how to use the Javascript library to get a player's information. + +```javascript +import { getPlayer, CachedPlayer } from "mcutils-library"; + +const cachedPlayer = await getPlayer(playerId); + +console.log(player); +``` \ No newline at end of file diff --git a/package.json b/package.json index d6d3254..ba41ff1 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "react-spinners": "^0.13.8", "react-syntax-highlighter": "^15.5.0", "react-use-websocket": "4.8.1", + "read-file": "^0.2.0", "remote-mdx": "^0.0.4", "tailwind-merge": "^2.2.2", "tailwindcss-animate": "^1.0.7" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9eb43a8..0294f7c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -95,6 +95,9 @@ dependencies: react-use-websocket: specifier: 4.8.1 version: 4.8.1(react-dom@18.2.0)(react@18.2.0) + read-file: + specifier: ^0.2.0 + version: 0.2.0 remote-mdx: specifier: ^0.0.4 version: 0.0.4(react@18.2.0) @@ -6494,6 +6497,11 @@ packages: dependencies: pify: 2.3.0 + /read-file@0.2.0: + resolution: {integrity: sha512-na/zgd5KplGlR+io+ygXQMIoDfX/Y0bNS5+P2TOXOTk5plquOVd0snudCd30hZJAsnVK2rxuxUP2z0CN+Aw1lQ==} + engines: {node: '>=0.8'} + dev: false + /readdirp@3.6.0: resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} engines: {node: '>=8.10.0'} diff --git a/src/app/(pages)/documentation/[[...slug]]/page.tsx b/src/app/(pages)/documentation/[[...slug]]/page.tsx index 98bc37b..c633a22 100644 --- a/src/app/(pages)/documentation/[[...slug]]/page.tsx +++ b/src/app/(pages)/documentation/[[...slug]]/page.tsx @@ -5,7 +5,7 @@ import { generateEmbed } from "@/common/embed"; type DocumentationPageParams = { params: { - slug?: string; + slug?: string[]; }; }; @@ -18,9 +18,16 @@ export async function generateStaticParams() { } export async function generateMetadata({ params: { slug } }: DocumentationPageParams): Promise { + const pageSlug = slug?.join("/"); const documentationPages = getDocumentation(); - let page = documentationPages.find(page => page.slug === slug); + let page = documentationPages.find(page => page.slug === pageSlug); + // Use the landing page on "/documentation" + if (!page && !slug) { + page = documentationPages.find(page => page.slug === "landing"); + } + + // Fallback to page not found if (!page) { return generateEmbed({ title: "Page not found", @@ -30,34 +37,37 @@ export async function generateMetadata({ params: { slug } }: DocumentationPagePa return generateEmbed({ title: page.metadata.title, - description: "Click to view this page", + description: `${page.metadata.description}\n\nClick to view this page`, }); } export default function Page({ params: { slug } }: DocumentationPageParams) { + const pageSlug = slug?.join("/"); const documentationPages = getDocumentation(); - let page = documentationPages.find(page => page.slug === slug); + let page = documentationPages.find(page => page.slug === pageSlug); - // Fallback to the landing page - if (!page) { + // Use the landing page on "/documentation" + if (!page && !slug) { page = documentationPages.find(page => page.slug === "landing"); } - // Fallback to a 404 page if we still can't find the page + // Page was not found, show an error page if (!page) { - page = { - metadata: { - title: "404 - Not Found", - }, - content: "If you are seeing this, it means that the documentation page you are looking for does not exist.", - slug: "empty", - }; + return ( +
+

Not Found

+

The page you are looking for was not found.

+
+ ); } return (
- {/* The documentation page title */} - {page.metadata.title &&

{page.metadata.title}

} + {/* The documentation page title and description */} +
+ {page.metadata.title &&

{page.metadata.title}

} + {page.metadata.description &&

{page.metadata.description}

} +
{/* The content of the documentation page */}
diff --git a/src/app/components/code-highlighter.tsx b/src/app/components/code-highlighter.tsx index e687d5f..b4f5c83 100644 --- a/src/app/components/code-highlighter.tsx +++ b/src/app/components/code-highlighter.tsx @@ -9,6 +9,11 @@ type CodeHighlighterProps = { */ code: string; + /** + * The language of the code. + */ + language?: string; + /** * Should the element be rounded? */ @@ -62,11 +67,11 @@ function rowRenderer({ }); } -export function CodeHighlighter({ code, rounded = true }: CodeHighlighterProps): ReactElement { +export function CodeHighlighter({ code, language = "json", rounded = true }: CodeHighlighterProps): ReactElement { return (
{ + const Tag = `h${level}`; + return ( +
1 ? "pt-6" : null)}> + + +
+ ); + }; +} + +/** + * The components to use in the MDX renderer. + */ const components = { - h1: (props: any) =>

, - h2: (props: any) =>

, + h1: (props: any) => createHeading(1)(props), + h2: (props: any) => createHeading(2)(props), + code: (props: any) => { + if (!props.className) { + return ; + } + + return ( +
+ +
+ ); + }, + ul: (props: any) =>
    {props.children}
, + a: (props: any) => ( + + {props.children} + + ), }; export function CustomMDX(props: any) { diff --git a/src/common/documentation.ts b/src/common/documentation.ts index 150d7ee..83969ba 100644 --- a/src/common/documentation.ts +++ b/src/common/documentation.ts @@ -1,11 +1,20 @@ +/* eslint-disable */ + import * as fs from "node:fs"; import path from "node:path"; +// @ts-ignore +import read from "read-file"; type Metadata = { /** * The title of the documentation page. */ title: string; + + /** + * The description of the documentation page. + */ + description?: string; }; /** @@ -14,10 +23,28 @@ type Metadata = { const documentationDirectory = path.join(process.cwd(), "documentation"); /** - * Gets the files for the documentation. + * Gets all the documentation files recursively. + * + * @param dirPath the directory path to search for documentation files. */ -function getDocumentationFiles() { - return fs.readdirSync(documentationDirectory); +function getDocumentationFiles(dirPath: string): string[] { + let files: string[] = []; + const items = fs.readdirSync(dirPath); + + items.forEach(item => { + const itemPath = path.join(dirPath, item); + const stat = fs.statSync(itemPath); + + if (stat.isDirectory()) { + // Recursively traverse directories + files.push(...getDocumentationFiles(itemPath)); + } else if (stat.isFile() && path.extname(item) === ".md") { + // Collect markdown files + files.push(itemPath); + } + }); + + return files; } /** @@ -26,18 +53,19 @@ function getDocumentationFiles() { * @param file the file to get the content of. */ function getDocumentationFileContent(file: string) { - return fs.readFileSync(path.join(documentationDirectory, file), "utf-8"); + return read.sync(file, "utf8"); } /** * Gets all the documentation pages. */ export function getDocumentation() { - const files = getDocumentationFiles(); + const files = getDocumentationFiles(documentationDirectory); return files.map(file => { const { metadata, content } = parseFrontmatter(getDocumentationFileContent(file)); - let slug = path.basename(file, path.extname(file)); + let slug = path.relative(documentationDirectory, file).replace(/\.(md)$/, ""); + slug = slug.replace(/\\/g, "/"); // Normalize path separators return { metadata, diff --git a/tailwind.config.ts b/tailwind.config.ts index bd7741d..b396c84 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -3,7 +3,13 @@ import defaultTheme from "tailwindcss/defaultTheme"; const config = { darkMode: ["class"], - content: ["./pages/**/*.{ts,tsx}", "./components/**/*.{ts,tsx}", "./app/**/*.{ts,tsx}", "./src/**/*.{ts,tsx}"], + content: [ + "./pages/**/*.{ts,tsx}", + "./components/**/*.{ts,tsx}", + "./app/**/*.{ts,tsx}", + "./src/**/*.{ts,tsx}", + "../documentation", + ], prefix: "", theme: { container: {