Compare commits

..

No commits in common. "9be7530b159234091d20f194f59ddd68ede9aaeb" and "1ceaa155070afc39a75cece0c8a38aeef2aaa75c" have entirely different histories.

8 changed files with 52 additions and 24 deletions

View File

@ -1,19 +1,9 @@
import { promises as fs } from "fs";
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)));
}
}
}
}

View File

@ -4,6 +4,7 @@ import css from "./css";
import errors from "./errors";
import homepage from "./homepage";
import posts from "./posts";
import redirects from "./redirects";
import rss from "./rss";
import tutorials from "./tutorials";
@ -14,6 +15,7 @@ export = {
errors,
homepage,
posts,
redirects,
rss,
tutorials
};

29
lib/generate/redirects.ts Normal file
View File

@ -0,0 +1,29 @@
import * as metadata from "../metadata";
import { Page } from "../metadata";
import layout from "../layout";
import * as util from "../util";
async function generateRedirect(oldPermalink: string, newPermalink: string) {
const page = await metadata.get("site/redirect.html.ejs");
page.text = util.render(page.text, {
metadata: page.metadata,
newPermalink
}, "site/redirect.html.ejs");
page.text = await layout(page.text, page.metadata, page.metadata.layout!);
if (oldPermalink.endsWith("/")) {
oldPermalink += "index.html";
}
util.write(oldPermalink, page.text);
}
export default async function redirects(posts: Page[]) {
for (const post of posts) {
if (post.metadata.oldPermalink) {
await generateRedirect(post.metadata.oldPermalink, post.metadata.permalink);
}
}
}

View File

@ -20,6 +20,7 @@ async function generate(): Promise<Page[]> {
const posts = await generators.posts();
generators.homepage(posts);
generators.redirects(posts);
const categories = await generators.categories(posts);
await generators.rss(posts, categories, tutorials);
@ -73,15 +74,6 @@ async function generate(): Promise<Page[]> {
app.use(apRouter);
app.use(express.static("out"));
// redirect posts with changed permalinks
for (const post of posts) {
if (post.metadata.oldPermalink) {
app.get(post.metadata.oldPermalink, (req, res) => {
res.status(301).redirect(post.metadata.permalink);
});
}
}
app.use((err, req, res, next) => {
console.error("Unhandled error:", err);
res.status(500).sendFile("500.html", {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

View File

@ -5,8 +5,7 @@
on
<span>
<% const formatted = formatDate(metadata.date, "MMM Do, YYYY") %>
<% const fullFormatted = formatDate(metadata.date, "hh:mm:ss A MMM Do, YYYY") %>
<time itemprop="datePublished" datetime="<%= metadata.date.toISOString() %>" title="<%= fullFormatted %>"><%= formatted %></time>
<time itemprop="datePublished" datetime="<%= metadata.date.toISOString() %>"><%= formatted %></time>
</span>
<% if (metadata.category) { %>
in
@ -19,4 +18,4 @@
<%= metadata.readingTime %> min read
<% } %>
</p>
</p>

View File

@ -17,7 +17,7 @@ metadata.layout = "default.html.ejs"
</summary>
<p id="comments-info">
Comments powered by ActivityPub. To respond to this post or to another comment, copy its URL into the search interface of your client for Mastodon, Pleroma, or other compatible software.
<a href="/meta/2019/reincarnation/#activity-pub">Learn more</a>.
<a href="/meta/2019/reincarnation#activitypub">Learn more</a>.
</p>
<noscript>
<p id="comments-js-warning">

16
site/redirect.html.ejs Normal file
View File

@ -0,0 +1,16 @@
```
metadata.title = "Redirect"
metadata.layout = "default.html.ejs"
```
<script>
window.location = "<%= newPermalink %>";
</script>
<article>
<div class="article-content">
<p>
This page has moved to a new URL. If you are not automatically redirected, click <a href="<%= newPermalink %>">here</a>.
</p>
</div>
</article>