this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

πŸ”‡ Remove useless logs in middleware

+47 -69
+47 -69
src/middleware.ts
··· 5 5 6 6 let loggedCollections = false; 7 7 8 - export const onRequest = defineMiddleware( 9 - async ({ locals, url, routePattern }, next) => { 10 - if (!loggedCollections) { 11 - const ids: Record<string, string[]> = {}; 12 - for (const name of Object.keys(collections)) { 13 - ids[name] = []; 14 - for (const entry of await getCollection(name)) { 15 - ids[name].push(entry.id); 16 - } 17 - } 18 - 19 - console.info("Loaded collections"); 20 - console.info(JSON.stringify(ids, null, 2)); 21 - 22 - const emtns = await getEntry("works", "emotiβˆ—ns"); 23 - console.info(JSON.stringify({ "emotiβˆ—ns": emtns }, null, 2)); 24 - 25 - loggedCollections = true; 26 - } 27 - 28 - locals.lang = process.env.LANG === "fr" ? "fr" : "en"; 29 - locals.locale = process.env.LOCALE as 30 - | `${typeof locals.lang}-${string}` 31 - | undefined; 32 - locals.buildCommit = 33 - // Netlify 34 - process.env.COMMIT_REF || 35 - // Cloudflare Pages 36 - process.env.CF_PAGES_COMMIT_SHA || 37 - // Fallback 38 - "dev"; 8 + export const onRequest = defineMiddleware(async ({ locals, url }, next) => { 9 + locals.lang = process.env.LANG === "fr" ? "fr" : "en"; 10 + locals.locale = process.env.LOCALE as 11 + | `${typeof locals.lang}-${string}` 12 + | undefined; 13 + locals.buildCommit = 14 + // Netlify 15 + process.env.COMMIT_REF || 16 + // Cloudflare Pages 17 + process.env.CF_PAGES_COMMIT_SHA || 18 + // Fallback 19 + "dev"; 39 20 40 - const response = await next(); 21 + const response = await next(); 41 22 42 - if ( 43 - ["application/json", "text/plain"].includes( 44 - response.headers.get("content-type")?.split(";")[0] || "", 45 - ) 46 - ) { 47 - return response; 48 - } 23 + if ( 24 + ["application/json", "text/plain"].includes( 25 + response.headers.get("content-type")?.split(";")[0] || "", 26 + ) 27 + ) { 28 + return response; 29 + } 49 30 50 - const dom = new JSDOM(await response.text(), { 51 - url: url.toString(), 52 - contentType: response.headers.get("content-type") || "text/html", 53 - }); 31 + const dom = new JSDOM(await response.text(), { 32 + url: url.toString(), 33 + contentType: response.headers.get("content-type") || "text/html", 34 + }); 54 35 55 - for (const translatable of dom.window.document.querySelectorAll("[i18n]")) { 56 - const key = translatable.textContent?.trim(); 57 - if (!key) continue; 36 + for (const translatable of dom.window.document.querySelectorAll("[i18n]")) { 37 + const key = translatable.textContent?.trim(); 38 + if (!key) continue; 58 39 59 - const translation = 60 - locals.lang === "fr" 61 - ? await getEntry("frenchMessages", key) 62 - : { data: { msgstr: key } }; 40 + const translation = 41 + locals.lang === "fr" 42 + ? await getEntry("frenchMessages", key) 43 + : { data: { msgstr: key } }; 63 44 64 - translatable.removeAttribute("i18n"); 65 - if (translation) { 66 - translatable.innerHTML = translation.data.msgstr; 67 - } 45 + translatable.removeAttribute("i18n"); 46 + if (translation) { 47 + translatable.innerHTML = translation.data.msgstr; 68 48 } 49 + } 69 50 70 - for (const translatable of dom.window.document.querySelectorAll("i18n")) { 71 - const key = translatable.innerHTML?.trim(); 72 - if (!key) continue; 51 + for (const translatable of dom.window.document.querySelectorAll("i18n")) { 52 + const key = translatable.innerHTML?.trim(); 53 + if (!key) continue; 73 54 74 - const translation = 75 - locals.lang === "fr" 76 - ? await getEntry("frenchMessages", key) 77 - : undefined; 55 + const translation = 56 + locals.lang === "fr" ? await getEntry("frenchMessages", key) : undefined; 78 57 79 - translatable.outerHTML = translation?.data.msgstr ?? key; 80 - } 58 + translatable.outerHTML = translation?.data.msgstr ?? key; 59 + } 81 60 82 - return new Response(dom.serialize(), { 83 - status: 200, 84 - headers: response.headers, 85 - }); 86 - }, 87 - ); 61 + return new Response(dom.serialize(), { 62 + status: 200, 63 + headers: response.headers, 64 + }); 65 + });