Skip to content

Commit

Permalink
♻️ Add title of note, if available
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 14, 2020
1 parent 6ed705d commit 35e88b4
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { join } from "path";

interface Note {
slug: string;
title?: string;
date: Date;
}

Expand All @@ -16,9 +17,19 @@ const parseNoteFile = async (
year: string,
file: string
): Promise<Note> => {
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),
};
};
Expand Down Expand Up @@ -53,9 +64,9 @@ export const run = async () => {
let addedYears: Array<string> = [];
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",
Expand All @@ -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("<!--notes-->")[0]
Expand Down

0 comments on commit 35e88b4

Please sign in to comment.