mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-04 09:15:58 +02:00
25 lines
520 B
TypeScript
25 lines
520 B
TypeScript
import { IFileOrFolder } from "../components/ResourcesSidebar/index"
|
|
|
|
export function traversePaths(
|
|
[head, ...tail]: string[],
|
|
basePath: string = "/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)],
|
|
}
|
|
}
|