Change how static files are structured
|
@ -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"));
|
||||
const files = await readDirRecursive("site/static");
|
||||
for (const f of files) {
|
||||
await util.write(path.relative("site/static", f), await fs.readFile(f));
|
||||
}
|
||||
}
|
||||
|
||||
// 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)));
|
||||
}
|
||||
async function readDirRecursive(dir: string): Promise<string[]> {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,8 @@ export default async function posts(): Promise<Page[]> {
|
|||
|
||||
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 (!(<PostMetadata>page.metadata).permalink) {
|
||||
let postMeta = <PostMetadata>page.metadata;
|
||||
|
@ -22,6 +23,8 @@ export default async function posts(): Promise<Page[]> {
|
|||
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")) {
|
||||
(<PostMetadata>page.metadata).readingTime = util.getReadingTime(page.text);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ metadata.shortDesc = "Stand by for reincarnation."
|
|||
```
|
||||
|
||||
<figure>
|
||||
<img src="/img/2019-09-18-reincarnation/galactic_entity.png" alt="Futurama Galactic Entity image" />
|
||||
<img src="<%= metadata.permalink %>/galactic_entity.png" alt="Futurama Galactic Entity image" />
|
||||
<figcaption>A wise man once said that nothing really dies, it just comes back in a new form. Then he died.</figcaption>
|
||||
</figure>
|
||||
|
||||
|
|
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.8 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |