diff --git a/lib/router.js b/lib/router.js index e5bc0c12a..a1a8cacad 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2071,9 +2071,6 @@ router.get('/nciae/xsxx', lazyloadRouteHandler('./routes/universities/nciae/xsxx // cfan router.get('/cfan/news', lazyloadRouteHandler('./routes/cfan/news')); -// 搜狐 - 搜狐号 -router.get('/sohu/mp/:id', lazyloadRouteHandler('./routes/sohu/mp')); - // 腾讯企鹅号 router.get('/tencent/news/author/:mid', lazyloadRouteHandler('./routes/tencent/news/author')); diff --git a/lib/v2/sohu/maintainer.js b/lib/v2/sohu/maintainer.js new file mode 100644 index 000000000..da817c8d9 --- /dev/null +++ b/lib/v2/sohu/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/mp/:id': ['HenryQW'], +}; diff --git a/lib/routes/sohu/mp.js b/lib/v2/sohu/mp.js similarity index 70% rename from lib/routes/sohu/mp.js rename to lib/v2/sohu/mp.js index 4f265dbc3..ffa4dea4d 100644 --- a/lib/routes/sohu/mp.js +++ b/lib/v2/sohu/mp.js @@ -1,12 +1,12 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const date = require('@/utils/date'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const { id } = ctx.params; + const authorArticleAPI = `https://v2.sohu.com/author-page-api/author-articles/pc/${id}`; - const response = await got.get(`https://v2.sohu.com/author-page-api/author-articles/pc/${id}`); - + const response = await got.get(authorArticleAPI); const list = response.data.data.pcArticleVOS.splice(0, 10); let author, link; @@ -23,9 +23,10 @@ module.exports = async (ctx) => { const $ = cheerio.load(response); if (!author) { - const meta = $('#article-container h4 > a'); - author = meta.text(); - link = meta.attr('href').split('==')[0]; + const meta = $('span[data-role="original-link"]'); + author = meta.find('a').text(); + // can't get author's link on server, so use the RSSHub link + // link = meta.attr('href').split('==')[0]; } const article = $('#mp-editor'); @@ -38,11 +39,11 @@ module.exports = async (ctx) => { title: e.title, link: e.link, description: article.html(), - pubDate: date(e.publicTimeStr, 8), + pubDate: parseDate(e.publicTime), author, }; - return Promise.resolve(single); + return single; }) ); diff --git a/lib/v2/sohu/radar.js b/lib/v2/sohu/radar.js new file mode 100644 index 000000000..3ceba885f --- /dev/null +++ b/lib/v2/sohu/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'sohu.com': { + _name: '搜狐', + '.': [ + { + title: '搜狐号', + docs: 'https://docs.rsshub.app/new-media.html#sou-hu-hao', + source: ['/a/:id'], + target: (params) => `/sohu/mp/${params.id.split('_')[1]}`, + }, + ], + }, +}; diff --git a/lib/v2/sohu/router.js b/lib/v2/sohu/router.js new file mode 100644 index 000000000..761175b49 --- /dev/null +++ b/lib/v2/sohu/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/mp/:id', require('./mp')); +};