UNPKG

rsshub

Version:
37 lines (36 loc) 1.55 kB
import { t as rofetch } from "./ofetch-C3ts-Hud.mjs"; import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as cache_default } from "./cache-BkqOokyU.mjs"; import sanitizeHtml from "sanitize-html"; //#region lib/routes/landiannews/utils.ts const rootUrl = "https://www.landiannews.com/"; const getRenderedText = (html) => sanitizeHtml(html, { allowedTags: [], allowedAttributes: {} }); const getPubDate = (dateGmt, date) => dateGmt ? parseDate(`${dateGmt}Z`) : date ? parseDate(date) : void 0; 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 rofetch(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 rofetch(apiUrl)).map((item) => ({ title: getRenderedText(item.title.rendered), description: item.content.rendered, link: item.link, pubDate: getPubDate(item.date_gmt, item.date), 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 };