rsshub
Version:
Make RSS Great Again!
164 lines (161 loc) • 4.29 kB
JavaScript
import { i as postsToItems, n as applyLanguageToTagSlug, r as ghostFetch, t as CHANNEL_TAG_MAP } from "./utils-DeEIopw3.mjs";
//#region lib/routes/theinitium/app.ts
const APP_CATEGORY_MAP = {
latest_sc: {
channelType: "latest",
language: "zh-hans"
},
latest_tc: {
channelType: "latest",
language: "zh-hant"
},
daily_brief_sc: {
channelType: "daily-brief",
language: "zh-hans"
},
daily_brief_tc: {
channelType: "daily-brief",
language: "zh-hant"
},
whats_new_sc: {
channelType: "whatsnew",
language: "zh-hans"
},
whats_new_tc: {
channelType: "whatsnew",
language: "zh-hant"
},
report_sc: {
channelType: "feature",
language: "zh-hans"
},
report_tc: {
channelType: "feature",
language: "zh-hant"
},
opinion_sc: {
channelType: "opinion",
language: "zh-hans"
},
opinion_tc: {
channelType: "opinion",
language: "zh-hant"
},
international_sc: {
channelType: "international",
language: "zh-hans"
},
international_tc: {
channelType: "international",
language: "zh-hant"
},
mainland_sc: {
channelType: "mainland",
language: "zh-hans"
},
mainland_tc: {
channelType: "mainland",
language: "zh-hant"
},
hongkong_sc: {
channelType: "hongkong",
language: "zh-hans"
},
hongkong_tc: {
channelType: "hongkong",
language: "zh-hant"
},
taiwan_sc: {
channelType: "taiwan",
language: "zh-hans"
},
taiwan_tc: {
channelType: "taiwan",
language: "zh-hant"
}
};
const APP_CATEGORY_LABELS = {
latest_sc: "最新",
latest_tc: "最新",
daily_brief_sc: "日报",
daily_brief_tc: "日報",
whats_new_sc: "速递",
whats_new_tc: "速遞",
report_sc: "专题",
report_tc: "專題",
opinion_sc: "评论",
opinion_tc: "評論",
international_sc: "国际",
international_tc: "國際",
mainland_sc: "大陆",
mainland_tc: "大陸",
hongkong_sc: "香港",
hongkong_tc: "香港",
taiwan_sc: "台湾",
taiwan_tc: "台灣"
};
const route = {
path: "/app/:category?",
categories: ["new-media"],
example: "/theinitium/app",
parameters: { category: "Category, see below, latest_sc by default" },
features: {
requireConfig: [{
name: "INITIUM_MEMBER_COOKIE",
optional: true,
description: "端传媒会员登录后的 Cookie,用于获取付费文章全文。"
}],
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "App",
maintainers: ["quiniapiezoelectricity", "pseudoyu"],
radar: [{
source: ["theinitium.com/latest/"],
target: "/app/latest_sc"
}],
handler,
description: `Category 栏目:
| ----- | 简体中文 | 繁體中文 |
| ----- | ----------------- | ----------------- |
| 最新 | latest\\_sc | latest\\_tc |
| 日报 | daily\\_brief\\_sc | daily\\_brief\\_tc |
| 速递 | whats\\_new\\_sc | whats\\_new\\_tc |
| 专题 | report\\_sc | report\\_tc |
| 评论 | opinion\\_sc | opinion\\_tc |
| 国际 | international\\_sc | international\\_tc |
| 大陆 | mainland\\_sc | mainland\\_tc |
| 香港 | hongkong\\_sc | hongkong\\_tc |
| 台湾 | taiwan\\_sc | taiwan\\_tc |
::: tip
原 App 路由已迁移至 Ghost CMS API。播客(article\\_audio)分类已停用,请改用 \`/theinitium/channel\` 路由。
:::`
};
async function handler(ctx) {
const category = ctx.req.param("category") ?? "latest_sc";
const mapping = APP_CATEGORY_MAP[category];
if (!mapping) throw new Error(`Unknown category: ${category}. Supported: ${Object.keys(APP_CATEGORY_MAP).join(", ")}`);
const { channelType, language } = mapping;
const baseTag = CHANNEL_TAG_MAP[channelType] ?? channelType;
let filter = "";
if (baseTag === "") filter = `tag:hash-${language}`;
else filter = `tag:${applyLanguageToTagSlug(baseTag, language)}`;
const items = await postsToItems((await ghostFetch("posts", {
include: "tags,authors",
limit: "20",
filter
})).posts);
const label = APP_CATEGORY_LABELS[category] ?? category;
return {
title: `${language === "zh-hans" ? "端传媒" : "端傳媒"} - ${label}`,
link: "https://theinitium.com/latest/",
icon: "https://theinitium.com/favicon.ico",
language: language === "zh-hans" ? "zh-CN" : "zh-TW",
item: items
};
}
//#endregion
export { route };