From 502946376f0e64c63dec247c580a605d36b4f5ef Mon Sep 17 00:00:00 2001 From: wholteza Date: Sun, 28 Jan 2024 20:34:07 +0100 Subject: [PATCH] Restructured toolchain to its own workspace --- .gitignore | 5 +- build.js | 97 --------- firebase.json | 2 +- package-lock.json | 14 ++ package.json | 16 +- packages/@zblog/toolchain/.gitignore | 3 + packages/@zblog/toolchain/package.json | 17 ++ .../@zblog/toolchain/src/markdown.ts | 201 ++++++++++-------- .../@zblog/toolchain/src/zblog-toolchain.ts | 102 +++++++++ packages/@zblog/toolchain/tsconfig.json | 9 + plugin.js | 0 readme.md | 10 + src/index.ts | 18 ++ .../notes}/1-initial-commit/assets/git.png | Bin {notes => src/notes}/1-initial-commit/note.md | 0 {notes => src/notes}/2-ideas/note.md | 0 .../notes}/3-markdown-parser/note.md | 0 .../notes}/4-markdown-parser-part-2/note.md | 0 {notes => src/notes}/5-pomodoro-timer/note.md | 0 {templates => src/templates}/404.html | 0 {templates => src/templates}/index.html | 0 {templates => src/templates}/note.html | 0 tsconfig.json | 14 ++ 23 files changed, 312 insertions(+), 196 deletions(-) delete mode 100644 build.js create mode 100644 packages/@zblog/toolchain/.gitignore create mode 100644 packages/@zblog/toolchain/package.json rename markdown.js => packages/@zblog/toolchain/src/markdown.ts (80%) create mode 100644 packages/@zblog/toolchain/src/zblog-toolchain.ts create mode 100644 packages/@zblog/toolchain/tsconfig.json delete mode 100644 plugin.js create mode 100644 readme.md create mode 100644 src/index.ts rename {notes => src/notes}/1-initial-commit/assets/git.png (100%) rename {notes => src/notes}/1-initial-commit/note.md (100%) rename {notes => src/notes}/2-ideas/note.md (100%) rename {notes => src/notes}/3-markdown-parser/note.md (100%) rename {notes => src/notes}/4-markdown-parser-part-2/note.md (100%) rename {notes => src/notes}/5-pomodoro-timer/note.md (100%) rename {templates => src/templates}/404.html (100%) rename {templates => src/templates}/index.html (100%) rename {templates => src/templates}/note.html (100%) create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index bfc5219..9bb1fdc 100644 --- a/.gitignore +++ b/.gitignore @@ -65,5 +65,6 @@ node_modules/ # dotenv environment variables file .env -.dist -temp \ No newline at end of file +dist +temp +bin \ No newline at end of file diff --git a/build.js b/build.js deleted file mode 100644 index 7425795..0000000 --- a/build.js +++ /dev/null @@ -1,97 +0,0 @@ -import * as fs from "fs"; -import { toHtml } from "./markdown.js"; - -const paths = { - output: ".dist", - notes: { - root: "notes", - assets: "assets", - note: "note.md", - }, - templates: { - root: "templates", - note: "note.html", - index: "index.html", - notFound: "404.html", - }, -}; - -if (fs.readdirSync(".").includes(paths.output)) { - fs.rmSync(paths.output, { recursive: true, force: true }); - console.log("Starting rebuild"); -} else { - console.log("Starting build"); -} -fs.mkdirSync(paths.output); - -console.log("Indexing content.."); -const directoryNames = fs.readdirSync(paths.notes.root); -const manifest = directoryNames.map((noteDirectory) => ({ - directoryName: noteDirectory, - name: noteDirectory, - markdown: fs.readFileSync( - `${paths.notes.root}/${noteDirectory}/${paths.notes.note}`, - { encoding: "utf-8" } - ), - assetDirectoryPath: `${paths.notes.root}/${noteDirectory}/${paths.notes.assets}`, - publicAssetDirectoryPath: `/${noteDirectory}_`, -})); - -console.log("Parsing content.."); -manifest.forEach((m) => { - const notePath = `${paths.templates.root}/${paths.templates.note}`; - let htmlTemplate = fs.readFileSync(notePath, { - encoding: "utf-8", - }); - htmlTemplate = htmlTemplate.replace( - "{{markdown}}", - toHtml(m.markdown, m.publicAssetDirectoryPath) - ); - fs.writeFileSync(`${paths.output}/${m.directoryName}.html`, htmlTemplate, { - encoding: "utf-8", - flag: "ax", - }); - - if (!fs.existsSync(m.assetDirectoryPath)) return; - const assetsList = fs.readdirSync(m.assetDirectoryPath); - assetsList.forEach((assetName) => - fs.cpSync( - `${m.assetDirectoryPath}/${assetName}`, - `${paths.output}/${m.name}_${assetName}` - ) - ); -}); - -console.log("Moving static templates.."); -[paths.templates.notFound].forEach((filename) => { - fs.copyFileSync( - `${paths.templates.root}/${filename}`, - `${paths.output}/${filename}` - ); -}); - -console.log("Building startpage.."); -let htmlTemplate = fs.readFileSync( - `${paths.templates.root}/${paths.templates.index}`, - { - encoding: "utf-8", - } -); - -const links = manifest - .map((m) => `${m.name}`) - .reverse(); - -const unorderedListItems = links.map((l) => `
  • ${l}
  • `).join("\r\n"); -const html = ` -