feat: enable file-based pages

This commit is contained in:
Ayo 2023-10-07 22:38:35 +02:00
parent c236d4b008
commit 6d9a3f2847
5 changed files with 14 additions and 21 deletions

6
package-lock.json generated
View file

@ -5,6 +5,7 @@
"packages": { "packages": {
"": { "": {
"dependencies": { "dependencies": {
"fs": "^0.0.1-security",
"nitropack": "latest" "nitropack": "latest"
} }
}, },
@ -1851,6 +1852,11 @@
"node": ">= 0.6" "node": ">= 0.6"
} }
}, },
"node_modules/fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
},
"node_modules/fs-extra": { "node_modules/fs-extra": {
"version": "11.1.1", "version": "11.1.1",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz",

View file

@ -7,6 +7,7 @@
"preview": "node .output/server/index.mjs" "preview": "node .output/server/index.mjs"
}, },
"dependencies": { "dependencies": {
"fs": "^0.0.1-security",
"nitropack": "latest" "nitropack": "latest"
} }
} }

7
routes/[...index].ts Normal file
View file

@ -0,0 +1,7 @@
import * as fs from "fs";
export default eventHandler((event) => {
const filename = event.path === "/" ? "/index.html" : `${event.path}.html`;
const path = `./src/pages${filename}`;
const html = fs.readFileSync(path, "utf8");
return html;
});

View file

@ -1,21 +0,0 @@
export default eventHandler((event) => {
const { org, repo } = event.context.params;
return getStars(org, repo);
});
type Project = {
org: string;
repo: string;
stars: string;
};
const getStars = async (org: string, repo: string): Promise<Project> => {
const stars = await cachedGHStars(`${org}/${repo}`);
return {
org,
repo,
stars,
};
};