-
Notifications
You must be signed in to change notification settings - Fork 1
/
make-error-pages.js
executable file
·66 lines (60 loc) · 1.33 KB
/
make-error-pages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
import { writeFileSync } from 'node:fs'
// The error pages have no extension, see
// https://blog.uirig.com/pretty-routes-for-static-html
[
'./static-pages-bundler/example-blog/root/root-meta/',
'./static-pages-bundler/example-docs/root/root-meta/'
]
.forEach(dir => {
make(dir, 400, 'Bad Request')
make(dir, 401, 'Unauthorized')
make(dir, 403, 'Forbidden')
make(dir, 404, 'Not Found')
make(dir, 503, 'Rate Limited')
make(dir, 'SORRY', 'Something went wrong.<br>Please try again.', '#7b0452')
})
function make(dir, statusCode, title, bgcolor = '#e43838') {
console.log('Saving', dir + statusCode)
writeFileSync(dir + String(statusCode),
`<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width">
<link rel="icon" type="image/svg+xml" href="favicon.svg">
<title>${statusCode} ${title.replace('<br>', ' ')}</title>
<style>
body {
font-family: Futura, system-ui, sans-serif;
background: ${bgcolor};
color: #fff;
padding: 0;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
h1 {
font-size: 66px;
margin: 0 10px 0 0;
}
p {
font-size: 19px;
opacity: 0.8
}
@media (max-width: 440px) {
body {
flex-direction: column;
text-align: center;
}
}
</style>
</head>
<body>
<h1>${statusCode}</h1>
<p>${title}</p>
</body>
</html>
`, 'utf8')
}