feat: local caching for dev

This commit is contained in:
Cory Dransfeldt 2024-11-16 17:02:32 -08:00
parent c70fc72952
commit 522d8ca48a
No known key found for this signature in database
21 changed files with 375 additions and 326 deletions

View file

@ -1,22 +1,28 @@
import { createClient } from '@supabase/supabase-js';
import { createClient } from "@supabase/supabase-js";
const SUPABASE_URL = import.meta.env.SUPABASE_URL;
const SUPABASE_KEY = import.meta.env.SUPABASE_KEY;
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY);
let cachedBlogroll = null;
export async function fetchBlogroll() {
if (import.meta.env.MODE === "development" && cachedBlogroll)
return cachedBlogroll;
const { data, error } = await supabase
.from('authors')
.select('*')
.eq('blogroll', true)
.order('name', { ascending: true });
.from("authors")
.select("*")
.eq("blogroll", true)
.order("name", { ascending: true });
if (error) {
console.error('Error fetching authors for the blogroll:', error);
return [];
}
if (error) return [];
return data.sort((a, b) =>
const sortedData = data.sort((a, b) =>
a.name.toLowerCase().localeCompare(b.name.toLowerCase())
);
};
if (import.meta.env.MODE === "development") cachedBlogroll = sortedData;
return sortedData;
};