From e8e74a1a8dc2b42ccead7f5da6e4354754298a03 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 20 Apr 2024 00:44:40 +0100 Subject: [PATCH] hide api link in navbar on mobile --- src/app/components/navbar.tsx | 12 ++++-- src/common/documentation.ts | 75 ++++++++++++++++++++++------------- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/src/app/components/navbar.tsx b/src/app/components/navbar.tsx index 21e3219..b996a8f 100644 --- a/src/app/components/navbar.tsx +++ b/src/app/components/navbar.tsx @@ -8,6 +8,7 @@ import Logo from "./logo"; import { ToggleThemeButton } from "./theme-toggle-button"; import { GithubStar } from "@/app/components/github-star"; import { Card } from "@/app/components/card"; +import { cn } from "@/common/utils"; type Page = { /** @@ -20,6 +21,11 @@ type Page = { */ url: string; + /** + * Whether to hide the button on mobile. + */ + hideOnMobile?: boolean; + /** * Whether clicking the button will * open the link in a new tab. @@ -31,7 +37,7 @@ const pages: Page[] = [ { name: "Player", url: "/player" }, { name: "Server", url: "/server/java" }, { name: "Mojang", url: "/mojang/status" }, - { name: "API", url: "https://api.mcutils.xyz", openInNewTab: true }, + { name: "API", url: "https://api.mcutils.xyz", hideOnMobile: true, openInNewTab: true }, { name: "Docs", url: "/documentation" }, ]; @@ -47,7 +53,7 @@ export default function NavBar(): ReactElement {
-

Minecraft Utilities

+

Minecraft Utilities

@@ -59,7 +65,7 @@ export default function NavBar(): ReactElement { return ( { + const { metadata, content } = parseFrontmatter(getDocumentationFileContent(file)); + let slug = path.basename(file, path.extname(file)); + + return { + metadata, + content, + slug, + }; + }); +} + +/** + * Parses the frontmatter of a file. + * + * @param fileContent the content of the file. + */ function parseFrontmatter(fileContent: string) { let frontmatterRegex = /---\s*([\s\S]*?)\s*---/; let match = frontmatterRegex.exec(fileContent); @@ -22,31 +69,3 @@ function parseFrontmatter(fileContent: string) { return { metadata: metadata as Metadata, content }; } - -const documentationDirectory = path.join(process.cwd(), "documentation"); - -/** - * Gets the files for the documentation. - */ -function getDocumentationFiles() { - return fs.readdirSync(documentationDirectory); -} - -function getDocumentationFileContent(file: string) { - return fs.readFileSync(path.join(documentationDirectory, file), "utf-8"); -} - -export function getDocumentation() { - const files = getDocumentationFiles(); - - return files.map(file => { - const { metadata, content } = parseFrontmatter(getDocumentationFileContent(file)); - let slug = path.basename(file, path.extname(file)); - - return { - metadata, - content, - slug, - }; - }); -}