Files
animethemes-web/src/lib/randomTheme.js
T
Manuel S c6b2005ff2 feat: Added first letter filter to theme index (#74)
* Added series and studio index links to the search switcher.
* Added placeholder image to series and studio summary card.
* Random themes can no longer contain spoilers.
* Rewrote listbox with Reach UI to fix various issues (it's also more accessible now).
* Fixed issues with horizontal scroll.
2021-09-01 03:53:04 +02:00

25 lines
812 B
JavaScript

import { baseUrl } from "gatsby-source-animethemes/src";
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();
}