Skip to content

Instantly share code, notes, and snippets.

@miao1007
Created June 26, 2022 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miao1007/0a5646a65878b086393b6c7b27e339f6 to your computer and use it in GitHub Desktop.
Save miao1007/0a5646a65878b086393b6c7b27e339f6 to your computer and use it in GitHub Desktop.
Hexo use modified date from git commit log
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