forked from shadowfacts/shadowfacts.net
Fix error pages
This commit is contained in:
parent
38b8c34a05
commit
5b307675b1
|
@ -0,0 +1,20 @@
|
||||||
|
import * as metadata from "../metadata";
|
||||||
|
import layout from "../layout";
|
||||||
|
import * as util from "../util";
|
||||||
|
|
||||||
|
export default async function errors() {
|
||||||
|
await generate("404.html");
|
||||||
|
await generate("500.html");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function generate(filename: string) {
|
||||||
|
const page = await metadata.get(`site/${filename}.ejs`);
|
||||||
|
|
||||||
|
page.text = util.render(page.text, {
|
||||||
|
metadata: page.metadata
|
||||||
|
}, `site/${filename}.ejs`);
|
||||||
|
|
||||||
|
page.text = await layout(page.text, page.metadata, page.metadata.layout!);
|
||||||
|
|
||||||
|
await util.write(filename, page.text);
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
import categories from "./categories";
|
import categories from "./categories";
|
||||||
import copy from "./copy";
|
import copy from "./copy";
|
||||||
import css from "./css";
|
import css from "./css";
|
||||||
|
import errors from "./errors";
|
||||||
import homepage from "./homepage";
|
import homepage from "./homepage";
|
||||||
import missing from "./missing";
|
|
||||||
import posts from "./posts";
|
import posts from "./posts";
|
||||||
import redirects from "./redirects";
|
import redirects from "./redirects";
|
||||||
import rss from "./rss";
|
import rss from "./rss";
|
||||||
|
@ -12,10 +12,10 @@ export = {
|
||||||
categories,
|
categories,
|
||||||
copy,
|
copy,
|
||||||
css,
|
css,
|
||||||
|
errors,
|
||||||
homepage,
|
homepage,
|
||||||
missing,
|
|
||||||
posts,
|
posts,
|
||||||
redirects,
|
redirects,
|
||||||
rss,
|
rss,
|
||||||
tutorials
|
tutorials
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
import * as metadata from "../metadata";
|
|
||||||
import layout from "../layout";
|
|
||||||
import * as util from "../util";
|
|
||||||
|
|
||||||
export default async function missing() {
|
|
||||||
const page = await metadata.get("site/404.html.ejs");
|
|
||||||
|
|
||||||
page.text = util.render(page.text, {
|
|
||||||
metadata: page.metadata
|
|
||||||
}, "site/404.html.ejs");
|
|
||||||
|
|
||||||
page.text = await layout(page.text, page.metadata, page.metadata.layout!);
|
|
||||||
|
|
||||||
util.write("404.html", page.text);
|
|
||||||
}
|
|
13
lib/index.ts
13
lib/index.ts
|
@ -14,7 +14,7 @@ import * as path from "path";
|
||||||
async function generate(): Promise<Page[]> {
|
async function generate(): Promise<Page[]> {
|
||||||
generators.copy();
|
generators.copy();
|
||||||
generators.css();
|
generators.css();
|
||||||
generators.missing();
|
generators.errors();
|
||||||
|
|
||||||
const tutorials = await generators.tutorials();
|
const tutorials = await generators.tutorials();
|
||||||
|
|
||||||
|
@ -74,6 +74,17 @@ async function generate(): Promise<Page[]> {
|
||||||
app.use(apRouter);
|
app.use(apRouter);
|
||||||
app.use(express.static("out"));
|
app.use(express.static("out"));
|
||||||
|
|
||||||
|
app.use((err, req, res, next) => {
|
||||||
|
res.status(500).sendFile("500.html", {
|
||||||
|
root: "out"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
res.status(404).sendFile("404.html", {
|
||||||
|
root: "out"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const port = process.env.PORT || 8083;
|
const port = process.env.PORT || 8083;
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Listening on port ${port}`);
|
console.log(`Listening on port ${port}`);
|
||||||
|
|
|
@ -3,7 +3,7 @@ metadata.title = "Not Found"
|
||||||
metadata.layout = "default.html.ejs"
|
metadata.layout = "default.html.ejs"
|
||||||
```
|
```
|
||||||
|
|
||||||
<div class="main search">
|
<div class="main error-page">
|
||||||
<h1 class="page-heading">Unable to find what you were looking for.</h1>
|
<h1 class="page-heading">Unable to find what you were looking for.</h1>
|
||||||
<h3>Try searching:</h3>
|
<h3>Try searching:</h3>
|
||||||
<form action="https://www.google.com/search" method="GET">
|
<form action="https://www.google.com/search" method="GET">
|
||||||
|
@ -11,4 +11,4 @@ metadata.layout = "default.html.ejs"
|
||||||
<input type="text" name="q" id="q" placeholder="Search...">
|
<input type="text" name="q" id="q" placeholder="Search...">
|
||||||
<input type="submit" value="Search">
|
<input type="submit" value="Search">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
```
|
||||||
|
metadata.title = "Not Found"
|
||||||
|
metadata.layout = "default.html.ejs"
|
||||||
|
```
|
||||||
|
|
||||||
|
<div class="main error-page">
|
||||||
|
<h1 class="page-heading">Something went wrong.</h1>
|
||||||
|
<p>
|
||||||
|
Please try again later. If the error persists, please <a href="mailto:me@shadowfacts.net">contact me</a>.
|
||||||
|
</p>
|
||||||
|
</div>
|
|
@ -195,8 +195,8 @@ article {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.search {
|
.error-page {
|
||||||
margin: 100px auto;
|
margin: 0 auto;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
|
@ -205,7 +205,6 @@ article {
|
||||||
line-height: 1.3;
|
line-height: 1.3;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0 2rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input#q {
|
input#q {
|
||||||
|
|
Loading…
Reference in New Issue