Skip to content

Commit 65a7ce4

Browse files
committed
improved 404 default page
1 parent 9dc68a3 commit 65a7ce4

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

middlewares/not_found.ts

+47-5
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@ export function notFound(userOptions?: Partial<Options>): Middleware {
5151
async function getDirectoryIndex(root: string, file: string): Promise<string> {
5252
const folders: [string, string][] = [];
5353
const files: [string, string][] = [];
54+
const folderIcon =
55+
`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" viewBox="0 0 256 256"><use xlink:href="#icon-folder"></use></svg>`;
56+
const fileIcon =
57+
`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" viewBox="0 0 256 256"><use xlink:href="#icon-file"></use></svg>`;
5458

5559
try {
5660
for await (const info of Deno.readDir(join(root, file))) {
5761
info.isDirectory
58-
? folders.push([`${info.name}/`, `📁 ${info.name}/`])
62+
? folders.push([`${info.name}/`, `${folderIcon} ${info.name}/`])
5963
: files.push([
6064
info.name === "index.html" ? "./" : info.name,
61-
`📄 ${info.name}`,
65+
`${fileIcon} ${info.name}`,
6266
]);
6367
}
6468
} catch {
@@ -69,11 +73,11 @@ async function getDirectoryIndex(root: string, file: string): Promise<string> {
6973
info.isDirectory
7074
? folders.push([
7175
posix.join(base, `${info.name}/`),
72-
`📁 ${info.name}/`,
76+
`${folderIcon} ${info.name}/`,
7377
])
7478
: files.push([
7579
posix.join(base, info.name === "index.html" ? "./" : info.name),
76-
`📄 ${info.name}`,
80+
`${fileIcon} ${info.name}`,
7781
]);
7882
}
7983
} catch {
@@ -94,9 +98,47 @@ async function getDirectoryIndex(root: string, file: string): Promise<string> {
9498
<meta charset="UTF-8">
9599
<meta name="viewport" content="width=device-width, initial-scale=1.0">
96100
<title>404 - Not found</title>
97-
<style> body { font-family: sans-serif; max-width: 40em; margin: auto; padding: 2em; line-height: 1.5; }</style>
101+
<style>
102+
html {
103+
color-scheme: light dark;
104+
}
105+
body {
106+
font-family: sans-serif;
107+
max-width: 40em;
108+
margin: auto;
109+
padding: 2em;
110+
line-height: 1.5;
111+
}
112+
h1 {
113+
margin-bottom: 0;
114+
}
115+
ul {
116+
margin: 2em 0;
117+
padding: 0;
118+
list-style-type: "";
119+
}
120+
li a {
121+
display: flex;
122+
align-items: center;
123+
column-gap: 0.5em;
124+
text-decoration: none;
125+
&:hover {
126+
text-decoration: underline;
127+
}
128+
}
129+
</style>
98130
</head>
99131
<body>
132+
<svg display="none">
133+
<defs>
134+
<g id="icon-file">
135+
<path d="M213.66,82.34l-56-56A8,8,0,0,0,152,24H56A16,16,0,0,0,40,40V216a16,16,0,0,0,16,16H200a16,16,0,0,0,16-16V88A8,8,0,0,0,213.66,82.34ZM160,51.31,188.69,80H160ZM200,216H56V40h88V88a8,8,0,0,0,8,8h48V216Z"/>
136+
</g>
137+
<g id="icon-folder">
138+
<path d="M232,88V200.89A15.13,15.13,0,0,1,216.89,216H40a16,16,0,0,1-16-16V64A16,16,0,0,1,40,48H93.33a16.12,16.12,0,0,1,9.6,3.2L130.67,72H216A16,16,0,0,1,232,88Z"></path>
139+
</g>
140+
</defs>
141+
</svg>
100142
<h1>404 - Not found</h1>
101143
<p>The URL <code>${file}</code> does not exist</p>
102144
<ul>

0 commit comments

Comments
 (0)