@@ -19,7 +19,7 @@ function decodeUtf8(str: string): string {
1919 * 在md文件的frontmatter中更新lastUpdated字段
2020 */
2121try {
22- console . log ( chalk . bgBlack . white . bold ( '1. markdown预处理 ' ) , chalk . gray ( '(自动补充markdown文件当中的frontmatter信息 )' ) ) ;
22+ console . log ( chalk . bgCyan . black . bold ( ' 1. Markdown 预处理 ' ) , chalk . gray ( '(自动补充 frontmatter 信息 )' ) ) ;
2323 // 获取本次提交修改过的文件列表
2424 const modifiedFiles = execSync ( 'git diff --cached --name-only' , { encoding : 'utf-8' } )
2525 . trim ( )
3535 } ) . map ( decodeUtf8 ) ;
3636
3737 const mdFiles = modifiedFiles . filter ( file => minimatch ( file , '_posts/**/*.md' ) ) . filter ( file => fs . existsSync ( file ) ) ;
38- console . log ( chalk . blue . bold ( ' 本次提交修改的文件: ') , modifiedFiles ) ;
39- console . log ( chalk . blue . bold ( ' 在_posts中的md文件:') , mdFiles ) ;
38+ console . log ( chalk . cyan ( ' • 本次提交修改的文件: ') , modifiedFiles ) ;
39+ console . log ( chalk . cyan ( ' • 在_posts中的md文件:') , mdFiles ) ;
4040 mdFiles . forEach ( file => {
4141 const pth = path . resolve ( file ) ;
4242 const content = fs . readFileSync ( pth , { encoding : 'utf-8' } ) ;
@@ -48,22 +48,22 @@ try {
4848 // 无title字段则使用文件名
4949 if ( ! frontmatter . title ) {
5050 frontmatter . title = fileName ;
51- console . log ( chalk . green ( `文件[ ${ chalk . bold ( fileName ) } ]的title字段为空, 已更新为文件名` ) ) ;
51+ console . log ( chalk . green ( ' ✔ 更新 Title: ' ) + chalk . yellow ( fileName ) ) ;
5252 }
5353
5454 // 更新lastUpdated字段
5555 frontmatter . lastUpdated = formatDate ( stats . mtime ) ;
56- console . log ( chalk . green ( `文件[ ${ chalk . bold ( fileName ) } ]的lastUpdated字段已更新` ) ) ;
56+ console . log ( chalk . green ( ' ✔ 更新 LastUpdated: ' ) + chalk . yellow ( fileName ) ) ;
5757
5858 if ( ! frontmatter . date ) {
5959 const creationTime = stats . birthtime ;
6060 frontmatter . date = formatDate ( creationTime ) ;
61- console . log ( chalk . green ( `文件[ ${ chalk . bold ( fileName ) } ]的date字段为空, 已更新为文件创建时间` ) ) ;
61+ console . log ( chalk . green ( ' ✔ 更新 Date: ' ) + chalk . yellow ( fileName ) ) ;
6262 }
6363
6464 if ( ! frontmatter . id ) {
6565 frontmatter . id = genPostId ( ) ;
66- console . log ( chalk . green ( `文件[ ${ chalk . bold ( fileName ) } ]的id字段为空, 已生成唯一id` ) ) ;
66+ console . log ( chalk . green ( ' ✔ 生成 ID: ' ) + chalk . yellow ( fileName ) ) ;
6767 }
6868
6969 const newContent = matter . stringify ( fileContent . content , frontmatter ) ;
@@ -75,14 +75,14 @@ try {
7575 if ( mdFiles . length > 0 ) {
7676 execSync ( `git add ${ mdFiles . map ( file => `"${ file } "` ) . join ( ' ' ) } ` ) ;
7777 } else {
78- console . log ( chalk . green . bold ( '没有需要更新的文件, markdown文件预处理结束 ') ) ;
78+ console . log ( chalk . gray ( ' - 没有需要更新的文件 ') ) ;
7979 }
8080
81- console . log ( chalk . bgBlack . white . bold ( '2. fileName Lint' ) , chalk . gray ( '(lint文件名和目录名, 避免在其他系统不可用的情况 )' ) ) ;
81+ console . log ( '\n' + chalk . bgCyan . black . bold ( ' 2. FileName Lint ' ) , chalk . gray ( '(检查文件名兼容性 )' ) ) ;
8282 lint ( ) ;
83- console . log ( chalk . bgGreen . white . bold ( 'Pre-commit hook completed successfully.' ) ) ;
83+ console . log ( '\n' + chalk . green . bold ( '✨ Pre-commit hook completed successfully.' ) ) ;
8484 process . exit ( 0 ) ;
8585} catch ( error ) {
86- console . error ( chalk . bgRed . white . bold ( 'Error running pre-commit hook:' ) , error ) ;
86+ console . error ( '\n' + chalk . red . bold ( '✖ Error running pre-commit hook:' ) , error ) ;
8787 process . exit ( 1 ) ;
8888}
0 commit comments