diff --git a/packages/@vuepress/plugin-last-updated/index.js b/packages/@vuepress/plugin-last-updated/index.js index a4e8b137ad..d6fa880b09 100644 --- a/packages/@vuepress/plugin-last-updated/index.js +++ b/packages/@vuepress/plugin-last-updated/index.js @@ -4,11 +4,17 @@ module.exports = (options = {}, context) => ({ extendPageData ($page) { const { transformer } = options const timestamp = getGitLastUpdatedTimeStamp($page._filePath) - const lastUpdated = typeof transformer === 'function' ? transformer(timestamp) : timestamp - $page.lastUpdated = lastUpdated + if (timestamp) { + const lastUpdated = typeof transformer === 'function' ? transformer(timestamp) : timestamp + $page.lastUpdated = lastUpdated + } } }) function getGitLastUpdatedTimeStamp (filePath) { - return parseInt(spawn.sync('git', ['log', '-1', '--format=%ct', filePath]).stdout.toString('utf-8')) * 1000 + let lastUpdated + try { + lastUpdated = parseInt(spawn.sync('git', ['log', '-1', '--format=%ct', filePath]).stdout.toString('utf-8')) * 1000 + } catch (e) { /* do not handle for now */ } + return lastUpdated }