feat(resources): implement breadcrumbs

This commit is contained in:
Jean-Philippe Sirois
2019-08-12 22:40:15 -04:00
parent da3f21d4d6
commit 809678383a
7 changed files with 120 additions and 24 deletions
+24
View File
@@ -0,0 +1,24 @@
import { IFileOrFolder } from "../components/ResourcesSidebar/index"
export function traversePaths(
[head, ...tail]: string[],
basePath = "/resources"
): IFileOrFolder {
const path = basePath + "/" + head
const isFile = !tail.length
if (isFile) {
// probably not more than one dot
const [name] = head.split(".")
return {
title: name,
type: "file",
path,
}
}
return {
title: head,
type: "folder",
path,
children: [traversePaths(tail, path)],
}
}