|
|
|
@ -302,4 +302,23 @@ path.posix.resolve(dataDirUnix, ...universalRelativePath),
@@ -302,4 +302,23 @@ path.posix.resolve(dataDirUnix, ...universalRelativePath),
|
|
|
|
|
// '/home/john/data-dir/static/img/logo.jpg' |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
以下代码用于将路径转换为数组 |
|
|
|
|
以下代码用于将路径转换为数组 |
|
|
|
|
|
|
|
|
|
```javascript |
|
|
|
|
const splitRelativePathIntoSegments = (relPath) => { |
|
|
|
|
if (path.isAbsolute(relPath)) { |
|
|
|
|
throw new Error("Path isn’t relative: " + relPath); |
|
|
|
|
} |
|
|
|
|
relPath = path.normalize(relPath); |
|
|
|
|
const result = []; |
|
|
|
|
while (true) { |
|
|
|
|
const base = path.basename(relPath); |
|
|
|
|
if (base.length === 0) break; |
|
|
|
|
result.unshift(base); |
|
|
|
|
const dir = path.dirname(relPath); |
|
|
|
|
if (dir === ".") break; |
|
|
|
|
relPath = dir; |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
}; |
|
|
|
|
``` |