diff --git a/src/index.ts b/src/index.ts index aa5437b..2516364 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ import { join } from "path"; interface Note { slug: string; + title?: string; date: Date; } @@ -16,9 +17,19 @@ const parseNoteFile = async ( year: string, file: string ): Promise => { - const commits = await octokit.repos.listCommits({ owner, repo, path: `notes/${year}/${file}` }); + const commits = await octokit.repos.listCommits({ + owner, + repo, + path: `notes/${year}/${file}`, + }); + const contents = await readFile(join(".", "notes", year, file), "utf8"); return { slug: file, + title: + (contents.split("\n").find((line) => line.startsWith("title: ")) || "").replace( + "title: ", + "" + ) || undefined, date: new Date(commits.data[0].commit.author.date), }; }; @@ -53,9 +64,9 @@ export const run = async () => { let addedYears: Array = []; allNotes[year].forEach((note) => { const isPast = new Date(note.date).getTime() < new Date().getTime(); - const text = `${addedYears.includes(year) ? "" : `### ${year}\n\n`}- [\`${ - note.slug - }\`](./notes/${year}/${note.slug}), ${new Date(note.date).toLocaleDateString("en-us", { + const text = `${addedYears.includes(year) ? "" : `### ${year}\n\n`}- [${ + note.title || `\`${note.slug}\`` + }](./notes/${year}/${note.slug}), ${new Date(note.date).toLocaleDateString("en-us", { year: "numeric", month: "long", day: "numeric", @@ -65,11 +76,11 @@ export const run = async () => { addedYears.push(year); }); }); - let content = `## 🎤 Summary + let content = `## 🌯 Summary - ${totalNotes} notes in ${years.length} years `; - if (upcomingNotes.length) content += `## 🔮 Upcoming notes\n\n${upcomingNotes}`; - if (pastNotes.length) content += `## 📜 Past notes\n\n${pastNotes}`; + if (upcomingNotes.length) content += upcomingNotes; + if (pastNotes.length) content += pastNotes; let readmeContents = await readFile(join(".", "README.md"), "utf-8"); readmeContents = `${ readmeContents.split("")[0]