Skip to content

Commit ccfb5ea

Browse files
committed
feat!: Auto-gen thoughts page proper from articles
1 parent e6f3868 commit ccfb5ea

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

pages/thoughts.html

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,11 @@
1010
<p>A peak inside my brain you ask? Reader, beware...</p>
1111
<section class="area">
1212
<div class="header-details">
13-
<h3>The Importance of Monitoring and Alerting</h3>
14-
<p class="tag">9th September, 2019</p>
13+
<h3>{title0}</h3>
14+
<p class="tag">{date0}</p>
1515
</div>
16-
<p>
17-
We all know that monitoring and alerting are important, right? But
18-
just how important do we really think they are? How much do we show
19-
that in what we do?
20-
</p>
21-
<p>
22-
This is a story about an experience I had at a previous company, where
23-
I had the pleasure of being at least partially responsible for the
24-
system going down, and what we learned.
25-
</p>
26-
<a
27-
class="button"
28-
href="/thoughts/2019-09-09_The-Importance-of-Monitoring-and-Alerting"
29-
>Read the rest</a
30-
>
16+
{body0}
17+
<a class="button" href="/thoughts/{link0}">Read the rest</a>
3118
</section>
3219
</main>
3320

scripts/generateThoughts.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,22 @@ const articles = findInDir("./thoughts/articles", ".md");
3030

3131
const mdConverter = new showdown.Converter();
3232

33-
const articlesGenerated = [];
33+
const articlesGenerated: Array<{
34+
title: string;
35+
link: string;
36+
body: string;
37+
date: string;
38+
}> = [];
3439

3540
articles.forEach((article) => {
3641
const articleWithoutFolder = article
3742
.replace("thoughts/articles/", "")
3843
.replace(".md", ".html");
39-
let [datestring, title] = articleWithoutFolder
44+
let [datestring, titleWithDash] = articleWithoutFolder
4045
.replace(".html", "")
4146
.split("_");
4247
const date = dateFormat(new Date(datestring), "do LLL, u");
43-
title = title.replace(/-/g, " ");
48+
const title = titleWithDash.replace(/-/g, " ");
4449
const body = mdConverter.makeHtml(fs.readFileSync(article, "utf8"));
4550

4651
const articleContents = thoughtsPageTemplateContents
@@ -55,13 +60,31 @@ articles.forEach((article) => {
5560
"utf8"
5661
);
5762

63+
const splitBody = body.split("</p>");
64+
5865
articlesGenerated.push({
66+
link: `${datestring}_${titleWithDash}`,
5967
title,
6068
date,
61-
body,
69+
body: `${splitBody[0]}</p>${splitBody[1]}</p>`,
6270
});
6371
});
6472

6573
console.log(`Generated ${articlesGenerated.length} articles`);
6674

75+
console.log("Updating thoughts page proper");
76+
let thoughtsPageContents = fs.readFileSync("./public/thoughts.html", "utf8");
77+
78+
for (let i = 0; i < Math.min(2, articlesGenerated.length); i++) {
79+
thoughtsPageContents = thoughtsPageContents
80+
.replace(`{title${i}}`, articlesGenerated[i].title)
81+
.replace(`{date${i}}`, articlesGenerated[i].date)
82+
.replace(`{body${i}}`, articlesGenerated[i].body)
83+
.replace(`{link${i}}`, articlesGenerated[i].link);
84+
}
85+
86+
console.log("Updated thoughts page");
87+
88+
fs.writeFileSync("./public/thoughts.html", thoughtsPageContents, "utf8");
89+
6790
console.log("/// Finished generation of thoughts");

0 commit comments

Comments
 (0)