From 3441822d7483f85ab5075a15ad26ef6ecbd5e101 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 26 Sep 2021 10:13:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=208=E8=A7=86=E7=95=8C=20(#82?= =?UTF-8?q?62)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 12 ++++++++ lib/v2/8world/index.js | 57 +++++++++++++++++++++++++++++++++++++ lib/v2/8world/maintainer.js | 3 ++ lib/v2/8world/radar.js | 13 +++++++++ lib/v2/8world/router.js | 3 ++ 5 files changed, 88 insertions(+) create mode 100644 lib/v2/8world/index.js create mode 100644 lib/v2/8world/maintainer.js create mode 100644 lib/v2/8world/radar.js create mode 100644 lib/v2/8world/router.js diff --git a/docs/new-media.md b/docs/new-media.md index 8bf18c45f1..b860fcad53 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -44,6 +44,18 @@ pageClass: routes +## 8 视界 + +### 分类 + + + +| 即时 | 新加坡 | 东南亚 | 中港台 | 国际 | 财经 | 体育 | +| -------- | --------- | -------------- | ------------- | ----- | ------- | ------ | +| realtime | singapore | southeast-asia | greater-china | world | finance | sports | + + + ### 主题文章 diff --git a/lib/v2/8world/index.js b/lib/v2/8world/index.js new file mode 100644 index 0000000000..3a5ce452f8 --- /dev/null +++ b/lib/v2/8world/index.js @@ -0,0 +1,57 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'realtime'; + + const rootUrl = 'https://www.8world.com'; + const currentUrl = `${rootUrl}/${category}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('div[data-column="Two-Third"] .article-title .article-link') + .map((_, item) => { + item = $(item); + + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.description = content('.text-long').html(); + item.title = content('meta[name="cXenseParse:mdc-title"]').attr('content'); + item.author = content('meta[name="cXenseParse:author"]').attr('content'); + item.pubDate = parseDate(content('meta[name="cXenseParse:recs:publishtime"]').attr('content')); + item.category = content('meta[name="cXenseParse:mdc-keywords"]') + .toArray() + .map((keyword) => content(keyword).attr('content')); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/8world/maintainer.js b/lib/v2/8world/maintainer.js new file mode 100644 index 0000000000..81eb78d732 --- /dev/null +++ b/lib/v2/8world/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category?': ['nczitzk'], +}; diff --git a/lib/v2/8world/radar.js b/lib/v2/8world/radar.js new file mode 100644 index 0000000000..90e50ea8b0 --- /dev/null +++ b/lib/v2/8world/radar.js @@ -0,0 +1,13 @@ +module.exports = { + '8world.com': { + _name: '8视界', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/new-media.html#_8-shi-jie-fen-lei', + source: ['/:category', '/'], + target: '/8world/:category?', + }, + ], + }, +}; diff --git a/lib/v2/8world/router.js b/lib/v2/8world/router.js new file mode 100644 index 0000000000..cf781366fd --- /dev/null +++ b/lib/v2/8world/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category?', require('./index')); +};