Skip to content

Commit e86e470

Browse files
committed
feat: Make last-updated plugin extendPageData function asynchronous
1 parent 59b20bb commit e86e470

File tree

1 file changed

+7
-5
lines changed
  • packages/@vuepress/plugin-last-updated

1 file changed

+7
-5
lines changed

packages/@vuepress/plugin-last-updated/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const path = require('path')
22
const spawn = require('cross-spawn')
33

44
module.exports = (options = {}, context) => ({
5-
extendPageData ($page) {
5+
async extendPageData ($page) {
66
const { transformer } = options
7-
const timestamp = getGitLastUpdatedTimeStamp($page._filePath)
7+
const timestamp = await getGitLastUpdatedTimeStamp($page._filePath)
88
const $lang = $page._computed.$lang
99
if (timestamp) {
1010
const lastUpdated = typeof transformer === 'function'
@@ -19,14 +19,16 @@ function defaultTransformer (timestamp, lang) {
1919
return new Date(timestamp).toLocaleString(lang)
2020
}
2121

22-
function getGitLastUpdatedTimeStamp (filePath) {
22+
async function getGitLastUpdatedTimeStamp (filePath) {
2323
let lastUpdated
2424
try {
25-
lastUpdated = parseInt(spawn.sync(
25+
const commandResult = await spawn(
2626
'git',
2727
['log', '-1', '--format=%at', path.basename(filePath)],
2828
{ cwd: path.dirname(filePath) }
29-
).stdout.toString('utf-8')) * 1000
29+
)
30+
const formattedResult = commandResult.stdout.toString('utf-8')
31+
lastUpdated = parseInt(formattedResult) * 1000
3032
} catch (e) { /* do not handle for now */ }
3133
return lastUpdated
3234
}

0 commit comments

Comments
 (0)