feat: nested sub pages
This commit is contained in:
parent
6d9a3f2847
commit
77a93f8507
4 changed files with 50 additions and 2 deletions
11
pages/about.html
Normal file
11
pages/about.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>top about</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Top Level About</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
11
pages/about/index.html
Normal file
11
pages/about/index.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>About Me</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>About Me</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
11
pages/about/me.html
Normal file
11
pages/about/me.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>About Meeeee</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>About Meeeeeezzz</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1,7 +1,22 @@
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
export default eventHandler((event) => {
|
export default eventHandler((event) => {
|
||||||
const filename = event.path === "/" ? "/index.html" : `${event.path}.html`;
|
const filename = event.path === "/" ? "/index.html" : `${event.path}.html`;
|
||||||
const path = `./src/pages${filename}`;
|
const fallback = getPath(event.path + "/index.html");
|
||||||
const html = fs.readFileSync(path, "utf8");
|
const path = getPath(filename);
|
||||||
|
let html = "";
|
||||||
|
try {
|
||||||
|
html = fs.readFileSync(path, "utf8");
|
||||||
|
} catch (error) {
|
||||||
|
try {
|
||||||
|
html = fs.readFileSync(fallback, "utf8");
|
||||||
|
} catch {
|
||||||
|
html = `cannot find ${path} or ${fallback}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getPath(filename: string) {
|
||||||
|
return `./pages${filename}`;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue