From 1a5913dfc1e1d3aa45f6fc9a5cfcdcb4b008d48a Mon Sep 17 00:00:00 2001 From: LarsVomMars Date: Fri, 27 Dec 2024 12:24:46 +0100 Subject: fixes maybe --- .scripts/transform.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .scripts/transform.js (limited to '.scripts/transform.js') diff --git a/.scripts/transform.js b/.scripts/transform.js new file mode 100644 index 0000000..87a5aec --- /dev/null +++ b/.scripts/transform.js @@ -0,0 +1,34 @@ +import { statSync, readFileSync, writeFileSync, readdirSync } from "fs"; +import { join } from "path"; + +function transform(filePath) { + const stats = statSync(filePath); + const lastWriteDate = new Date(stats.mtime).toISOString().split("T")[0]; + console.log(`Transforming ${filePath} last modified at ${lastWriteDate}`); + + let content = readFileSync(filePath, "utf-8"); + const title = content.split("\n")[0].substring(1).trim(); + if (title === "--") return; + console.log(`Title: ${title}`); + + content = `--- +title: "${title}" +pubDate: "${lastWriteDate}" +--- +${content}`; + + writeFileSync(filePath, content); +} + +const blogsDir = "./src/content/blog"; +readdirSync(blogsDir).forEach((blog) => { + const blogPath = join(blogsDir, blog); + if (statSync(blogPath).isDirectory()) { + readdirSync(blogPath).forEach((blogFile) => { + const blogFilePath = join(blogPath, blogFile); + if (statSync(blogFilePath).isFile()) { + transform(blogFilePath); + } + }); + } +}); -- cgit v1.2.3