Change how static files are structured

This commit is contained in:
Shadowfacts 2019-11-11 12:10:48 -05:00
parent 0353c6c221
commit 3f82277e9e
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
8 changed files with 23 additions and 14 deletions

View File

@ -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<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);
}

View File

@ -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);

View File

@ -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>

View File

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 78 KiB

View File

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB