diff --git a/lib/generate/errors.ts b/lib/generate/errors.ts new file mode 100644 index 0000000..157d16f --- /dev/null +++ b/lib/generate/errors.ts @@ -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); +} diff --git a/lib/generate/index.ts b/lib/generate/index.ts index c46aebf..fa55e87 100644 --- a/lib/generate/index.ts +++ b/lib/generate/index.ts @@ -1,8 +1,8 @@ import categories from "./categories"; import copy from "./copy"; import css from "./css"; +import errors from "./errors"; import homepage from "./homepage"; -import missing from "./missing"; import posts from "./posts"; import redirects from "./redirects"; import rss from "./rss"; @@ -12,10 +12,10 @@ export = { categories, copy, css, + errors, homepage, - missing, posts, redirects, rss, tutorials -}; \ No newline at end of file +}; diff --git a/lib/generate/missing.ts b/lib/generate/missing.ts deleted file mode 100644 index 6e2af90..0000000 --- a/lib/generate/missing.ts +++ /dev/null @@ -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); -} \ No newline at end of file diff --git a/lib/index.ts b/lib/index.ts index d7d1b42..02da734 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -14,7 +14,7 @@ import * as path from "path"; async function generate(): Promise { generators.copy(); generators.css(); - generators.missing(); + generators.errors(); const tutorials = await generators.tutorials(); @@ -74,6 +74,17 @@ async function generate(): Promise { app.use(apRouter); 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; app.listen(port, () => { console.log(`Listening on port ${port}`); diff --git a/site/404.html.ejs b/site/404.html.ejs index 149ea54..cb608cf 100644 --- a/site/404.html.ejs +++ b/site/404.html.ejs @@ -3,7 +3,7 @@ metadata.title = "Not Found" metadata.layout = "default.html.ejs" ``` - diff --git a/site/500.html.ejs b/site/500.html.ejs new file mode 100644 index 0000000..fff910f --- /dev/null +++ b/site/500.html.ejs @@ -0,0 +1,11 @@ +``` +metadata.title = "Not Found" +metadata.layout = "default.html.ejs" +``` + +
+

Something went wrong.

+

+ Please try again later. If the error persists, please contact me. +

+
diff --git a/site/css/main.scss b/site/css/main.scss index 76fd402..de7d282 100644 --- a/site/css/main.scss +++ b/site/css/main.scss @@ -195,8 +195,8 @@ article { } } -.search { - margin: 100px auto; +.error-page { + margin: 0 auto; text-align: center; h3 { @@ -205,7 +205,6 @@ article { line-height: 1.3; text-align: center; margin: 0; - padding: 0 2rem; } input#q {