更新任务6
This commit is contained in:
1 parent
b8697c4ce8
commit
255b1ffa41
1 file changed
+9
-9
@@ -16,10 +16,8 @@ export class FileUtils {
|
|||||||
*/
|
*/
|
||||||
static getFileName (url: string) {
|
static getFileName (url: string) {
|
||||||
console.log(url,"文件名称");
|
console.log(url,"文件名称");
|
||||||
const parsedUrl = new URL(url)
|
url = url.replace(/\\/g, '/')
|
||||||
let pathname = parsedUrl.pathname
|
const segments = url.split('/')
|
||||||
pathname = pathname.replace(/\\/g, '/')
|
|
||||||
const segments = pathname.split('/')
|
|
||||||
return segments[segments.length - 1]
|
return segments[segments.length - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,11 +27,9 @@ export class FileUtils {
|
|||||||
*/
|
*/
|
||||||
static getLastFolderName (url: string): string {
|
static getLastFolderName (url: string): string {
|
||||||
console.log(url,"文件夹名称");
|
console.log(url,"文件夹名称");
|
||||||
const parsedUrl = new URL(url)
|
|
||||||
let pathname = parsedUrl.pathname
|
|
||||||
// 统一路径分隔符为 '/'
|
// 统一路径分隔符为 '/'
|
||||||
pathname = pathname.replace(/\\/g, '/')
|
url = url.replace(/\\/g, '/')
|
||||||
const segments = pathname.split('/')
|
const segments = url.split('/')
|
||||||
|
|
||||||
if (segments[segments.length - 1].includes('.')) {
|
if (segments[segments.length - 1].includes('.')) {
|
||||||
return segments[segments.length - 2]
|
return segments[segments.length - 2]
|
||||||
@@ -70,4 +66,8 @@ export class FileUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// // /home/runner/work/duyl328.github.io/duyl328.github.io/docs/notes/index.md
|
||||||
|
// let fileName = FileUtils.getFileName("/home/runner/work/duyl328.github.io/duyl328.github.io/docs/notes/index.md")
|
||||||
|
// // let fileName = FileUtils.getFileName("D:/duyl328/github.io/autoSidebar/utils/fileUtils.ts")
|
||||||
|
// console.log(fileName);
|
||||||
Reference in new issue
Block a user