rsshub
Version:
Make RSS Great Again!
31 lines (29 loc) • 1.24 kB
JavaScript
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
//#region lib/routes/iplaysoft/utils.ts
const rootUrl = "https://www.iplaysoft.com/";
const fetchTaxonomy = async (slug, type) => {
const taxonomyUrl = `${rootUrl}wp-json/wp/v2/${type}?slug=${slug}`;
return await cache_default.tryGet(taxonomyUrl, async () => {
const taxonomyData = await ofetch_default(taxonomyUrl);
if (!taxonomyData[0] || !taxonomyData[0].id || !taxonomyData[0].name) throw new Error(`${type} ${slug} not found`);
return {
id: taxonomyData[0].id,
name: taxonomyData[0].name
};
});
};
const fetchCategory = async (categorySlug) => await fetchTaxonomy(categorySlug, "categories");
const fetchTag = async (tagSlug) => await fetchTaxonomy(tagSlug, "tags");
async function fetchNewsItems(apiUrl) {
return (await ofetch_default(apiUrl)).map((item) => ({
title: item.title.rendered,
description: item.content.rendered,
link: item.link,
pubDate: new Date(item.date_gmt).toUTCString(),
author: item._embedded.author[0].name,
category: item._embedded["wp:term"].flat().map((term) => term.name)
}));
}
//#endregion
export { fetchNewsItems as n, fetchTag as r, fetchCategory as t };