Skip to content

Commit 8eb2cb1

Browse files
Update src/data/links.json
Co-authored-by: Mia Bajić <[email protected]>
1 parent 4d92770 commit 8eb2cb1

File tree

9 files changed

+49
-45
lines changed

9 files changed

+49
-45
lines changed

.env.development

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
EP_SESSIONS_API="https://gist.githubusercontent.com/egeakman/eddfb15f32ae805e8cfb4c5856ae304b/raw/466f8c20c17a9f6c5875f973acaec60e4e4d0fae/sessions.json"
2+
EP_SPEAKERS_API="https://gist.githubusercontent.com/nikoshell/d8efd41f90961cc6298519c0eec04843/raw/d13a7b1d35f61be1773404e7faf8395dd4862313/speakers.json"

.env.preview

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
EP_SESSIONS_API="https://gist.githubusercontent.com/egeakman/eddfb15f32ae805e8cfb4c5856ae304b/raw/466f8c20c17a9f6c5875f973acaec60e4e4d0fae/sessions.json"
2+
EP_SPEAKERS_API="https://gist.githubusercontent.com/nikoshell/d8efd41f90961cc6298519c0eec04843/raw/d13a7b1d35f61be1773404e7faf8395dd4862313/speakers.json"

.env.production

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
EP_SESSIONS_API="https://gist.githubusercontent.com/egeakman/eddfb15f32ae805e8cfb4c5856ae304b/raw/466f8c20c17a9f6c5875f973acaec60e4e4d0fae/sessions.json"
2+
EP_SPEAKERS_API="https://gist.githubusercontent.com/nikoshell/d8efd41f90961cc6298519c0eec04843/raw/d13a7b1d35f61be1773404e7faf8395dd4862313/speakers.json"

astro.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default defineConfig({
2020
},
2121
resolve: {
2222
alias: {
23+
"@utils": path.resolve("./src/utils"),
2324
"@data": path.resolve("./src/data"),
2425
"@components": path.resolve("./src/components"),
2526
"@sections": path.resolve("./src/components/sections"),

src/content/config.ts

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,8 @@
11
import { defineCollection, reference, z } from "astro:content";
2-
import fs from "fs/promises";
3-
import path from "path";
2+
import { loadData } from "../utils/dataLoader";
43

5-
const CACHE_DIR = ".cache/data";
6-
7-
async function ensureCacheDir() {
8-
await fs.mkdir(CACHE_DIR, { recursive: true });
9-
}
10-
11-
async function fetchWithCache(url: string, filename: string): Promise<Buffer> {
12-
const filePath = path.join(CACHE_DIR, filename);
13-
14-
try {
15-
// Return cached if available
16-
const data = await fs.readFile(filePath);
17-
console.log(`Fetch from cache: ${filePath}`);
18-
return data;
19-
} catch {
20-
const res = await fetch(url);
21-
if (!res.ok) throw new Error(`Failed to fetch: ${url}`);
22-
23-
const arrayBuffer = await res.arrayBuffer();
24-
const buffer: Buffer = Buffer.from(arrayBuffer);
25-
await fs.writeFile(filePath, new Uint8Array(buffer));
26-
return buffer;
27-
}
28-
}
4+
const mode = import.meta.env.MODE;
5+
console.log(`\x1b[35m[EP]\x1b[0m Current MODE: \x1b[1m\x1b[34m${mode}\x1b[0m`);
296

307
const tiers = [
318
"Keystone",
@@ -83,32 +60,19 @@ const keynoters = defineCollection({
8360

8461
// Shared data fetching function
8562
async function getCollectionsData() {
86-
// Only fetch if not already cached
87-
await ensureCacheDir();
88-
89-
const speakersBuffer = await fetchWithCache(
90-
"https://gist.githubusercontent.com/nikoshell/d8efd41f90961cc6298519c0eec04843/raw/d13a7b1d35f61be1773404e7faf8395dd4862313/speakers.json",
91-
"speakers.json"
92-
);
93-
94-
const sessionsBuffer = await fetchWithCache(
95-
"https://gist.githubusercontent.com/egeakman/eddfb15f32ae805e8cfb4c5856ae304b/raw/466f8c20c17a9f6c5875f973acaec60e4e4d0fae/sessions.json",
96-
"sessions.json"
97-
);
98-
99-
const cachedSpeakersData = JSON.parse(speakersBuffer.toString("utf-8"));
100-
const cachedSessionsData = JSON.parse(sessionsBuffer.toString("utf-8"));
63+
const speakersData = await loadData(import.meta.env.EP_SPEAKERS_API);
64+
const sessionsData = await loadData(import.meta.env.EP_SESSIONS_API);
10165

10266
// Create indexed versions for efficient lookups
103-
const speakersById = Object.entries(cachedSpeakersData).reduce(
67+
const speakersById = Object.entries(speakersData).reduce(
10468
(acc, [id, speaker]: [string, any]) => {
10569
acc[id] = { id, ...speaker };
10670
return acc;
10771
},
10872
{} as Record<string, any>
10973
);
11074

111-
const sessionsById = Object.entries(cachedSessionsData).reduce(
75+
const sessionsById = Object.entries(sessionsData).reduce(
11276
(acc, [id, session]: [string, any]) => {
11377
acc[id] = { id, ...session };
11478
return acc;
@@ -117,8 +81,8 @@ async function getCollectionsData() {
11781
);
11882

11983
return {
120-
speakersData: cachedSpeakersData,
121-
sessionsData: cachedSessionsData,
84+
speakersData,
85+
sessionsData,
12286
speakersById,
12387
sessionsById,
12488
};
File renamed without changes.

src/env.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
/// <reference path="../.astro/types.d.ts" />
22
/// <reference types="astro/client" />
3+
4+
interface ImportMetaEnv {
5+
readonly EP_SESSIONS_API: string;
6+
readonly EP_SPEAKERS_API: string;
7+
}
8+
9+
interface ImportMeta {
10+
readonly env: ImportMetaEnv;
11+
}

src/utils/dataLoader.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const mode = import.meta.env.MODE;
2+
export async function loadData(apiUrl: any) {
3+
if (!apiUrl) {
4+
console.warn(`No API URL provided`);
5+
return {};
6+
}
7+
8+
try {
9+
console.log(`Fetching data from: ${apiUrl}`);
10+
const response = await fetch(apiUrl);
11+
12+
if (!response.ok) {
13+
throw new Error(
14+
`Failed to fetch data: ${response.status} ${response.statusText}`
15+
);
16+
}
17+
18+
return await response.json();
19+
} catch (error) {
20+
console.error(`Error loading data:`, error);
21+
return {};
22+
}
23+
}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"jsx": "react-jsx",
77
"jsxImportSource": "react",
88
"paths": {
9+
"@utils/*": ["src/utils/*"],
910
"@data/*": ["src/data/*"],
1011
"@components/*": ["src/components/*"],
1112
"@sections/*": ["src/components/sections/*"],

0 commit comments

Comments
 (0)