mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-04 09:15:58 +02:00
feat(resources): implement breadcrumbs
This commit is contained in:
@@ -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)],
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user