From aa7847690e616b9aa890f275282b77ad48f7e510 Mon Sep 17 00:00:00 2001
From: James King
Date: Mon, 11 May 2020 16:02:01 +0100
Subject: [PATCH] fix: Modify descriptions for each page/article
---
scripts/generatePages.ts | 19 ++++++++++++++++++-
scripts/generateThoughts.ts | 15 +++++++++++----
templates/head.html | 12 +++---------
...e-Importance-of-Monitoring-and-Alerting.md | 8 ++++----
4 files changed, 36 insertions(+), 18 deletions(-)
diff --git a/scripts/generatePages.ts b/scripts/generatePages.ts
index bf146b2..50d5691 100644
--- a/scripts/generatePages.ts
+++ b/scripts/generatePages.ts
@@ -15,6 +15,22 @@ pages.forEach((page) => {
pageName = "home";
}
+ let description = "I'm James King, and I make things for the web";
+ switch (pageName) {
+ case "thoughts":
+ description = "A peak inside my brain you ask? Reader, beware...";
+ break;
+ case "profile":
+ description =
+ "So who am I? I'm James King, a 27 year old Software Engineer from Lincolnshire. You want some more info?";
+ break;
+ case "coding":
+ description = "Shall we take a look at some projects I've done?";
+ break;
+ default:
+ // do nothing - already set description for home/index
+ }
+
templates.forEach((template) => {
const templateContents = fs
.readFileSync(template, "utf8")
@@ -25,7 +41,8 @@ pages.forEach((page) => {
new RegExp(`{${template.replace("templates/", "")}}`, "g"),
templateContents
)
- .replace("{subpage}", "");
+ .replace(/{subpage}/g, "")
+ .replace(/{description}/g, description);
});
fs.writeFileSync(page.replace("pages/", "public/"), pageContents, "utf8");
diff --git a/scripts/generateThoughts.ts b/scripts/generateThoughts.ts
index 2630b71..2ea0939 100644
--- a/scripts/generateThoughts.ts
+++ b/scripts/generateThoughts.ts
@@ -17,7 +17,7 @@ let thoughtsPageTemplateContents = fs.readFileSync(
templates.forEach((template) => {
const templateContents = fs
.readFileSync(template, "utf8")
- .replace(new RegExp(`{page}`, "g"), "thoughts");
+ .replace(/{page}/g, "thoughts");
thoughtsPageTemplateContents = thoughtsPageTemplateContents.replace(
new RegExp(`{${template.replace("templates/", "")}}`, "g"),
@@ -48,11 +48,20 @@ articles.forEach((article) => {
const title = titleWithDash.replace(/-/g, " ");
const body = mdConverter.makeHtml(fs.readFileSync(article, "utf8"));
+ const splitBody = body.split("
");
+
const articleContents = thoughtsPageTemplateContents
.replace("{title}", title)
.replace("{date}", date)
.replace("{body}", body)
- .replace("thoughts {subpage}", `${title}`);
+ .replace(/thoughts {subpage}/g, `${title}`)
+ .replace(
+ /{description}/g,
+ `${splitBody[0]} ${splitBody[1]}`
+ .replace(/\<(.*?)\>/g, "")
+ .replace("\n", "")
+ );
+
console.log(`Found article ${title} published ${date}`);
fs.writeFileSync(
`public/thoughts/${articleWithoutFolder}`,
@@ -60,8 +69,6 @@ articles.forEach((article) => {
"utf8"
);
- const splitBody = body.split("");
-
articlesGenerated.push({
link: `${datestring}_${titleWithDash}`,
title,
diff --git a/templates/head.html b/templates/head.html
index 7964241..e89e424 100644
--- a/templates/head.html
+++ b/templates/head.html
@@ -18,20 +18,14 @@
ripixel | {page} {subpage}
-
+
-
+
-
+