修改日志管理默认排序

This commit is contained in:
whyour 2022-11-14 15:12:17 +08:00
parent b19ad2a13b
commit e868e65208

View File

@ -284,6 +284,20 @@ enum FileType {
'file', 'file',
} }
interface IFile {
title: string;
key: string;
type: 'directory' | 'file',
parent: string;
mtime: number;
children?: IFile[],
}
export function dirSort(a: IFile, b: IFile) {
if (a.type !== b.type) return FileType[a.type] < FileType[b.type] ? -1 : 1
else if (a.mtime !== b.mtime) return a.mtime > b.mtime ? -1 : 1
}
export function readDirs( export function readDirs(
dir: string, dir: string,
baseDir: string = '', baseDir: string = '',
@ -303,10 +317,8 @@ export function readDirs(
key, key,
type: 'directory', type: 'directory',
parent: relativePath, parent: relativePath,
children: readDirs(subPath, baseDir).sort( mtime: stats.mtime.getTime(),
(a: any, b: any) => children: readDirs(subPath, baseDir).sort(dirSort),
(FileType as any)[a.type] - (FileType as any)[b.type],
),
}; };
} }
return { return {
@ -315,11 +327,10 @@ export function readDirs(
isLeaf: true, isLeaf: true,
key, key,
parent: relativePath, parent: relativePath,
mtime: stats.mtime.getTime(),
}; };
}); });
return result.sort( return result.sort(dirSort);
(a: any, b: any) => (FileType as any)[a.type] - (FileType as any)[b.type],
);
} }
export function readDir( export function readDir(