该文件有一个路径,例如:
C:\Users\Nastya\Desktop\Project\app\views\pages\button.html
C:\Users\Nastya\Desktop\Project\app\views\pages\gallery.html
C:\Users\Nastya\Desktop\Project\app\views\pages\heading.html
C:\Users\Nastya\Desktop\Project\app\views\pages\index.html
C:\Users\Nastya\Desktop\Project\app\views\pages\paragraph.html
C:\Users\Nastya\Desktop\Project\app\views\pages\table.html
C:\Users\Nastya\Desktop\Project\app\views\pages\blog\index.html
C:\Users\Nastya\Desktop\Project\app\views\pages\blog\cat\index.html
如何获得:
/button/
/gallery/
/heading/
/
/paragraph/
/table/
/blog/
/blog/cat/
不知道下一步该怎么做?
function resolve(paths) {
var ret = path.dirname(paths);
var base = path.basename(paths, path.extname(paths));
if (base != 'index') ret = path.join(ret, base);
return ret;
}
事实证明:
C:\Users\Nastya\Desktop\Project\app\views\pages\button
C:\Users\Nastya\Desktop\Project\app\views\pages\gallery
C:\Users\Nastya\Desktop\Project\app\views\pages\heading
C:\Users\Nastya\Desktop\Project\app\views\pages
C:\Users\Nastya\Desktop\Project\app\views\pages\paragraph
C:\Users\Nastya\Desktop\Project\app\views\pages\table
C:\Users\Nastya\Desktop\Project\app\views\pages\blog
C:\Users\Nastya\Desktop\Project\app\views\pages\blog\cat
您可以使用 RegEx 选择 \pages\ 之后的部分