Skip to content

Commit

Permalink
Refactored caching logic for individual blog posts
Browse files Browse the repository at this point in the history
This code caused errors which I was able to refactor at a second glance. The specific technique for caching is expected to change soon, though. To resolve #502, that is.
  • Loading branch information
EthanThatOneKid committed Aug 29, 2022
1 parent a45ee87 commit 0ba4d54
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/routes/blog/[id].json.ts
Expand Up @@ -2,18 +2,14 @@ import type { RequestEvent, RequestHandlerOutput } from '@sveltejs/kit/types/int
import type { Newsletter } from './_query';

async function getCache(id: number, origin: string) {
const target = origin + `/blog.json`;
const target = new URL('/blog.json', origin);

try {
const response = await fetch(target);
const data = await response.json();
const newsletter = (data as Newsletter[]).find((item) => {
return item.id === id;
});
return newsletter;
} catch (err) {
console.error(err);
return undefined;
const response = await fetch(target);
const payload = await response.json();

if (payload.posts && payload.posts.length > 0) {
const posts = payload.posts as Newsletter[];
return posts.find((item) => item.id === id);
}
}

Expand Down

0 comments on commit 0ba4d54

Please sign in to comment.