Skip to content

Commit dd88055

Browse files
authored
feat(route): add 穿越火线CFHD专区资讯中心 (DIYgod#15601)
* feat(route): add 穿越火线CFHD专区资讯中心 * fix: remove enclosure_url
1 parent 245e618 commit dd88055

File tree

2 files changed

+144
-2
lines changed

2 files changed

+144
-2
lines changed

lib/routes/qq/cfhd/index.ts

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import { Route } from '@/types';
2+
3+
import cache from '@/utils/cache';
4+
import got from '@/utils/got';
5+
import { load } from 'cheerio';
6+
import iconv from 'iconv-lite';
7+
import timezone from '@/utils/timezone';
8+
import { parseDate } from '@/utils/parse-date';
9+
10+
export const handler = async (ctx) => {
11+
const { category = '60847' } = ctx.req.param();
12+
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 12;
13+
14+
const rootUrl = 'https://cfhd.cf.qq.com';
15+
const rootImageUrl = 'https://game.gtimg.cn';
16+
const currentUrl = new URL(`webplat/info/news_version3/37427/59139/59140/${category}/m22510/list_1.shtml`, rootUrl).href;
17+
18+
const { data: response } = await got(currentUrl, {
19+
responseType: 'buffer',
20+
});
21+
22+
const $ = load(iconv.decode(response, 'gbk'));
23+
24+
const language = $('html').prop('lang');
25+
26+
let items = $('div.news-list-item ul li.list-item')
27+
.slice(0, limit)
28+
.toArray()
29+
.map((item) => {
30+
item = $(item);
31+
32+
return {
33+
title: item.find('p').text(),
34+
pubDate: parseDate(item.find('span.date').text()),
35+
link: new URL(item.find('a.clearfix').prop('href'), rootUrl).href,
36+
};
37+
});
38+
39+
items = await Promise.all(
40+
items.map((item) =>
41+
cache.tryGet(item.link, async () => {
42+
const { data: detailResponse } = await got(item.link, {
43+
responseType: 'buffer',
44+
});
45+
46+
const $$ = load(iconv.decode(detailResponse, 'gbk'));
47+
48+
const title = $$('div.news-details-title h4').text();
49+
const description = $$('div.news-details-cont').html();
50+
const image = $$('div.news-details-cont img').first().prop('src');
51+
52+
item.title = title;
53+
item.description = description;
54+
item.pubDate = timezone(parseDate($$('p.news-details-p1').text().trim()), +8);
55+
item.content = {
56+
html: description,
57+
text: $$('div.news-details-cont').text(),
58+
};
59+
item.image = image;
60+
item.banner = image;
61+
item.language = language;
62+
63+
return item;
64+
})
65+
)
66+
);
67+
68+
const image = new URL('images/cfhd/web202305/logo.png', rootImageUrl).href;
69+
70+
return {
71+
title: `${$('title').text().split(/-/)[0]} - ${$('li.cur').text()}`,
72+
description: $('meta[name="Description"]').prop('content'),
73+
link: currentUrl,
74+
item: items,
75+
allowEmpty: true,
76+
image,
77+
author: $('meta[name="author"]').prop('content'),
78+
language,
79+
};
80+
};
81+
82+
export const route: Route = {
83+
path: '/cfhd/news/:category?',
84+
name: '穿越火线 CFHD 专区资讯中心',
85+
url: 'cfhd.cf.qq.com',
86+
maintainers: ['nczitzk'],
87+
handler,
88+
example: '/qq/cfhd/news',
89+
parameters: { category: '分类,默认为 60847,即最新,可在对应分类页 URL 中找到' },
90+
description: `:::tip
91+
若订阅 [穿越火线 CFHD 专区资讯中心 - 最新](https://cfhd.cf.qq.com/webplat/info/news_version3/37427/59139/59140/60847/m22510/list_1.shtml),网址为 \`https://cfhd.cf.qq.com/webplat/info/news_version3/37427/59139/59140/60847/m22510/list_1.shtml\`。截取 \`https://cfhd.cf.qq.com/webplat/info/news_version3/37427/59139/59140/\` 到末尾 \`/m22510/list_1.shtml\` 的部分 \`60847\` 作为参数填入,此时路由为 [\`/qq/cfhd/news/60847\`](https://rsshub.app/qq/cfhd/news/60847)。
92+
:::
93+
94+
| 分类 | ID |
95+
| ----------------------------------------------------------------------------------------------------- | --------------------------------------------- |
96+
| [最新](https://cfhd.cf.qq.com/webplat/info/news_version3/37427/59139/59140/60847/m22510/list_1.shtml) | [60847](https://rsshub.app/qq/cfhd/news/60847) |
97+
| [公告](https://cfhd.cf.qq.com/webplat/info/news_version3/37427/59139/59140/59625/m22510/list_1.shtml) | [59625](https://rsshub.app/qq/cfhd/news/59625) |
98+
| [版本](https://cfhd.cf.qq.com/webplat/info/news_version3/37427/59139/59140/60850/m22510/list_1.shtml) | [60850](https://rsshub.app/qq/cfhd/news/60850) |
99+
| [赛事](https://cfhd.cf.qq.com/webplat/info/news_version3/37427/59139/59140/59626/m22510/list_1.shtml) | [59626](https://rsshub.app/qq/cfhd/news/59626) |
100+
| [杂谈](https://cfhd.cf.qq.com/webplat/info/news_version3/37427/59139/59140/59624/m22510/list_1.shtml) | [59624](https://rsshub.app/qq/cfhd/news/59624) |
101+
`,
102+
categories: ['game'],
103+
104+
features: {
105+
requireConfig: false,
106+
requirePuppeteer: false,
107+
antiCrawler: false,
108+
supportRadar: true,
109+
supportBT: false,
110+
supportPodcast: false,
111+
supportScihub: false,
112+
},
113+
radar: [
114+
{
115+
title: '穿越火线 CFHD 专区资讯中心 - 最新',
116+
source: ['cfhd.cf.qq.com/webplat/info/news_version3/37427/59139/59140/60847/m22510/list_1.shtml'],
117+
target: '/cfhd/news/60847',
118+
},
119+
{
120+
title: '穿越火线 CFHD 专区资讯中心 - 公告',
121+
source: ['cfhd.cf.qq.com/webplat/info/news_version3/37427/59139/59140/59625/m22510/list_1.shtml'],
122+
target: '/cfhd/news/59625',
123+
},
124+
{
125+
title: '穿越火线 CFHD 专区资讯中心 - 版本',
126+
source: ['cfhd.cf.qq.com/webplat/info/news_version3/37427/59139/59140/60850/m22510/list_1.shtml'],
127+
target: '/cfhd/news/60850',
128+
},
129+
{
130+
title: '穿越火线 CFHD 专区资讯中心 - 赛事',
131+
source: ['cfhd.cf.qq.com/webplat/info/news_version3/37427/59139/59140/59626/m22510/list_1.shtml'],
132+
target: '/cfhd/news/59626',
133+
},
134+
{
135+
title: '穿越火线 CFHD 专区资讯中心 - 杂谈',
136+
source: ['cfhd.cf.qq.com/webplat/info/news_version3/37427/59139/59140/59624/m22510/list_1.shtml'],
137+
target: '/cfhd/news/59624',
138+
},
139+
],
140+
};

lib/routes/qq/namespace.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { Namespace } from '@/types';
22

33
export const namespace: Namespace = {
4-
name: '腾讯新闻较真查证平台',
5-
url: 'ac.qq.com',
4+
name: '腾讯网',
5+
url: 'qq.com',
6+
categories: ['new-media'],
7+
description: '',
68
};

0 commit comments

Comments
 (0)