Skip to content

Commit

Permalink
✨ Add number of words to summary & API
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary authored Jul 2, 2022
1 parent b6694e8 commit ac6b07a
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Note {
slug: string;
title?: string;
date: Date;
words: number;
}

const parseNoteFile = async (
Expand All @@ -22,17 +23,19 @@ const parseNoteFile = async (
.toString()
.trim();
const date = new Date(dateInput);
const title =
(
contents.split("\n").find((line) => line.startsWith("title: ")) || ""
).replace("title: ", "") ||
(contents.split("\n").find((line) => line.startsWith("# ")) || "")
.split("# ")[1]
.trim() ||
undefined;
return {
slug: file,
title:
(
contents.split("\n").find((line) => line.startsWith("title: ")) || ""
).replace("title: ", "") ||
(contents.split("\n").find((line) => line.startsWith("# ")) || "")
.split("# ")[1]
.trim() ||
undefined,
title: title,
date,
words: contents.length - (title || "").length,
};
};

Expand Down Expand Up @@ -74,9 +77,9 @@ export const run = async () => {
const isPast = new Date(note.date).getTime() < new Date().getTime();
const text = `${addedYears.includes(year) ? "" : `### ${year}\n\n`}- [${
note.title || `\`${note.slug}\``
}](./${dirName}/${year}/${note.slug}), ${new Date(
note.date
).toLocaleDateString("en-us", {
}](./${dirName}/${year}/${note.slug}) (${note.words.toLocaleString(
"en-US"
)} words), ${new Date(note.date).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
Expand Down

0 comments on commit ac6b07a

Please sign in to comment.