diff --git a/src/app/[...slug]/page.tsx b/src/app/[...slug]/page.tsx index adc0561..04a64b5 100644 --- a/src/app/[...slug]/page.tsx +++ b/src/app/[...slug]/page.tsx @@ -1,16 +1,8 @@ -import { GetFilesTree, RemoveSuffix } from "@/features/functions"; -import { LoadThem, GetWikiPaths } from "@/features/getAllTopics"; -import { Image } from "@/mdx-components"; -import { readFileSync } from "fs"; +import { RemoveSuffix, getProfileInfo } from "@/features/functions"; +import { LoadThem, GetWikiPaths, meta_informations } from "@/features/getAllTopics"; import { Metadata } from "next"; type StaticSlugParams = { params: Awaited>[number] } -/* -const images: {[k: string]: {fileName: string, slugId: string}} = {}; -for (const file of GetFilesTree("./images")){ - const [base, imagesFolder, fileName] = file.split("/"); - images[fileName.split(".")[0]] = {fileName, slugId: fileName.split(".")[0]} -}*/ export async function generateStaticParams() { const slugs = []; for (const ss of GetWikiPaths()) { @@ -22,10 +14,29 @@ export async function generateStaticParams() { export default async function GetMarkdownPageView({ params }: StaticSlugParams) { const slg = params.slug; const [blogs, metadatas] = await LoadThem(); + const {displayName,author, tags = []} = metadatas[slg.join("/")] as {displayName: string, tags?: string[], author?: string} + const info = await getProfileInfo(author??""); const MdxData = blogs[slg.join("/")]; + const tagDefs = meta_informations.tags; return (
+
+

{displayName}

+ {info? +
+ {info} +
+ :undefined} +
+
+
+ {tags.map((e: string,i)=>{ + if(!(e in tagDefs)) return undefined; + const {color, display, "text-color": textColor} = tagDefs[e]; + return {display} + })} +
{/*
*/} @@ -37,4 +48,20 @@ export async function generateMetadata({ params }: StaticSlugParams): Promise x.charAt(0).toUpperCase() + x.substring(1)).join("->")} on Bedrock API Wiki` } +} +function Tag(data: {children?: any, color?: string, textColor?: string}){ + return
+

+ {data.children} +

+
+} +function AuthorInfo(data: {children: any}){ + return +

+ by + {data.children.name} +

+ +
} \ No newline at end of file diff --git a/src/app/layout.tsx b/src/app/layout.tsx index b3ea9a1..10a344e 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -4,7 +4,7 @@ import "../styles/globals.css"; import "../styles/codelights.css"; import Footer from "@/components/footer"; import { Metadata } from "next"; -import { LoadThem } from "@/features/getAllTopics"; +import { LoadThem, meta_informations } from "@/features/getAllTopics"; import { readFileSync } from "fs"; import BaseView from "@/components/BaseView"; import { URL } from "url"; @@ -27,10 +27,10 @@ export default async function RootLayout({ }) { const [blogs, metadatas] = await LoadThem(); const menus = {} as any; - const options = {tags: JSON.parse(readFileSync("./wiki/tags_definition.json").toString()), menus}; + const options = {tags: meta_informations.blog_kind, menus}; Object.keys(blogs).filter(e=>metadatas[e]?.displayName).forEach(e=>{ - const {tag="dev", displayName} = metadatas[e]??{}; - const m = menus[tag] = menus[tag]??[]; + const {kind="blog", displayName} = metadatas[e]??{}; + const m = menus[kind] = menus[kind]??[]; m.push({title:displayName, link: e}); }); return ( diff --git a/src/app/not-found.tsx b/src/app/not-found.tsx index 21cd563..e0d26dd 100644 --- a/src/app/not-found.tsx +++ b/src/app/not-found.tsx @@ -5,6 +5,7 @@ export default function NotFound(){

404 Not found


This is not page what are you looking for.

-
+ + } \ No newline at end of file diff --git a/src/components/aside/aside.tsx b/src/components/aside/aside.tsx index 2e20002..425da49 100644 --- a/src/components/aside/aside.tsx +++ b/src/components/aside/aside.tsx @@ -7,7 +7,7 @@ import { useEffect, useState } from "react"; export interface SideBarOptions { - tags: { [k: string]: { title: string, color?: string } } + tags: { [k: string]: { display: string, color?: string } } menus: { [k: string]: { title: string, link: string }[] } } export default function SideBar(params: { options: SideBarOptions }) { @@ -46,10 +46,14 @@ export default function SideBar(params: { options: SideBarOptions }) { let i = 0; for (const tag of Object.keys(params.options.tags)) { if (!(tag in params.options.menus)) continue; - const { title, color } = params.options.tags[tag]; + const { display: title, color } = params.options.tags[tag]; const subComponens = []; subComponens.push( -
+
+ {/* + + Sorry, your browser does not support inline SVG. + */} {title}
); diff --git a/src/components/header.tsx b/src/components/header.tsx index d3ae0f3..a2a6989 100644 --- a/src/components/header.tsx +++ b/src/components/header.tsx @@ -5,10 +5,10 @@ export default function Header() { return
- - + Scripting Wiki
diff --git a/src/features/functions.ts b/src/features/functions.ts index c213688..7800f75 100644 --- a/src/features/functions.ts +++ b/src/features/functions.ts @@ -9,4 +9,12 @@ export function* GetFilesTree(base: string): Generator { export function RemoveSuffix(fileName: string) { const spl = fileName.split("."); return fileName.substring(0,fileName.length - spl[spl.length-1].length - 1); +} +const fetchedUsers: {[k: string]: any} = {}; +export async function getProfileInfo(profileName: string){ + if(profileName in fetchedUsers) return fetchedUsers[profileName]; + const source = await fetch("https://api.github.com/users/" + profileName); + if(source.status == 404) return null; + const data = source.json(); + return data; } \ No newline at end of file diff --git a/src/features/getAllTopics.ts b/src/features/getAllTopics.ts index d277db6..11d3247 100644 --- a/src/features/getAllTopics.ts +++ b/src/features/getAllTopics.ts @@ -1,8 +1,9 @@ +import { readFileSync } from "fs"; import { GetFilesTree, RemoveSuffix } from "./functions"; import { ComponentType } from "react"; export async function LoadThem() { - const metadatas: { [k: string]: any } = {}; + const metadatas: { [k: string]: {[k: string]: any} } = {}; const obj: { [k: string]: ComponentType<{}> } = {}; for (const ss of GetWikiPaths()) { const j = ss.join("/"); @@ -11,7 +12,7 @@ export async function LoadThem() { obj[k] = m.default; metadatas[k] = m.metadata; } - return [obj, metadatas]; + return [obj, metadatas] as [typeof obj, typeof metadatas]; } export function* GetWikiPaths() { for (const filePath of GetFilesTree("./wiki")) { @@ -21,4 +22,18 @@ export function* GetWikiPaths() { yield ss; } } -} \ No newline at end of file +} + + +export const meta_informations: { + "blog_kind": {[k: string]: { + color: string, + display: string + }}, + "tags": {[k: string]: { + color: string, + display: string, + "text-color"?: string + }} + "code-languages": {[k: string]: string} +} = JSON.parse(readFileSync("./wiki/metadata.json").toString()); \ No newline at end of file diff --git a/src/mdx-components.tsx b/src/mdx-components.tsx index 42f216e..582c2cc 100644 --- a/src/mdx-components.tsx +++ b/src/mdx-components.tsx @@ -2,6 +2,7 @@ import { existsSync, readFileSync, statfsSync } from "fs"; import type { MDXComponents } from "mdx/types"; import Link from "next/link"; import { resolve } from "path"; +import { meta_informations } from "./features/getAllTopics"; export function useMDXComponents(components: MDXComponents): MDXComponents { return { @@ -107,7 +108,7 @@ export function BlockQuote(params: any){ {params.children}
} -const languageToTextMap = JSON.parse(readFileSync("./wiki/language-maps.json").toString()) as { [key: string]: any } +const languageToTextMap = meta_informations["code-languages"]; ////////////////////// Custom elements diff --git a/wiki/api-environment.md b/wiki/api-environment.md index a92467a..ed5ae07 100644 --- a/wiki/api-environment.md +++ b/wiki/api-environment.md @@ -1,8 +1,11 @@ --- displayName: API Environment -tag: docs +kind: docs +author: conmaster2112 +tags: + - depracated + - js --- -# API Environment Minecraft: Bedrock Edition uses their own version of JavaScript based on QuickJS. It uses the ECMAScript module (ESM) system for organizing and loading code, which allows for a more modular and organized approach to writing scripts for the game. ## Common problems diff --git a/wiki/language-maps.json b/wiki/language-maps.json deleted file mode 100644 index 88b4c8b..0000000 --- a/wiki/language-maps.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "language-js": "JavaScript", - "language-javascript": "JavaScript", - "language-ts": "TypeScript", - "language-typescript": "TypeScript", - "language-json": "JSON", - "language-md": "Markdown", - "language-markdown": "Markdown", - "language-cpp": "C++", - "language-c": "C", - "language-h": "C", - "language-hpp": "C" -} \ No newline at end of file diff --git a/wiki/metadata.json b/wiki/metadata.json new file mode 100644 index 0000000..ceb3f3b --- /dev/null +++ b/wiki/metadata.json @@ -0,0 +1,44 @@ +{ + "tags":{ + "depracated":{ + "display":"Deprecated", + "color":"#990000" + }, + "js":{ + "display":"JavaScript", + "color":"#cca300", + "text-color":"black" + } + }, + "blog_kind":{ + "docs": { + "display":"Documentation", + "color":"#0059b3" + }, + "blog":{ + "display": "Blogs", + "color":"#660066" + }, + "dev": { + "display":"Examples", + "color":"#987420" + }, + "guide":{ + "display":"Guides", + "color":"#004d00" + } + }, + "code-languages":{ + "language-js": "JavaScript", + "language-javascript": "JavaScript", + "language-ts": "TypeScript", + "language-typescript": "TypeScript", + "language-json": "JSON", + "language-md": "Markdown", + "language-markdown": "Markdown", + "language-cpp": "C++", + "language-c": "C", + "language-h": "C", + "language-hpp": "C" + } +} \ No newline at end of file diff --git a/wiki/tags_definition.json b/wiki/tags_definition.json deleted file mode 100644 index ba9d6be..0000000 --- a/wiki/tags_definition.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "dev": { - "title":"Examples", - "color":"#987420" - }, - "docs": { - "title":"Documentation", - "color":"#0059b3" - }, - "guide":{ - "title":"Guides", - "color":"#004d00" - } -} \ No newline at end of file