From 9d926d32ed8788fcfee8bb090a92caa28e70ab4b Mon Sep 17 00:00:00 2001
From: Ethan Shen <42264778+nczitzk@users.noreply.github.com>
Date: Sun, 9 Apr 2023 02:42:26 +0800
Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E7=95=99=E5=9B=AD?=
=?UTF-8?q?=E7=BD=91=E6=96=B0=E9=97=BB=20(#12265)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(route): add 留园网新闻
* fix: add filter for links
* fix: maintainer and docs tag
---------
---
docs/new-media.md | 27 +++++++++++
lib/router.js | 2 +-
lib/{routes => v2}/6park/index.js | 32 ++++++++-----
lib/v2/6park/maintainer.js | 8 ++++
lib/v2/6park/news.js | 76 +++++++++++++++++++++++++++++++
lib/v2/6park/radar.js | 65 ++++++++++++++++++++++++++
lib/v2/6park/router.js | 4 ++
7 files changed, 201 insertions(+), 13 deletions(-)
rename lib/{routes => v2}/6park/index.js (67%)
create mode 100644 lib/v2/6park/maintainer.js
create mode 100644 lib/v2/6park/news.js
create mode 100644 lib/v2/6park/radar.js
create mode 100644 lib/v2/6park/router.js
diff --git a/docs/new-media.md b/docs/new-media.md
index 7380c2351..28c87b430 100644
--- a/docs/new-media.md
+++ b/docs/new-media.md
@@ -2997,6 +2997,33 @@ column 为 third 时可选的 category:
<\/p>/g, '')
.replace(/6park.com<\/font>/g, '');
return item;
diff --git a/lib/v2/6park/maintainer.js b/lib/v2/6park/maintainer.js
new file mode 100644
index 000000000..dbee4fcfb
--- /dev/null
+++ b/lib/v2/6park/maintainer.js
@@ -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'],
+};
diff --git a/lib/v2/6park/news.js b/lib/v2/6park/news.js
new file mode 100644
index 000000000..9261816e5
--- /dev/null
+++ b/lib/v2/6park/news.js
@@ -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>/g, '');
+ } catch (e) {
+ // no-empty
+ }
+
+ return item;
+ })
+ )
+ );
+
+ ctx.state.data = {
+ title: $('title').text(),
+ link: currentUrl,
+ item: items,
+ };
+};
diff --git a/lib/v2/6park/radar.js b/lib/v2/6park/radar.js
new file mode 100644
index 000000000..30febe7e3
--- /dev/null
+++ b/lib/v2/6park/radar.js
@@ -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')}`,
+ },
+ ],
+ },
+};
diff --git a/lib/v2/6park/router.js b/lib/v2/6park/router.js
new file mode 100644
index 000000000..050975422
--- /dev/null
+++ b/lib/v2/6park/router.js
@@ -0,0 +1,4 @@
+module.exports = function (router) {
+ router.get('/news/:site?/:id?/:keyword?', require('./news'));
+ router.get('/:id?/:type?/:keyword?', require('./'));
+};