From d63ece212fb89c591f1b13d0706f7a4e2bc18c73 Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Wed, 13 Apr 2022 17:23:23 +0800 Subject: [PATCH] fix(route): yystv change selector path, add radar and refactor to V2 (#9529) * fix(route): change selector path, add radar and refactor to V2 * fix: use parse-date utils * fix: use https --- lib/router.js | 4 +-- lib/{routes => v2}/yystv/category.js | 16 ++++----- lib/{routes => v2}/yystv/docs.js | 4 +-- lib/v2/yystv/maintainer.js | 4 +++ lib/v2/yystv/radar.js | 49 ++++++++++++++++++++++++++++ lib/v2/yystv/router.js | 4 +++ 6 files changed, 69 insertions(+), 12 deletions(-) rename lib/{routes => v2}/yystv/category.js (71%) rename lib/{routes => v2}/yystv/docs.js (87%) create mode 100644 lib/v2/yystv/maintainer.js create mode 100644 lib/v2/yystv/radar.js create mode 100644 lib/v2/yystv/router.js diff --git a/lib/router.js b/lib/router.js index abe4e0df1a..b32168d332 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1456,8 +1456,8 @@ router.get('/gamersky/news', lazyloadRouteHandler('./routes/gamersky/news')); router.get('/gamersky/ent/:category', lazyloadRouteHandler('./routes/gamersky/ent')); // 游研社 -router.get('/yystv/category/:category', lazyloadRouteHandler('./routes/yystv/category')); -router.get('/yystv/docs', lazyloadRouteHandler('./routes/yystv/docs')); +// router.get('/yystv/category/:category', lazyloadRouteHandler('./routes/yystv/category')); +// router.get('/yystv/docs', lazyloadRouteHandler('./routes/yystv/docs')); // konami router.get('/konami/pesmobile/:lang?/:os?', lazyloadRouteHandler('./routes/konami/pesmobile')); diff --git a/lib/routes/yystv/category.js b/lib/v2/yystv/category.js similarity index 71% rename from lib/routes/yystv/category.js rename to lib/v2/yystv/category.js index d731274c48..f7852481ca 100644 --- a/lib/routes/yystv/category.js +++ b/lib/v2/yystv/category.js @@ -1,10 +1,10 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const date = require('@/utils/date'); +const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const category = ctx.params.category; - const url = `http://www.yystv.cn/b/${category}`; + const url = `https://www.yystv.cn/b/${category}`; const response = await got({ method: 'get', url, @@ -18,8 +18,8 @@ module.exports = async (ctx) => { .map(function () { const info = { title: $(this).find('.b-main-info-title').text(), - link: 'http://www.yystv.cn' + $(this).find('.b-main-info-title a').attr('href'), - pubDate: date($(this).find('.b-main-createtime').text()), + link: 'https://www.yystv.cn' + $(this).find('.b-main-info-title a').attr('href'), + pubDate: parseRelativeDate($(this).find('.b-main-createtime').text()), author: $(this).find('.b-author').text(), }; return info; @@ -31,8 +31,8 @@ module.exports = async (ctx) => { .map(function () { const info = { title: $('.list-article-title', this).text(), - link: 'http://www.yystv.cn' + $('a', this).attr('href'), - pubDate: date($('.c-999', this).text()), + link: 'https://www.yystv.cn' + $('a', this).attr('href'), + pubDate: $('.c-999', this).text().includes('-') ? parseDate($('.c-999', this).text()) : parseRelativeDate($('.c-999', this).text()), author: $('.handler-author-link', this).text(), }; return info; @@ -49,7 +49,7 @@ module.exports = async (ctx) => { method: 'get', }); const $ = cheerio.load(r.data); - return $('.doc-content div').html(); + return $('.doc-content.rel').html(); }); return currentValue; }) @@ -58,7 +58,7 @@ module.exports = async (ctx) => { await getDescription(items).then(() => { ctx.state.data = { title: '游研社-' + $('title').text(), - link: `http://www.yystv.cn/b/${category}`, + link: `https://www.yystv.cn/b/${category}`, item: items, }; }); diff --git a/lib/routes/yystv/docs.js b/lib/v2/yystv/docs.js similarity index 87% rename from lib/routes/yystv/docs.js rename to lib/v2/yystv/docs.js index 68d70d8097..64d08c6f58 100644 --- a/lib/routes/yystv/docs.js +++ b/lib/v2/yystv/docs.js @@ -1,6 +1,6 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const date = require('@/utils/date'); +const { parseRelativeDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const url = `https://www.yystv.cn/docs`; @@ -18,7 +18,7 @@ module.exports = async (ctx) => { const info = { title: $('.list-article-title', this).text(), link: 'https://www.yystv.cn' + $('a', this).attr('href'), - pubDate: date($('.c-999', this).text()), + pubDate: parseRelativeDate($('.c-999', this).text()), author: $('.handler-author-link', this).text(), description: $('.list-article-intro', this).text(), }; diff --git a/lib/v2/yystv/maintainer.js b/lib/v2/yystv/maintainer.js new file mode 100644 index 0000000000..16d3088eae --- /dev/null +++ b/lib/v2/yystv/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/category/:category': ['LightStrawberry'], + '/docs': ['HaitianLiu'], +}; diff --git a/lib/v2/yystv/radar.js b/lib/v2/yystv/radar.js new file mode 100644 index 0000000000..0f594fc83f --- /dev/null +++ b/lib/v2/yystv/radar.js @@ -0,0 +1,49 @@ +module.exports = { + 'yystv.cn': { + _name: '游研社', + '.': [ + { + title: '推游', + docs: 'https://docs.rsshub.app/game.html#you-yan-she', + source: '/b/recommend', + target: '/yystv/category/recommend', + }, + { + title: '游戏史', + docs: 'https://docs.rsshub.app/game.html#you-yan-she', + source: '/b/history', + target: '/yystv/category/history', + }, + { + title: '大事件', + docs: 'https://docs.rsshub.app/game.html#you-yan-she', + source: '/b/big', + target: '/yystv/category/big', + }, + { + title: '文化', + docs: 'https://docs.rsshub.app/game.html#you-yan-she', + source: '/b/culture', + target: '/yystv/category/culture', + }, + { + title: '趣闻', + docs: 'https://docs.rsshub.app/game.html#you-yan-she', + source: '/b/news', + target: '/yystv/category/news', + }, + { + title: '经典回顾', + docs: 'https://docs.rsshub.app/game.html#you-yan-she', + source: '/b/retro', + target: '/yystv/category/retro', + }, + { + title: '全部文章', + docs: 'https://docs.rsshub.app/game.html#you-yan-she', + source: '/docs', + target: '/yystv/docs', + }, + ], + }, +}; diff --git a/lib/v2/yystv/router.js b/lib/v2/yystv/router.js new file mode 100644 index 0000000000..b5ab59d89a --- /dev/null +++ b/lib/v2/yystv/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/category/:category', require('./category')); + router.get('/docs', require('./docs')); +};