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
@@ -1,6 +1,7 @@
import partition from "ramda/es/partition"
import chain from "ramda/es/chain"
import { traversePaths } from "../../utils"
import {
IFileOrFolder,
IFile,
@@ -9,29 +10,6 @@ import {
IFileQuery,
} from "./index"
function traverse(
[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: [traverse(tail, path)],
}
}
function generateFolder({
title,
path,
@@ -85,7 +63,7 @@ function join([head, ...tail]: IFileOrFolder[]): IFileOrFolder[] {
export default function useBuildTree(resources: IAllResourcesQuery) {
const objects = resources.allFile.edges.map(({ node: file }: IFileQuery) =>
traverse(file.relativePath.split("/"))
traversePaths(file.relativePath.split("/"))
)
return join(objects)