mirror of
https://github.com/quartz-community/page-title.git
synced 2026-07-22 02:50:31 +00:00
18 lines
344 B
TypeScript
18 lines
344 B
TypeScript
/**
|
|
* Gets the path to root from a given slug.
|
|
* For example, "a/b/c" becomes "../.."
|
|
*/
|
|
export function pathToRoot(slug: string): string {
|
|
let rootPath = slug
|
|
.split("/")
|
|
.filter((x) => x !== "")
|
|
.slice(0, -1)
|
|
.map((_) => "..")
|
|
.join("/");
|
|
|
|
if (rootPath.length === 0) {
|
|
rootPath = ".";
|
|
}
|
|
|
|
return rootPath;
|
|
}
|