From febd6233b0f14293f82c33f5a520293dea9541be Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Sun, 5 Jun 2022 21:21:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E7=94=B5=E5=8A=A8?= =?UTF-8?q?=E9=82=A6=20(#9897)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 电动邦 * docs: fix h2 heading --- docs/new-media.md | 26 ++++++++++++++++++ lib/v2/diandong/ddh.js | 51 +++++++++++++++++++++++++++++++++++ lib/v2/diandong/maintainer.js | 4 +++ lib/v2/diandong/news.js | 50 ++++++++++++++++++++++++++++++++++ lib/v2/diandong/radar.js | 19 +++++++++++++ lib/v2/diandong/router.js | 4 +++ 6 files changed, 154 insertions(+) create mode 100644 lib/v2/diandong/ddh.js create mode 100644 lib/v2/diandong/maintainer.js create mode 100644 lib/v2/diandong/news.js create mode 100644 lib/v2/diandong/radar.js create mode 100644 lib/v2/diandong/router.js diff --git a/docs/new-media.md b/docs/new-media.md index 10608955f..f18f96998 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1616,6 +1616,32 @@ Supported sub-sites: +## 电动邦 + +### 资讯 + + + +分类 + +| 推荐 | 新车 | 导购 | 试驾 | 用车 | 技术 | 政策 | 行业 | +| -- | -- | -- | -- | -- | -- | -- | -- | +| 0 | 29 | 61 | 30 | 75 | 22 | 24 | 23 | + + + +### 电动号 + + + +分类 + +| 全部 | 新车 | 导购 | 评测 | 新闻 | 技术 | 政策 | 用车 | 二手车 | +| -- | -- | -- | -- | -- | -- | -- | -- | --- | +| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | + + + ## 电商报 ### 分区 diff --git a/lib/v2/diandong/ddh.js b/lib/v2/diandong/ddh.js new file mode 100644 index 000000000..7508fa1eb --- /dev/null +++ b/lib/v2/diandong/ddh.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const rootUrl = 'https://webapi.diandong.com'; + +const titleMap = { + 0: '全部', + 1: '新车', + 2: '导购', + 3: '评测', + 4: '新闻', + 5: '技术', + 6: '政策', + 7: '用车', + 8: '二手车', +}; + +module.exports = async (ctx) => { + const cate = ctx.params.cate ?? 0; + const limit = ctx.query.limit ? Number(ctx.query.limit) : 25; + const url = `${rootUrl}/content/ddhList?category_id=${cate}&page=1&size=${limit}&content_ids=`; + + const response = await got(url); + const data = response.data.data.list; + const list = data.map((item) => ({ + title: item.title, + pubDate: parseDate(item.published), + author: item.author, + link: `https://www.diandong.com/news/${item.contentid}.html`, + })); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const $ = cheerio.load(detailResponse.data); + + item.description = $('#gallery-selector').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `电动邦 - 电动号 - ${titleMap[cate]}`, + link: 'https://www.diandong.com/news/ddh', + item: items, + }; +}; diff --git a/lib/v2/diandong/maintainer.js b/lib/v2/diandong/maintainer.js new file mode 100644 index 000000000..7afe201cd --- /dev/null +++ b/lib/v2/diandong/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/news/:cate?': ['Fatpandac'], + '/ddh/:cate?': ['Fatpandac'], +}; diff --git a/lib/v2/diandong/news.js b/lib/v2/diandong/news.js new file mode 100644 index 000000000..5b6f250f1 --- /dev/null +++ b/lib/v2/diandong/news.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const rootUrl = 'https://webapi.diandong.com'; + +const titleMap = { + 0: '推荐', + 29: '新车', + 61: '导购', + 30: '试驾', + 75: '用车', + 22: '技术', + 24: '政策', + 23: '行业', +}; + +module.exports = async (ctx) => { + const cate = ctx.params.cate ?? 0; + const limit = ctx.query.limit ? Number(ctx.query.limit) : 25; + const url = `${rootUrl}/content/list?page=1&size=${limit}&source_id=12&content_type=news&content_ids=&category_id=${cate}`; + + const response = await got(url); + const data = response.data.data.list; + const list = data.map((item) => ({ + title: item.title, + pubDate: parseDate(item.published), + author: item.author, + link: `https://www.diandong.com/news/${item.contentid}.html`, + })); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const $ = cheerio.load(detailResponse.data); + + item.description = $('#gallery-selector').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `电动邦 - ${titleMap[cate]}`, + link: 'https://www.diandong.com/news', + item: items, + }; +}; diff --git a/lib/v2/diandong/radar.js b/lib/v2/diandong/radar.js new file mode 100644 index 000000000..cb37e371c --- /dev/null +++ b/lib/v2/diandong/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'diandong.com': { + _name: '电动邦', + '.': [ + { + title: '资讯', + docs: 'https://docs.rsshub.app/new-media.html#dong-qiu-di', + source: ['/news'], + target: '/diandong/news/:cate', + }, + { + title: '电动号', + docs: 'https://docs.rsshub.app/new-media.html#dong-qiu-di', + source: ['/news/ddh'], + target: '/diandong/ddh/:cate', + }, + ], + }, +}; diff --git a/lib/v2/diandong/router.js b/lib/v2/diandong/router.js new file mode 100644 index 000000000..e0ace36a7 --- /dev/null +++ b/lib/v2/diandong/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/news/:cate?', require('./news')); + router.get('/ddh/:cate?', require('./ddh')); +};