From 3f82277e9e1f650bb209dcd4e5e390fbf46c0d69 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 11 Nov 2019 12:10:48 -0500 Subject: [PATCH] Change how static files are structured --- lib/generate/copy.ts | 30 +++++++++++------- lib/generate/posts.ts | 5 ++- site/posts/2019-09-18-reincarnation.md | 2 +- site/{ => static}/favicon-152.png | Bin site/{ => static}/favicon.ico | Bin site/{ => static}/js/comments.js | 0 .../2019/reincarnation}/galactic_entity.png | Bin site/{ => static}/shadowfacts.png | Bin 8 files changed, 23 insertions(+), 14 deletions(-) rename site/{ => static}/favicon-152.png (100%) rename site/{ => static}/favicon.ico (100%) rename site/{ => static}/js/comments.js (100%) rename site/{img/2019-09-18-reincarnation => static/meta/2019/reincarnation}/galactic_entity.png (100%) rename site/{ => static}/shadowfacts.png (100%) diff --git a/lib/generate/copy.ts b/lib/generate/copy.ts index adb7431..b143170 100644 --- a/lib/generate/copy.ts +++ b/lib/generate/copy.ts @@ -3,17 +3,23 @@ import * as util from "../util"; import * as path from "path"; export default async function copy() { - util.write("favicon.ico", await fs.readFile("site/favicon.ico")); - util.write("favicon-152.png", await fs.readFile("site/favicon-152.png")); - util.write("shadowfacts.png", await fs.readFile("site/shadowfacts.png")); - util.write("js/comments.js", await fs.readFile("site/js/comments.js")); - - // copy images - const dirs = await fs.readdir("site/img"); - for (const dir of dirs) { - const imgs = await fs.readdir(path.join("site/img", dir)); - for (const img of imgs) { - util.write(path.join("img", dir, img), await fs.readFile(path.join("site/img", dir, img))); - } + const files = await readDirRecursive("site/static"); + for (const f of files) { + await util.write(path.relative("site/static", f), await fs.readFile(f)); } } + +async function readDirRecursive(dir: string): Promise { + const files = await fs.readdir(dir); + const promises = files.map(async (f) => { + const fPath = path.join(dir, f); + const stats = (await fs.stat(fPath)); + if (stats.isDirectory()) { + return readDirRecursive(fPath); + } else { + return [fPath]; + } + }); + const groups = await Promise.all(promises); + return Array.prototype.concat(...groups); +} diff --git a/lib/generate/posts.ts b/lib/generate/posts.ts index 9a4c516..c159502 100644 --- a/lib/generate/posts.ts +++ b/lib/generate/posts.ts @@ -13,7 +13,8 @@ export default async function posts(): Promise { const files = await fs.readdir("site/posts"); for (const f of files) { - let page = await metadata.get(path.join("site/posts", f)); + const postPath = path.join("site/posts", f); + let page = await metadata.get(postPath); if (!(page.metadata).permalink) { let postMeta = page.metadata; @@ -22,6 +23,8 @@ export default async function posts(): Promise { postMeta.permalink = `/${postMeta.category}/${postMeta.date.getFullYear()}/${postMeta.slug}/`; } + page.text = util.render(page.text, { metadata: page.metadata }, postPath); + if (page.metadata.source && page.metadata.source!.endsWith(".md")) { (page.metadata).readingTime = util.getReadingTime(page.text); diff --git a/site/posts/2019-09-18-reincarnation.md b/site/posts/2019-09-18-reincarnation.md index 048b1e5..6235025 100644 --- a/site/posts/2019-09-18-reincarnation.md +++ b/site/posts/2019-09-18-reincarnation.md @@ -6,7 +6,7 @@ metadata.shortDesc = "Stand by for reincarnation." ```
- Futurama Galactic Entity image + Futurama Galactic Entity image
A wise man once said that nothing really dies, it just comes back in a new form. Then he died.
diff --git a/site/favicon-152.png b/site/static/favicon-152.png similarity index 100% rename from site/favicon-152.png rename to site/static/favicon-152.png diff --git a/site/favicon.ico b/site/static/favicon.ico similarity index 100% rename from site/favicon.ico rename to site/static/favicon.ico diff --git a/site/js/comments.js b/site/static/js/comments.js similarity index 100% rename from site/js/comments.js rename to site/static/js/comments.js diff --git a/site/img/2019-09-18-reincarnation/galactic_entity.png b/site/static/meta/2019/reincarnation/galactic_entity.png similarity index 100% rename from site/img/2019-09-18-reincarnation/galactic_entity.png rename to site/static/meta/2019/reincarnation/galactic_entity.png diff --git a/site/shadowfacts.png b/site/static/shadowfacts.png similarity index 100% rename from site/shadowfacts.png rename to site/static/shadowfacts.png