rsshub
Version:
Make RSS Great Again!
119 lines (116 loc) • 4.77 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import path from "node:path";
//#region lib/routes/straitstimes/index.ts
init_esm_shims();
const route = {
path: "/:category?/:section?",
categories: ["traditional-media"],
example: "/straitstimes/singapore",
parameters: {
category: "Category, see below for more information",
section: "Section, see below for more information"
},
features: {
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
requireConfig: false
},
name: "News",
maintainers: ["quiniapiezoelectricity"],
handler,
description: `
| Category | \`:category\` |
| ---------------------- | --------------------------- |
| Singapore | \`singapore\` |
| Asia | \`asia\` |
| World | \`world\` |
| Opinion | \`opinion\` |
| Life | \`life\` |
| Business | \`business\` |
| Jobs | \`jobs\` |
| Parenting & Education | \`parenting-and-education\` |
| Food | \`food\` |
| Tech | \`tech\` |
| Sport | \`sport\` |
| Podcasts | \`podcasts\` |,
| Section | \`:section\` |
| ---------------------- | --------------------------- |
| Top Stories | \`top-stories\` |
| Latest | \`latest\` |`,
radar: [{
source: ["www.straitstimes.com/:category"],
target: "/:category"
}, {
source: ["www.straitstimes.com"],
target: "/"
}]
};
async function handler(ctx) {
const category = ctx.req.param("category") ? ctx.req.param("category").toLowerCase() : "singapore";
const section = ctx.req.param("section") ? ctx.req.param("section").toLowerCase() : void 0;
const apiKey = "T9XUJM9rAZoLOd2CAx2wCBSTrm3xoyPw";
const platform = "iosflex";
let feed;
feed = (await got_default({
method: "get",
url: `https://newsapi.sphdigital.com/v2/feed/section/st?page=1&platform=${platform}§ion=${category}/star&subscribed=false&version=4.0`,
headers: { "x-api-key": apiKey }
})).data.data;
const sections = new Set(feed.filter((item) => item.items[0].itemType === "SectionFooter").map((items$1) => items$1.items[0].sectionFooterData.link.id));
let slug = section && sections.has(`${category}-${section}-more/star`) ? `${category}-${section}-more/star` : void 0;
if (section === void 0) {
for (const section$1 of [
"latest",
"top-picks",
"top-stories"
]) if (sections.has(`${category}-${section$1}-more/star`)) {
slug = `${category}-${section$1}-more/star`;
break;
}
}
if (slug) feed = (await got_default({
method: "get",
url: `https://newsapi.sphdigital.com/v2/feed/section/st?page=1&platform=${platform}§ion=${slug}&subscribed=false&version=4.0`,
headers: { "x-api-key": apiKey }
})).data.data;
const articles = feed.filter((item) => item.items[0].itemType === "Article");
const items = await Promise.all(articles.map((item) => cache_default.tryGet(item.items[0].articleData.url, async () => {
const article = item.items[0].articleData;
if (article.authors) item.author = article.authors.map((author) => author.name).join(", ");
if (article.keywords) item.category = article.keywords.map((keyword) => keyword.name);
item.title = article.headline;
item.pubDate = parseDate(article.publicationTime, "X");
item.updated = parseDate(article.updatedTime, "X");
item.link = article.url;
let content = article.teaser;
if (article.documentId) content = (await got_default({
method: "get",
url: `https://newsapi.sphdigital.com/v2/feed/article/st/${article.documentId}?platform=${platform}&version=4.0`,
headers: { "x-api-key": apiKey }
})).data.data.body;
item.description = art(path.join(__dirname, "templates/description-38cf9443.art"), {
images: article.images ?? [],
article: content
});
return item;
})));
return {
title: `The Strait Times - ${category.replaceAll("-", " ").toUpperCase()}`,
link: `https://www.straitstimes.com/${category.toLowerCase()}`,
item: items
};
}
//#endregion
export { route };