-
-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#2224 git created option for date
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const spawn = require("cross-spawn"); | ||
|
||
function getGitFirstAddedTimeStamp(filePath) { | ||
return ( | ||
parseInt( | ||
spawn | ||
.sync( | ||
"git", | ||
// Formats https://www.git-scm.com/docs/git-log#_pretty_formats | ||
// %at author date, UNIX timestamp | ||
["log", "--diff-filter=A", "--follow", "-1", "--format=%at", filePath] | ||
) | ||
.stdout.toString("utf-8") | ||
) * 1000 | ||
); | ||
} | ||
|
||
// return a Date | ||
module.exports = function (inputPath) { | ||
let timestamp = getGitFirstAddedTimeStamp(inputPath); | ||
if (timestamp) { | ||
return new Date(timestamp); | ||
} | ||
}; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
date: git created | ||
--- | ||
{{ page.date.getTime() }} |