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')); +};