resources: set up home page

This commit is contained in:
Jean-Philippe Sirois
2019-09-17 01:58:15 -04:00
parent 2d16e9489c
commit 5bd0787112
5 changed files with 308 additions and 2 deletions
+26 -1
View File
@@ -1,4 +1,4 @@
import { IFileOrFolder } from "../components/ResourcesSidebar/index"
import { IFile, IFileOrFolder } from "../components/ResourcesSidebar/index"
export function traversePaths(
[head, ...tail]: string[],
@@ -22,3 +22,28 @@ export function traversePaths(
children: [traversePaths(tail, path)],
}
}
export function traversePathsToFiles(
[head, ...tail]: string[],
basePath: string = "/resources",
depth: number = 0
): IFileOrFolder {
const path = basePath + "/" + head + "/" + tail.join("/")
if (depth !== 0) {
// probably not more than one dot
const [name] = basePath.split(".")
return {
title: name,
type: "file",
path: basePath,
}
}
return {
title: head,
type: "folder",
path,
children: [traversePathsToFiles(tail, path, 1)],
}
}