Created
June 26, 2022 15:33
-
-
Save miao1007/0a5646a65878b086393b6c7b27e339f6 to your computer and use it in GitHub Desktop.
Hexo use modified date from git commit log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const childProcess = require('child_process'); | |
/** | |
* use `page.modified` in your theme | |
*/ | |
hexo.extend.filter.register('before_post_render', function (data) { | |
data.title = data.title.toLowerCase(); | |
data.modified = git_log(data.full_source) | |
return data; | |
}); | |
function git_log(dir) { | |
// https://git-scm.com/docs/pretty-formats | |
var args = [ | |
'log', | |
'--name-only', | |
'--pretty=format:"%as"', | |
'-n', | |
'1', | |
dir | |
]; | |
var s = childProcess.execFileSync("git", args).toString(); | |
return s.split('\n')[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment