UNPKG

rsshub

Version:
187 lines (148 loc) 9.11 kB
import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { t as got_default } from "./got-BDnf4rdT.mjs"; import { t as timezone } from "./timezone-DE--ze1V.mjs"; import { load } from "cheerio"; //#region lib/routes/chinawriter/index.ts const route = { path: "/:id{.+}?", categories: ["new-media"], example: "/chinawriter", parameters: { id: "栏目 id,见下表,默认为首页" }, description: `| 服务 | 文学奖项 | | ------ | -------- | | 403937 | 403973 | | 新闻 | 访谈 | 艺术 | | ------ | ------ | ------ | | 403990 | 403997 | 404002 | | 理论评论 | 文史 | 科幻 | 书汇 | 新作品 | | -------- | ------ | ------ | ------ | ------ | | 404029 | 404057 | 404078 | 404058 | 404015 | | 世界文坛 | 民族文艺 | 网络文学 | 儿童文学 | | -------- | -------- | -------- | -------- | | 404085 | 404086 | 404022 | 404059 | <details> <summary>更多栏目</summary> #### 会员 | 新发展会员名单 | 讣告 | | -------------- | ------------- | | 403978/403979 | 403978/403981 | #### 文学奖项 | 其他文学奖项 | | ------------- | | 403973/419349 | #### 新闻 | 时政新闻 | 中国作协 | 主席 | 党组书记 | 各地文讯 | | ------------- | ------------- | ------------- | ------------- | ------------- | | 403990/403991 | 403990/403993 | 403990/441519 | 403990/441520 | 403990/403994 | #### 艺术 | 新闻 | 影视 | 舞台 | 人物 | 展览 | 书画 | | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | | 404002/404003 | 404002/419388 | 404002/419389 | 404002/404005 | 404002/419390 | 404002/419391 | #### 理论评论 | 重要理论文章 | 理论热点 | 文学评论 | 创作谈 | 争鸣 | 综述 | 中国当代文学研究 | | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | -------------------- | | 404029/419350 | 404029/419351 | 404029/404030 | 404029/404032 | 404029/404033 | 404029/404034 | 404087/404988/425775 | #### 文史 | 文坛轶事 | 文史漫谈 | 重温经典 | 版本研究 | 名人手迹 | 茅盾文学奖获奖作家研究 | | ------------- | ------------- | ------------- | ------------- | ------------- | ---------------------- | | 404057/404063 | 404057/442005 | 404057/419384 | 404057/419387 | 404057/419382 | 404087/404988/429369 | #### 科幻 | 动态 | 评论 | 作家印象 | 作品 | 科声幻影 | | ------------- | ------------- | ------------- | ------------- | ------------- | | 404078/404079 | 404078/404080 | 404078/404081 | 404078/404083 | 404078/404084 | #### 书汇 | 书摘 | 图书排行 | | ------------- | ------------- | | 404058/404067 | 404058/404069 | #### 新作品 | 小说 | 诗歌 | 散文 | 纪实 | 其他 | | ------------- | ------------- | ------------- | ------------- | ------------- | | 404015/404017 | 404015/404020 | 404015/404018 | 404015/404019 | 404015/419926 | | 平台推荐 | 本周之星 | 2018518 日前原创作品 | | ------------- | ------------- | ---------------------------- | | 404015/419789 | 404015/431511 | 404009 | | 人民文学 | 诗刊 | 民族文学 | 收获 | 十月 | | -------------------- | -------------------- | -------------------- | -------------------- | -------------------- | | 404015/416204/418925 | 404015/416204/418926 | 404015/416204/418928 | 404015/416204/418958 | 404015/416204/418956 | | 小说选刊 | 北京文学 | 上海文学 | 天津文学 | 草原 | | -------------------- | -------------------- | -------------------- | -------------------- | -------------------- | | 404015/416204/418929 | 404015/416204/418954 | 404015/416204/418962 | 404015/416204/419004 | 404015/416204/418989 | | 黄河 | 江南 | 钟山 | 广州文艺 | 湖南文学 | | -------------------- | -------------------- | -------------------- | -------------------- | -------------------- | | 404015/416204/426204 | 404015/416204/418957 | 404015/416204/418984 | 404015/416204/419881 | 404015/416204/419156 | | 山西文学 | 花城 | 青年作家 | 雨花 | 红豆 | | -------------------- | -------------------- | -------------------- | -------------------- | -------------------- | | 404015/416204/419827 | 404015/416204/418960 | 404015/416204/418967 | 404015/416204/419885 | 404015/416204/418993 | | 长江文艺 | 中国作家 | 青年文学 | 美文 | 芙蓉 | | -------------------- | -------------------- | -------------------- | -------------------- | -------------------- | | 404015/416204/418961 | 404015/416204/418927 | 404015/416204/418979 | 404015/416204/418985 | 404015/416204/418986 | | 长城 | 福建文学 | 啄木鸟 | 芳草 | 小说月报 | | -------------------- | -------------------- | -------------------- | -------------------- | -------------------- | | 404015/416204/418987 | 404015/416204/419003 | 404015/416204/435225 | 404015/416204/424311 | 404015/416204/418963 | #### 世界文坛 | 视点 | 译介 | 作家印象 | 文学评论 | 影像艺术 | 作品推介 | | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | | 404085/404090 | 404085/431803 | 404085/404091 | 404085/404092 | 404085/404093 | 404085/404095 | #### 民族文艺 | 动态 | 品评 | 作家印象 | 作品 | 影像 | | ------------- | ------------- | ------------- | ------------- | ------------- | | 404086/404098 | 404086/404101 | 404086/404099 | 404086/404100 | 404086/404102 | #### 网络文学 | 动态 | 观察 | 访谈 | 中国网络小说排行榜 | | ------------- | ------------- | ------------- | ------------------ | | 404022/404023 | 404022/404027 | 404022/404024 | 404022/404028 | #### 儿童文学 | 视点 | 文学评论 | 作家印象 | 作品推介 | 动漫艺术 | | ------------- | ------------- | ------------- | ------------- | ------------- | | 404059/404071 | 404059/404072 | 404059/404073 | 404059/404075 | 404059/404076 | </details>`, name: "栏目", maintainers: ["nczitzk"], handler }; async function handler(ctx) { const id = ctx.req.param("id"); const limit = ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 40; const rootUrl = "http://www.chinawriter.com.cn"; const currentUrl = `${new URL(id ?? "", rootUrl).href}/`; const { data: response } = await got_default(currentUrl); const $ = load(response); let items = ($("main div.inner").find("a").length === 0 ? $("body") : $("main div.inner")).find("a").toArray().filter((item) => /(?:\/\d{4}){2}\/\w+-\w+\.html/.test($(item).prop("href"))).slice(0, limit).map((item) => { const $item = $(item); const link = $item.prop("href"); return { title: $item.text(), link: link.startsWith("http") ? link : new URL($item.prop("href"), rootUrl).href }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { try { const { data: detailResponse } = await got_default(item.link); const content = load(detailResponse); content("div.end_shared").remove(); const info = content("div.end_info").text().trim(); item.title = content("#newstit").text() || content("h6.end_tit").text(); item.description = content("div.end_article").html(); item.author = info ? info.match(/\|(.*)\d{4}/)[1].trim() : ""; item.category = [...new Set([...content("div.location a.clink").slice(1).toArray().map((c) => content(c).text()), info ? info.match(/^(.*)\|/)[1].replaceAll("来源:", "").trim() : void 0].filter((c) => Boolean(c)))]; item.pubDate = content("div.end_info em").text() ? timezone(parseDate(content("div.end_info em").text(), "YYYY年MM月DD日HH:mm"), 8) : parseDate(content("meta[name=\"publishdate\"]").prop("content")); } catch {} return item; }))); const icon = new URL($("link[rel=\"icon\"]").prop("href"), rootUrl).href; return { item: items, title: $("title").text().replaceAll("--", " - "), link: currentUrl, description: $("meta[name=\"description\"]").prop("content"), language: "zh-CN", image: new URL($("h1.logo a img").prop("src"), rootUrl).href, icon, logo: icon, subtitle: $("meta[name=\"keywords\"]").prop("content"), allowEmpty: true }; } //#endregion export { route };