mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-05 16:06:15 +02:00
resources: set up home page
This commit is contained in:
+26
-1
@@ -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)],
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user