Skip to content

Commit

Permalink
🐛 Correctly parse manually overwritten date
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary authored Nov 20, 2022
1 parent 3bc750c commit cd6cac8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ interface Note {
*/
const parseNoteFile = async (dirName: string, year: string, file: string): Promise<Note> => {
const contents = await readFile(join(".", dirName, year, file), "utf8");
const dateInput = execSync(`git log --format=%aD ${dirName}/${year}/${file} | tail -1`)
.toString()
.trim();
const dateInput =
(contents.split("\n").find((line) => line.startsWith("date: ")) || "").replace(
"date: ",
""
) ||
execSync(`git log --format=%aD ${dirName}/${year}/${file} | tail -1`)
.toString()
.trim();
const date = new Date(dateInput);
const title =
(contents.split("\n").find((line) => line.startsWith("title: ")) || "").replace(
Expand Down

0 comments on commit cd6cac8

Please sign in to comment.