feat: enable file-based pages
This commit is contained in:
parent
c236d4b008
commit
6d9a3f2847
5 changed files with 14 additions and 21 deletions
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -5,6 +5,7 @@
|
|||
"packages": {
|
||||
"": {
|
||||
"dependencies": {
|
||||
"fs": "^0.0.1-security",
|
||||
"nitropack": "latest"
|
||||
}
|
||||
},
|
||||
|
@ -1851,6 +1852,11 @@
|
|||
"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": {
|
||||
"version": "11.1.1",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz",
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
"preview": "node .output/server/index.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"fs": "^0.0.1-security",
|
||||
"nitropack": "latest"
|
||||
}
|
||||
}
|
||||
|
|
7
routes/[...index].ts
Normal file
7
routes/[...index].ts
Normal 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;
|
||||
});
|
|
@ -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,
|
||||
};
|
||||
};
|
Loading…
Reference in a new issue