From 39197d8d2bcd063e6cca987bb1baf74e8dad6c02 Mon Sep 17 00:00:00 2001 From: xugaoyi <894072666@qq.com> Date: Sat, 8 Aug 2020 22:42:29 +0800 Subject: [PATCH] v1.4.1 --- package.json | 2 +- theme-vdoing/node_utils/setFrontmatter.js | 14 +++++++++----- theme-vdoing/package.json | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index d272bbdf85..5dc13546e6 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "vuepress-plugin-one-click-copy": "^1.0.2", "vuepress-plugin-thirdparty-search": "^1.0.2", "vuepress-plugin-zooming": "^1.1.7", - "vuepress-theme-vdoing": "^1.4.0", + "vuepress-theme-vdoing": "^1.4.1", "yamljs": "^0.3.0" }, "dependencies": { diff --git a/theme-vdoing/node_utils/setFrontmatter.js b/theme-vdoing/node_utils/setFrontmatter.js index 9b06a94f15..c1a26932a7 100644 --- a/theme-vdoing/node_utils/setFrontmatter.js +++ b/theme-vdoing/node_utils/setFrontmatter.js @@ -12,7 +12,7 @@ const PREFIX = '/pages/' /** - * 给.md文件设置frontmatter(标题、日期、永久链接) + * 给.md文件设置frontmatter(标题、日期、永久链接等数据) */ function setFrontmatter(sourceDir, themeConfig) { @@ -30,9 +30,7 @@ function setFrontmatter(sourceDir, themeConfig) { if (Object.keys(fileMatterObj.data).length === 0) { // 未定义FrontMatter数据 const stat = fs.statSync(file.filePath); - const dateStr = dateFormat(stat.birthtime);// 文件的创建时间 - - + const dateStr = dateFormat(getBirthtime(stat));// 文件的创建时间 const categories = getCategories(file, categoryText) // 注意下面这些反引号字符串的格式会映射到文件 @@ -65,7 +63,7 @@ permalink: ${getPermalink()}${file.filePath.indexOf('_posts') > -1 ? '\r\nsideba if (!matterData.hasOwnProperty('date')) { // 日期 const stat = fs.statSync(file.filePath); - matterData.date = dateFormat(stat.birthtime); + matterData.date = dateFormat(getBirthtime(stat)); mark = true; } @@ -121,6 +119,12 @@ function getCategories(file, categoryText) { return categories } +// 获取文件创建时间 +function getBirthtime(stat){ + // 在一些系统下无法获取birthtime属性的正确时间,使用atime代替 + return stat.birthtime.getFullYear() != 1970 ? stat.birthtime : stat.atime +} + // 定义永久链接数据 function getPermalink() { return `${PREFIX + (Math.random() + Math.random()).toString(16).slice(2, 8)}/` diff --git a/theme-vdoing/package.json b/theme-vdoing/package.json index 95844f4f8e..f23c847c0b 100644 --- a/theme-vdoing/package.json +++ b/theme-vdoing/package.json @@ -1,6 +1,6 @@ { "name": "vuepress-theme-vdoing", - "version": "1.4.0", + "version": "1.4.1", "description": "Vdoing theme for VuePress. 一个基于VuePress的知识管理兼博客主题。", "author": { "name": "gaoyi(Evan) Xu"