Skip to content

Instantly share code, notes, and snippets.

@cfjedimaster
Created March 10, 2026 17:44
Show Gist options
  • Select an option

  • Save cfjedimaster/c85dc899069e3034b427bfedce0836c3 to your computer and use it in GitHub Desktop.

Select an option

Save cfjedimaster/c85dc899069e3034b427bfedce0836c3 to your computer and use it in GitHub Desktop.
import type { LiveLoader } from 'astro/loaders';
interface Genre {
id: string;
name: string;
}
export function genreLoader(config: { apiKey: string }): LiveLoader<Genre> {
return {
name: 'genre-loader',
loadCollection: async () => {
try {
let genreReq = await fetch('https://api.themoviedb.org/3/genre/movie/list', {
headers: {
'Authorization': `Bearer ${config.apiKey}`,
'accept':'application/json'
}
});
let genreData = await genreReq.json();
console.log(`i got ${genreData.genres.length} genres`);
return {
genres: genreData.genres.map((g:Genre) => ({
id: g.id,
data: g,
})),
};
} catch (error) {
console.log('------------- ERRROR --------');
return {
error: new Error('Failed to load genres mf', { cause: error }),
};
}
},
loadEntry: async ({ filter }) => {
/*
try {
// filter will be { id: "some-id" } when called with a strin
const article = await fetchFromCMS({
apiKey: config.apiKey,
type: 'article',
id: filter.id,
});
if (!article) {
return {
error: new Error('Article not found'),
};
}
return {
id: article.id,
data: article,
rendered: {
html: article.htmlContent,
},
};
} catch (error) {
return {
error: new Error('Failed to load article', { cause: error }),
};
}
*/
return {};
},
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment