feat(route): add 留园网新闻 (#12265)
* feat(route): add 留园网新闻 * fix: add filter for links * fix: maintainer and docs tag ---------
This commit is contained in:
parent
1a1631ee4d
commit
9d926d32ed
|
|
@ -2997,6 +2997,33 @@ column 为 third 时可选的 category:
|
|||
|
||||
<Route author="nczitzk" example="/6park/chan1/keywords/都市" path="/6park/:id/keywords/:keyword?" :paramsDesc="['分站,见上表', '关键字']"/>
|
||||
|
||||
### 新闻栏目
|
||||
|
||||
<Route author="nczitzk" example="/6park/news" path="/6park/news/:site?/:id?" :paramsDesc="['分站,见下表,默认为 newspark', '栏目 id']">
|
||||
|
||||
分站
|
||||
|
||||
| newspark | local |
|
||||
| -------- | ----- |
|
||||
|
||||
::: tip 提示
|
||||
|
||||
若订阅 [时政](https://www.6parknews.com/newspark/index.php?type=1),其网址为 <https://www.6parknews.com/newspark/index.php?type=1>,其中 `newspark` 为分站,`1` 为栏目 id。
|
||||
|
||||
若订阅 [美国](https://local.6parknews.com/index.php?type_id=1),其网址为 <https://local.6parknews.com/index.php?type_id=1>,其中 `local` 为分站,`1` 为栏目 id。
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
### 头条精选
|
||||
|
||||
<Route author="nczitzk" example="/6park/news/newspark/gold" path="/6park/news/newspark/gold"/>
|
||||
|
||||
### 新闻搜索
|
||||
|
||||
<Route author="nczitzk" example="/6park/news/newspark/keywords/搜索" path="/6park/news/newspark/keywords/:keyword?" :paramsDesc="['关键字']"/>
|
||||
|
||||
## 隆众资讯
|
||||
|
||||
### 资讯
|
||||
|
|
|
|||
|
|
@ -3636,7 +3636,7 @@ router.get('/voa/day-photos', lazyloadRouteHandler('./routes/voa/day-photos'));
|
|||
router.get('/voa/:language/:channel?', lazyloadRouteHandler('./routes/voa/index'));
|
||||
|
||||
// 留园网
|
||||
router.get('/6park/:id?/:type?/:keyword?', lazyloadRouteHandler('./routes/6park/index'));
|
||||
// router.get('/6park/:id?/:type?/:keyword?', lazyloadRouteHandler('./routes/6park/index'));
|
||||
|
||||
// 哔嘀影视
|
||||
// router.get('/mp4er/:type?/:caty?/:area?/:year?/:order?', lazyloadRouteHandler('./routes/mp4er/index'));
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id || 'chan1';
|
||||
const type = ctx.params.type || '';
|
||||
const keyword = ctx.params.keyword || '';
|
||||
const id = ctx.params.id ?? 'chan1';
|
||||
const type = ctx.params.type ?? '';
|
||||
const keyword = ctx.params.keyword ?? '';
|
||||
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50;
|
||||
|
||||
const rootUrl = 'https://club.6parkbbs.com';
|
||||
const indexUrl = `${rootUrl}/${id}/index.php`;
|
||||
|
|
@ -17,31 +21,35 @@ module.exports = async (ctx) => {
|
|||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('#d_list ul li, #thread_list li, .t_l .t_subject')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
let items = $('#d_list ul li, #thread_list li, .t_l .t_subject')
|
||||
.toArray()
|
||||
.slice(0, limit)
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
const a = item.find('a').eq(0);
|
||||
|
||||
const a = item.find('a').first();
|
||||
|
||||
return {
|
||||
link: `${rootUrl}/${id}/${a.attr('href')}`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.title = content('title').text().replace(' -6park.com', '');
|
||||
item.author = detailResponse.data.match(/送交者: .*>(.*)<.*\[/)[1];
|
||||
item.pubDate = new Date(detailResponse.data.match(/于 (.*) 已读/)[1]).toUTCString();
|
||||
item.pubDate = timezone(parseDate(detailResponse.data.match(/于 (.*) 已读/)[1], 'YYYY-MM-DD h:m'), +8);
|
||||
item.description = content('pre')
|
||||
.html()
|
||||
.replace(/<p><\/p>/g, '')
|
||||
.replace(/<font color="#E6E6DD">6park.com<\/font>/g, '');
|
||||
|
||||
return item;
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
module.exports = {
|
||||
'/:id?': ['nczitzk'],
|
||||
'/:id/gold': ['nczitzk'],
|
||||
'/:id/keywords/:keyword?': ['nczitzk'],
|
||||
'/news/:site?/:id?': ['nczitzk'],
|
||||
'/news/newspark/gold': ['nczitzk'],
|
||||
'/news/newspark/keywords/:keyword?': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const site = ctx.params.site ?? 'newspark';
|
||||
const id = ctx.params.id ?? '';
|
||||
const keyword = ctx.params.keyword ?? '';
|
||||
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50;
|
||||
|
||||
const isLocal = site === 'local';
|
||||
|
||||
const rootUrl = `https://${isLocal ? site : 'www'}.6parknews.com`;
|
||||
const indexUrl = `${rootUrl}${isLocal ? '' : '/newspark'}/index.php`;
|
||||
const currentUrl = `${indexUrl}${keyword ? `?act=newssearch&app=news&keywords=${keyword}&submit=查询` : id ? (isNaN(id) ? `?act=${id}` : isLocal ? `?type_id=${id}` : `?type=${id}`) : ''}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let items = $('#d_list ul li, #thread_list li, .t_l .t_subject')
|
||||
.toArray()
|
||||
.slice(0, limit)
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const a = item.find('a').first();
|
||||
const link = a.attr('href');
|
||||
|
||||
return {
|
||||
title: a.text(),
|
||||
link: /^http/.test(link) ? link : `${rootUrl}/${/^view/.test(link) ? `newspark/${link}` : link}`,
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items
|
||||
.filter((item) => /6parknews\.com/.test(item.link))
|
||||
.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
try {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
const matches = detailResponse.data.match(/新闻来源:(.*?)于.*(\d{4}-\d{2}-\d{2} \d{1,2}:\d{1,2}:\d{1,2})/);
|
||||
|
||||
item.title = content('h2').text();
|
||||
item.author = matches[1].trim();
|
||||
item.pubDate = timezone(parseDate(matches[2], 'YYYY-MM-DD h:m'), +8);
|
||||
item.description = content('#shownewsc')
|
||||
.html()
|
||||
.replace(/<p><\/p>/g, '');
|
||||
} catch (e) {
|
||||
// no-empty
|
||||
}
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
module.exports = {
|
||||
'6parkbbs.com': {
|
||||
_name: '留园网',
|
||||
club: [
|
||||
{
|
||||
title: '分站',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#liu-yuan-wang',
|
||||
source: ['/:id/index.php', '/'],
|
||||
target: '/6park/:id?',
|
||||
},
|
||||
{
|
||||
title: '精华区',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#liu-yuan-wang',
|
||||
source: ['/:id/index.php', '/'],
|
||||
target: '/6park/:id/gold',
|
||||
},
|
||||
{
|
||||
title: '搜索关键字',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#liu-yuan-wang',
|
||||
source: ['/:id/index.php', '/'],
|
||||
target: (params, url) => `/6park/:id/keywords/${new URL(url).searchParams.get('keywords')}`,
|
||||
},
|
||||
],
|
||||
local: [
|
||||
{
|
||||
title: '新闻栏目',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#liu-yuan-wang',
|
||||
source: ['/index.php', '/'],
|
||||
target: (params, url) => `/6park/news/local/${new URL(url).searchParams.get('type_id')}`,
|
||||
},
|
||||
{
|
||||
title: '头条精选',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#liu-yuan-wang',
|
||||
source: ['/index.php', '/'],
|
||||
target: '/6park/news/newspark/gold',
|
||||
},
|
||||
{
|
||||
title: '新闻搜索',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#liu-yuan-wang',
|
||||
source: ['/index.php', '/'],
|
||||
target: (params, url) => `/6park/news/newspark/keywords/${new URL(url).searchParams.get('keywords')}`,
|
||||
},
|
||||
],
|
||||
newspark: [
|
||||
{
|
||||
title: '新闻栏目',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#liu-yuan-wang',
|
||||
source: ['/newspark/index.php', '/'],
|
||||
target: (params, url) => `/6park/news/newspark/${new URL(url).searchParams.get('type')}`,
|
||||
},
|
||||
{
|
||||
title: '头条精选',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#liu-yuan-wang',
|
||||
source: ['/newspark/index.php', '/'],
|
||||
target: '/6park/news/newspark/gold',
|
||||
},
|
||||
{
|
||||
title: '新闻搜索',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#liu-yuan-wang',
|
||||
source: ['/newspark/index.php', '/'],
|
||||
target: (params, url) => `/6park/news/newspark/keywords/${new URL(url).searchParams.get('keywords')}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/news/:site?/:id?/:keyword?', require('./news'));
|
||||
router.get('/:id?/:type?/:keyword?', require('./'));
|
||||
};
|
||||
Loading…
Reference in New Issue