add tree weight
parent
fbf0c1c25f
commit
8157ca19ff
@ -1,10 +1,4 @@
|
||||
type node = {
|
||||
value: string;
|
||||
pretty?: string | null;
|
||||
children: node[];
|
||||
current: boolean;
|
||||
};
|
||||
|
||||
type FrontMatter = {
|
||||
title?: string
|
||||
weight?: number
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
export interface TreeItem {
|
||||
value: string,
|
||||
current: boolean,
|
||||
children: TreeItem[],
|
||||
weight: number,
|
||||
pretty: string | null
|
||||
}
|
||||
|
||||
export class TreeItemConstructor {
|
||||
value: string;
|
||||
current: boolean;
|
||||
children: TreeItemConstructor[] = [];
|
||||
weight: number;
|
||||
pretty: string | null;
|
||||
|
||||
constructor(
|
||||
value = "root",
|
||||
current = false,
|
||||
pretty: string | null = null,
|
||||
weight = 0
|
||||
) {
|
||||
this.value = value;
|
||||
this.current = current;
|
||||
this.pretty = pretty
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
addChild(child: TreeItemConstructor) {
|
||||
this.children.push(child)
|
||||
this.children.sort((a, b) => b.weight - a.weight);
|
||||
}
|
||||
|
||||
plain(): TreeItem {
|
||||
return {
|
||||
value: this.value,
|
||||
current: this.current,
|
||||
children: this.children.map(child => child.plain()),
|
||||
weight: this.weight,
|
||||
pretty: this.pretty
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
import { useRouter } from "next/router";
|
||||
import { FC } from "react";
|
||||
|
||||
const DocPage: FC<{}> = () => {
|
||||
const route = useRouter()
|
||||
|
||||
console.log(route.query)
|
||||
return (
|
||||
<>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default DocPage;
|
Loading…
Reference in New Issue