From bd3a5c52101fee6850cc95d6ccfe51a4d5c95c09 Mon Sep 17 00:00:00 2001 From: ConMaster <64863757+conmaster2112@users.noreply.github.com> Date: Wed, 14 Feb 2024 11:35:35 +0100 Subject: [PATCH 1/6] n-cleanup --- src/app/[...slug]/page.tsx | 16 ++++++---------- src/app/layout.tsx | 8 ++++---- src/components/aside/aside.tsx | 10 +++++++--- src/components/header.tsx | 4 ++-- src/features/getAllTopics.ts | 10 +++++++++- src/mdx-components.tsx | 3 ++- wiki/api-environment.md | 2 +- wiki/language-maps.json | 13 ------------- wiki/metadata.json | 34 ++++++++++++++++++++++++++++++++++ wiki/tags_definition.json | 14 -------------- 10 files changed, 65 insertions(+), 49 deletions(-) delete mode 100644 wiki/language-maps.json create mode 100644 wiki/metadata.json delete mode 100644 wiki/tags_definition.json diff --git a/src/app/[...slug]/page.tsx b/src/app/[...slug]/page.tsx index adc0561..554e335 100644 --- a/src/app/[...slug]/page.tsx +++ b/src/app/[...slug]/page.tsx @@ -1,16 +1,9 @@ -import { GetFilesTree, RemoveSuffix } from "@/features/functions"; -import { LoadThem, GetWikiPaths } from "@/features/getAllTopics"; -import { Image } from "@/mdx-components"; -import { readFileSync } from "fs"; +import { RemoveSuffix } 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]} -}*/ +const meta = meta_informations; export async function generateStaticParams() { const slugs = []; for (const ss of GetWikiPaths()) { @@ -22,10 +15,13 @@ export async function generateStaticParams() { export default async function GetMarkdownPageView({ params }: StaticSlugParams) { const slg = params.slug; const [blogs, metadatas] = await LoadThem(); + const {displayName} = metadatas[slg.join("/")] const MdxData = blogs[slg.join("/")]; return (
+

{displayName}

+
{/*
*/} 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/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/getAllTopics.ts b/src/features/getAllTopics.ts index d277db6..6f65e6e 100644 --- a/src/features/getAllTopics.ts +++ b/src/features/getAllTopics.ts @@ -1,3 +1,4 @@ +import { readFileSync } from "fs"; import { GetFilesTree, RemoveSuffix } from "./functions"; import { ComponentType } from "react"; @@ -21,4 +22,11 @@ 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}} + "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..32d97a0 100644 --- a/wiki/api-environment.md +++ b/wiki/api-environment.md @@ -1,6 +1,6 @@ --- displayName: API Environment -tag: docs +kind: docs --- # 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. 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..214c518 --- /dev/null +++ b/wiki/metadata.json @@ -0,0 +1,34 @@ +{ + "tags":{}, + "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 From d868f2a920a248b7d1e9528cbe9e464ecfa82cd7 Mon Sep 17 00:00:00 2001 From: ConMaster <64863757+conmaster2112@users.noreply.github.com> Date: Wed, 14 Feb 2024 13:25:05 +0100 Subject: [PATCH 2/6] added tags --- src/app/[...slug]/page.tsx | 19 +++++++++++++++++-- src/features/getAllTopics.ts | 4 ++-- wiki/api-environment.md | 8 +++++++- wiki/metadata.json | 7 ++++++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/app/[...slug]/page.tsx b/src/app/[...slug]/page.tsx index 554e335..5bd5092 100644 --- a/src/app/[...slug]/page.tsx +++ b/src/app/[...slug]/page.tsx @@ -15,13 +15,21 @@ export async function generateStaticParams() { export default async function GetMarkdownPageView({ params }: StaticSlugParams) { const slg = params.slug; const [blogs, metadatas] = await LoadThem(); - const {displayName} = metadatas[slg.join("/")] + const {displayName, tags = []} = metadatas[slg.join("/")] as {displayName: string, tags?: string[]} const MdxData = blogs[slg.join("/")]; + const tagDefs = meta_informations.tags; return (

{displayName}

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

+ {data.children} +

+
} \ No newline at end of file diff --git a/src/features/getAllTopics.ts b/src/features/getAllTopics.ts index 6f65e6e..1f0cd8f 100644 --- a/src/features/getAllTopics.ts +++ b/src/features/getAllTopics.ts @@ -3,7 +3,7 @@ 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("/"); @@ -12,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")) { diff --git a/wiki/api-environment.md b/wiki/api-environment.md index 32d97a0..6deafe1 100644 --- a/wiki/api-environment.md +++ b/wiki/api-environment.md @@ -1,8 +1,14 @@ --- displayName: API Environment kind: docs +tags: + - depracated + - depracated + - depracated + - depracated + - depracated + - depracated --- -# 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/metadata.json b/wiki/metadata.json index 214c518..e158158 100644 --- a/wiki/metadata.json +++ b/wiki/metadata.json @@ -1,5 +1,10 @@ { - "tags":{}, + "tags":{ + "depracated":{ + "display":"Deprecated", + "color":"#990000" + } + }, "blog_kind":{ "docs": { "display":"Documentation", From f6ea3e7a08db149a0eeb605041bfe655cace3823 Mon Sep 17 00:00:00 2001 From: ConMaster <64863757+conmaster2112@users.noreply.github.com> Date: Wed, 14 Feb 2024 13:29:45 +0100 Subject: [PATCH 3/6] not-found external image link example --- src/app/not-found.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From 82f32ebff19d77444ab969e8836a7c63878cda8d Mon Sep 17 00:00:00 2001 From: ConMaster <64863757+conmaster2112@users.noreply.github.com> Date: Wed, 14 Feb 2024 13:40:44 +0100 Subject: [PATCH 4/6] text color for tags --- src/app/[...slug]/page.tsx | 10 +++++----- src/features/getAllTopics.ts | 11 +++++++++-- wiki/api-environment.md | 6 +----- wiki/metadata.json | 5 +++++ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/app/[...slug]/page.tsx b/src/app/[...slug]/page.tsx index 5bd5092..faf5307 100644 --- a/src/app/[...slug]/page.tsx +++ b/src/app/[...slug]/page.tsx @@ -26,8 +26,8 @@ export default async function GetMarkdownPageView({ params }: StaticSlugParams)
{tags.map((e: string,i)=>{ if(!(e in tagDefs)) return undefined; - const {color, display} = tagDefs[e]; - return {display} + const {color, display, "text-color": textColor} = tagDefs[e]; + return {display} })}
@@ -42,9 +42,9 @@ export async function generateMetadata({ params }: StaticSlugParams): Promise x.charAt(0).toUpperCase() + x.substring(1)).join("->")} on Bedrock API Wiki` } } -export function Tag(data: {children?: any, color?: string}){ - return
-

+export function Tag(data: {children?: any, color?: string, textColor?: string}){ + return

+

{data.children}

diff --git a/src/features/getAllTopics.ts b/src/features/getAllTopics.ts index 1f0cd8f..11d3247 100644 --- a/src/features/getAllTopics.ts +++ b/src/features/getAllTopics.ts @@ -26,7 +26,14 @@ export function* GetWikiPaths() { export const meta_informations: { - "blog_kind": {[k: string]: {color: string, display: string}}, - "tags": {[k: string]: {color: string, display: string}} + "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/wiki/api-environment.md b/wiki/api-environment.md index 6deafe1..6cee31f 100644 --- a/wiki/api-environment.md +++ b/wiki/api-environment.md @@ -3,11 +3,7 @@ displayName: API Environment kind: docs tags: - depracated - - depracated - - depracated - - depracated - - depracated - - depracated + - js --- 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. diff --git a/wiki/metadata.json b/wiki/metadata.json index e158158..ceb3f3b 100644 --- a/wiki/metadata.json +++ b/wiki/metadata.json @@ -3,6 +3,11 @@ "depracated":{ "display":"Deprecated", "color":"#990000" + }, + "js":{ + "display":"JavaScript", + "color":"#cca300", + "text-color":"black" } }, "blog_kind":{ From a90e931ab2209b759f32bab218baa98b820d0037 Mon Sep 17 00:00:00 2001 From: ConMaster <64863757+conmaster2112@users.noreply.github.com> Date: Wed, 14 Feb 2024 15:32:23 +0100 Subject: [PATCH 5/6] author feature --- src/app/[...slug]/page.tsx | 29 +++++++++++++++++++++++------ src/features/functions.ts | 8 ++++++++ wiki/api-environment.md | 1 + 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/app/[...slug]/page.tsx b/src/app/[...slug]/page.tsx index faf5307..2c94258 100644 --- a/src/app/[...slug]/page.tsx +++ b/src/app/[...slug]/page.tsx @@ -1,4 +1,4 @@ -import { RemoveSuffix } from "@/features/functions"; +import { RemoveSuffix, getProfileInfo } from "@/features/functions"; import { LoadThem, GetWikiPaths, meta_informations } from "@/features/getAllTopics"; import { Metadata } from "next"; @@ -15,15 +15,23 @@ export async function generateStaticParams() { export default async function GetMarkdownPageView({ params }: StaticSlugParams) { const slg = params.slug; const [blogs, metadatas] = await LoadThem(); - const {displayName, tags = []} = metadatas[slg.join("/")] as {displayName: string, tags?: string[]} + 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}

-
-
+
+

{displayName}

+ {info? +
+ {info} +
+ :undefined} +
+
+
{tags.map((e: string,i)=>{ if(!(e in tagDefs)) return undefined; const {color, display, "text-color": textColor} = tagDefs[e]; @@ -43,9 +51,18 @@ export async function generateMetadata({ params }: StaticSlugParams): Promise + return

{data.children}

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

+ by + {data.children.name} +

+ +
} \ No newline at end of file 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/wiki/api-environment.md b/wiki/api-environment.md index 6cee31f..ed5ae07 100644 --- a/wiki/api-environment.md +++ b/wiki/api-environment.md @@ -1,6 +1,7 @@ --- displayName: API Environment kind: docs +author: conmaster2112 tags: - depracated - js From d1497592fca85c6d5570a9890946fbfb9728b7d1 Mon Sep 17 00:00:00 2001 From: ConMaster <64863757+conmaster2112@users.noreply.github.com> Date: Wed, 14 Feb 2024 15:36:17 +0100 Subject: [PATCH 6/6] entry fix --- src/app/[...slug]/page.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/app/[...slug]/page.tsx b/src/app/[...slug]/page.tsx index 2c94258..04a64b5 100644 --- a/src/app/[...slug]/page.tsx +++ b/src/app/[...slug]/page.tsx @@ -3,7 +3,6 @@ import { LoadThem, GetWikiPaths, meta_informations } from "@/features/getAllTopi import { Metadata } from "next"; type StaticSlugParams = { params: Awaited>[number] } -const meta = meta_informations; export async function generateStaticParams() { const slugs = []; for (const ss of GetWikiPaths()) { @@ -50,14 +49,14 @@ export async function generateMetadata({ params }: StaticSlugParams): Promise x.charAt(0).toUpperCase() + x.substring(1)).join("->")} on Bedrock API Wiki` } } -export function Tag(data: {children?: any, color?: string, textColor?: string}){ +function Tag(data: {children?: any, color?: string, textColor?: string}){ return

{data.children}

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

by