Skip to content

Commit c3dc5f7

Browse files
committed
feat: 🚀 文件创建时间如果获取不到,则获取最后一次访问时间
1 parent 4f888ec commit c3dc5f7

File tree

2 files changed

+5
-2
lines changed
  • plugins/vitepress-plugin-auto-frontmatter/src
  • vitepress-theme-teeker/src/post

2 files changed

+5
-2
lines changed

plugins/vitepress-plugin-auto-frontmatter/src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ const writeFrontmatterToFile = (filePaths: string[], option: AutoFrontmatterOpti
6565
let tempFrontmatter = { ...frontmatter };
6666
let hasChange = false;
6767

68+
const stat = statSync(filePath);
69+
6870
const addInfo: Record<string, any> = {
6971
title: getMdFileTitle(basename(filePath)),
70-
date: statSync(filePath).birthtime,
72+
date: stat.birthtime || stat.atime,
7173
};
7274

7375
for (const [key, value] of Object.entries(addInfo)) {

vitepress-theme-teeker/src/post/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export function getDate(post: RequiredKeyPartialOther<TkContentData, "frontmatte
115115

116116
// 如果目录下面有 index.md,则 url 不是目录名/index,而是目录名/,因此通过后面的 / 来补 index.md
117117
const filePath = join(srcDir, `${url.endsWith("/") ? `${url}/index` : url.replace(/\.html$/, "")}.md`);
118-
return formatDate(statSync(filePath).birthtime || new Date());
118+
const stat = statSync(filePath);
119+
return formatDate(stat.birthtime || stat.atime);
119120
}
120121

121122
/**

0 commit comments

Comments
 (0)