fix build

This commit is contained in:
Wes Bos 2023-02-22 13:47:13 -05:00
parent 9c2e3c5926
commit 585e6088fa
3 changed files with 30 additions and 23 deletions

View file

@ -10,7 +10,7 @@
[[redirects]]
from = "/*"
to = "/.netlify/functions/server"
to = "/.netlify/edge-functions/server"
status = 200
[[headers]]

View file

@ -30,22 +30,22 @@ export default async function handleRequest(
responseHeaders: Headers,
remixContext: EntryContext
) {
// // check if we have a cached response in memory
// const cachedResponse = cache.get(request.url);
// if (cachedResponse) {
// console.log('Serving from cache', request.url);
// // if we have a cached response, check if it's less than 5 seconds old
// const now = new Date();
// const diff = now.getTime() - cachedResponse.date.getTime();
// if (true || diff < 5000) {
// // if it's less than 5 seconds old, return the cached response
// responseHeaders.set('Content-Type', 'text/html');
// return new Response(cachedResponse.html, {
// headers: responseHeaders,
// status: responseStatusCode,
// });
// }
// }
// check if we have a cached response in memory
const cachedResponse = cache.get(request.url);
if (cachedResponse) {
console.log('Serving from cache', request.url);
// if we have a cached response, check if it's less than 5 seconds old
const now = new Date();
const diff = now.getTime() - cachedResponse.date.getTime();
if (true || diff < 5000) {
// if it's less than 5 seconds old, return the cached response
responseHeaders.set('Content-Type', 'text/html');
return new Response(cachedResponse.html, {
headers: responseHeaders,
status: responseStatusCode,
});
}
}
let didError = false;
const chunks: Uint8Array[] = [];
@ -60,10 +60,15 @@ export default async function handleRequest(
}
);
// tee the stream so we can cache it and send it to the client
const [toReponse, toCache] = body.tee();
streamToText(toCache).then(html => {
console.log('I have the HTML!', html.length);
console.log('Caching', request.url);
cache.set(request.url, {
html: html.replace('Rendered Fresh',`Rendered from cache ${new Date().toISOString()}`),
date: new Date(),
});
});
const headers = new Headers(responseHeaders);

View file

@ -64,7 +64,6 @@ export function tags() {
const counts = allTags.reduce(countInstances, {});
// sort and filter for any tags that only have 1
const tags = Object.entries(counts)
.sort(([, countA], [, countB]) => countB - countA)
// Only show the tag if this topic has 3 or more people in it
.filter(([, count]) => count >= 3)
.map(([name, count]) => ({ name, count }));
@ -85,8 +84,11 @@ export function tags() {
delete lowercaseTagMap[normalizedName];
}
return acc;
}, []);
}, [])
// Sort by name first
.sort((a, b) => b.name.toLowerCase() > a.name.toLowerCase())
// Sort by count
.sort((a, b) => b.count - a.count);
return [{ name: 'all', count: people.length }, ...normalizedTags];
}
@ -116,12 +118,12 @@ const normalizedTagMap = tags().reduce((acc, tag) => {
}, {});
export function getPeople(tag?: string) {
return people
return [...people]
.sort(() => Math.random() - 0.5)
.map((person) => {
const normalizedPerson = {
...person,
// Clean out people that added basically the same tags twice
// Clean out people that added basically the same tags twice
tags: unique(
person.tags.map((tag) => normalizedTagMap[normalizeTag(tag)] || tag)
),