Compare commits
4 Commits
1ceaa15507
...
9be7530b15
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 9be7530b15 | |
Shadowfacts | 3965d03971 | |
Shadowfacts | 0d615ccb35 | |
Shadowfacts | 4c3a069671 |
|
@ -1,9 +1,19 @@
|
|||
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)));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ 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";
|
||||
|
||||
|
@ -15,7 +14,6 @@ export = {
|
|||
errors,
|
||||
homepage,
|
||||
posts,
|
||||
redirects,
|
||||
rss,
|
||||
tutorials
|
||||
};
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
10
lib/index.ts
10
lib/index.ts
|
@ -20,7 +20,6 @@ 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);
|
||||
|
||||
|
@ -74,6 +73,15 @@ 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.
After Width: | Height: | Size: 78 KiB |
|
@ -5,7 +5,8 @@
|
|||
on
|
||||
<span>
|
||||
<% const formatted = formatDate(metadata.date, "MMM Do, YYYY") %>
|
||||
<time itemprop="datePublished" datetime="<%= metadata.date.toISOString() %>"><%= formatted %></time>
|
||||
<% const fullFormatted = formatDate(metadata.date, "hh:mm:ss A MMM Do, YYYY") %>
|
||||
<time itemprop="datePublished" datetime="<%= metadata.date.toISOString() %>" title="<%= fullFormatted %>"><%= formatted %></time>
|
||||
</span>
|
||||
<% if (metadata.category) { %>
|
||||
in
|
||||
|
|
|
@ -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#activitypub">Learn more</a>.
|
||||
<a href="/meta/2019/reincarnation/#activity-pub">Learn more</a>.
|
||||
</p>
|
||||
<noscript>
|
||||
<p id="comments-js-warning">
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
```
|
||||
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>
|
Loading…
Reference in New Issue