Initial commit

This commit is contained in:
Lucàs
2025-05-08 01:09:55 +02:00
commit 7ca8c5e15a
6 changed files with 453 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
import { Context } from 'hono';
import { renderFile } from 'pug';
import path from 'path';
declare module 'hono' {
interface Context {
pug: (template: string, locals?: Record<string, any>) => Response;
}
}
function pugRenderer(viewsPath: string) {
return async (c: Context, next: () => Promise<void>) => {
c.pug = (template: string, locals: Record<string, any> = {}) => {
const filePath = path.join(viewsPath, `${template}.pug`);
const html = renderFile(filePath, locals);
return c.html(html);
};
await next();
};
}
export { pugRenderer };