remove premature optimization in serveStaticWithOG

This commit is contained in:
Siddharth Singh 2024-08-04 04:43:47 +05:30
parent 5ee0c1e852
commit baa6e318f3
No known key found for this signature in database

View file

@ -222,11 +222,13 @@ export const serveStaticWithOG = <E extends Env>(
return async function serveStatic(c: Context, next: Next) { return async function serveStatic(c: Context, next: Next) {
let file = ''; let file = '';
const getContent = async (path: string) => { const getContent = async (path: string) => {
console.log('here');
try { try {
if (!file) file = await Deno.readTextFile(path); if (!file) file = await Deno.readTextFile(path);
if (!file) throw new Error(`File at ${path} was empty!`); if (!file) throw new Error(`File at ${path} was empty!`);
if (c.req.header('accept')?.includes('html') && file.includes(OG_META_PLACEHOLDER)) { if (file.includes(OG_META_PLACEHOLDER)) {
const params = getPathParams(c.req.path); const params = getPathParams(c.req.path);
console.log(params);
if (params) { if (params) {
const meta = await buildMetaTags(params, Conf.local(c.req.path)); const meta = await buildMetaTags(params, Conf.local(c.req.path));
return file.replace(OG_META_PLACEHOLDER, meta); return file.replace(OG_META_PLACEHOLDER, meta);