mirror of
https://github.com/AnimeThemes/animethemes-web.git
synced 2026-07-11 01:24:31 +02:00
31aee782b0
* Rewrote data layer to work on-demand. * Added several favicon formats. * Added image for SEO page previews. * Disabled GitHub pages as it no longer works. * Several other adjustments.
25 lines
797 B
JavaScript
25 lines
797 B
JavaScript
import { baseUrl } from "lib/client/api";
|
|
|
|
const backLog = [];
|
|
|
|
export async function fetchRandomTheme() {
|
|
if (!backLog.length) {
|
|
const res = await fetch(`${baseUrl}/api/animetheme?sort=random&include=anime,animethemeentries.videos&filter[has]=animethemeentries&filter[spoiler]=false`);
|
|
const json = await res.json();
|
|
|
|
backLog.push(...json.animethemes.map((theme) => {
|
|
// Remove all entries which have spoilers (the filter parameter guarantees at least one spoiler-free entry)
|
|
while (theme.animethemeentries[0].spoiler) {
|
|
theme.animethemeentries.shift();
|
|
}
|
|
|
|
return {
|
|
...theme,
|
|
entries: theme.animethemeentries
|
|
};
|
|
}));
|
|
}
|
|
|
|
return backLog.pop();
|
|
}
|