mirror of
https://github.com/hex248/fonts.git
synced 2026-02-07 18:23:06 +00:00
fixes for vercel
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { readFile, readdir } from "node:fs/promises";
|
import { readFile, readdir, stat } from "node:fs/promises";
|
||||||
import { join, parse } from "node:path";
|
import { join, parse } from "node:path";
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { serveStatic } from "hono/serve-static";
|
import { serveStatic } from "hono/middleware/serve-static";
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
@@ -10,6 +10,27 @@ const templatePath = join("public", "index.html");
|
|||||||
const cardPlaceholder = "<!-- FONT_CARDS -->";
|
const cardPlaceholder = "<!-- FONT_CARDS -->";
|
||||||
const importPlaceholder = "/* FONT_IMPORT */";
|
const importPlaceholder = "/* FONT_IMPORT */";
|
||||||
|
|
||||||
|
const serveStaticFromFs = (options: { root: string }) =>
|
||||||
|
serveStatic({
|
||||||
|
root: options.root,
|
||||||
|
getContent: async (path) => {
|
||||||
|
try {
|
||||||
|
return await readFile(path);
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isDir: async (path) => {
|
||||||
|
try {
|
||||||
|
const stats = await stat(path);
|
||||||
|
return stats.isDirectory();
|
||||||
|
} catch (error) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
join,
|
||||||
|
});
|
||||||
|
|
||||||
const escapeHtml = (value: string) =>
|
const escapeHtml = (value: string) =>
|
||||||
value
|
value
|
||||||
.replaceAll("&", "&")
|
.replaceAll("&", "&")
|
||||||
@@ -100,8 +121,8 @@ const indexHtml = templateHtml
|
|||||||
|
|
||||||
app.get("/", (c) => c.html(indexHtml));
|
app.get("/", (c) => c.html(indexHtml));
|
||||||
|
|
||||||
app.use("/fonts/*", serveStatic({ root: "." }));
|
app.use("/fonts/*", serveStaticFromFs({ root: "." }));
|
||||||
app.use("/*", serveStatic({ root: "./public" }));
|
app.use("/*", serveStaticFromFs({ root: "./public" }));
|
||||||
|
|
||||||
const cssRoutes = async () => {
|
const cssRoutes = async () => {
|
||||||
const entries = await readdir(cssDir, { withFileTypes: true });
|
const entries = await readdir(cssDir, { withFileTypes: true });
|
||||||
|
|||||||
Reference in New Issue
Block a user