diff --git a/docs/new-media.md b/docs/new-media.md index 2d727ea9e..9ed7ddaff 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -185,6 +185,22 @@ pageClass: routes +## Bad.news + +### 通用 + + + +::: tip 提示 + +若订阅 [每日热点 - 最新](https://bad.news/tag/每日热点/sort-new),网址为 。截取 `https://bad.news` 到末尾的部分 `/tag/每日热点/sort-new` 作为参数,此时路由为 [`/bad/tag/每日热点/sort-new`](https://rsshub.app/bad/tag/每日热点/sort-new)。 + +若订阅子分类 [大陆资讯 - 热门](https://bad.news/tag/大陆资讯/sort-hot),网址为 。截取 `https://bad.news` 到末尾的部分 `/tag/大陆资讯/sort-hot` 作为参数,路由为 [`/bad/tag/大陆资讯/sort-hot`](https://rsshub.app/bad/tag/大陆资讯/sort-hot)。 + +::: + + + ## Bell Labs ### Event and News diff --git a/lib/v2/bad/index.js b/lib/v2/bad/index.js new file mode 100644 index 000000000..80668781e --- /dev/null +++ b/lib/v2/bad/index.js @@ -0,0 +1,58 @@ +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 rootUrl = 'https://bad.news'; + const currentUrl = `${rootUrl}${ctx.path === '/' ? '' : ctx.path}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + $('.option, .pagination').remove(); + + const items = $('.entry') + .toArray() + .map((item) => { + item = $(item); + + const a = item.find('a.title'); + + item.find('img').each(function () { + $(this).attr('src', $(this).attr('data-echo')); + $(this).removeClass('lazy'); + $(this).removeAttr('data-echo'); + $(this).removeAttr('id'); + }); + + item.find('video').each(function () { + $(this).attr('poster', $(this).attr('data-echo')); + $(this).removeAttr('data-echo'); + $(this).removeAttr('onerror'); + $(this).removeAttr('id'); + }); + + return { + title: a.text(), + link: a.attr('href'), + description: item.find('.coverdiv').html(), + author: item.find('.author').text().trim(), + pubDate: timezone(parseDate(item.find('time').attr('datetime')), +8), + category: item + .find('.label') + .toArray() + .map((l) => $(l).text().trim()), + }; + }); + + ctx.state.data = { + title: `Bad.news - ${$('.active').text()}${$('.selected').text()}`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/bad/maintainer.js b/lib/v2/bad/maintainer.js new file mode 100644 index 000000000..57f872453 --- /dev/null +++ b/lib/v2/bad/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:path+': ['nczitzk'], +}; diff --git a/lib/v2/bad/radar.js b/lib/v2/bad/radar.js new file mode 100644 index 000000000..fe2d1337b --- /dev/null +++ b/lib/v2/bad/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'bad.news': { + _name: 'Bad.news', + '.': [ + { + title: '通用', + docs: 'https://docs.rsshub.app/new-media.html#bad-news-tong-yong', + source: ['/'], + target: (params, url) => `/bad${new URL(url).href.match(/bad\.news(.*?)/)[1]}`, + }, + ], + }, +}; diff --git a/lib/v2/bad/router.js b/lib/v2/bad/router.js new file mode 100644 index 000000000..406315685 --- /dev/null +++ b/lib/v2/bad/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get(/([\w-/]+)?/, require('./index')); +};