From ac6b07ae9738c9cf49c6e52e210d9e5fc535b952 Mon Sep 17 00:00:00 2001 From: Anand Chowdhary Date: Sat, 2 Jul 2022 21:01:39 +0200 Subject: [PATCH] :sparkles: Add number of words to summary & API --- src/index.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 219b6ce..e930e9b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ interface Note { slug: string; title?: string; date: Date; + words: number; } const parseNoteFile = async ( @@ -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, }; }; @@ -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",