diff --git a/docs/new-media.md b/docs/new-media.md index 82f88d574..223a58134 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -3723,6 +3723,12 @@ wechat-feeds 来源[已停止更新](https://github.com/hellodword/wechat-feeds/ +## 小专栏 + +### 专栏 + + + ## 辛華社 ### 首页 diff --git a/lib/v2/xiaozhuanlan/column.js b/lib/v2/xiaozhuanlan/column.js new file mode 100644 index 000000000..e82f63fda --- /dev/null +++ b/lib/v2/xiaozhuanlan/column.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const md = require('markdown-it')({ + linkify: true, +}); +const baseUrl = 'https://xiaozhuanlan.com'; + +module.exports = async (ctx) => { + const { id } = ctx.params; + const response = await got(`${baseUrl}/${id}`); + + const $ = cheerio.load(response.data); + + let items = $('.xzl-topic-item') + .toArray() + .map((item) => { + item = $(item); + item.find('.topic-has-suggested-item').remove(); + return { + title: item.find('h3').text().trim(), + link: new URL(item.find('.topic-body-link').attr('href'), baseUrl).href, + author: item.find('.topic-header .xzl-author-lockup').text().trim(), + pubDate: parseDate(item.find('.topic-header .timeago').attr('title')), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const $ = cheerio.load(detailResponse.data); + + item.description = md.render($('.hidden_markdown_body').attr('data-summary')); + if ($('.topic-tags')) { + item.category = $('.topic-tags label') + .toArray() + .map((l) => $(l).text()); + } + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text().trim(), + link: `${baseUrl}/${id}`, + description: $('meta[name=description]').attr('content'), + item: items, + }; +}; diff --git a/lib/v2/xiaozhuanlan/maintainer.js b/lib/v2/xiaozhuanlan/maintainer.js new file mode 100644 index 000000000..52a034e3d --- /dev/null +++ b/lib/v2/xiaozhuanlan/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/column/:id': ['TonyRL'], +}; diff --git a/lib/v2/xiaozhuanlan/radar.js b/lib/v2/xiaozhuanlan/radar.js new file mode 100644 index 000000000..cf78b6a2b --- /dev/null +++ b/lib/v2/xiaozhuanlan/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'xiaozhuanlan.com': { + _name: '小专栏', + '.': [ + { + title: '专栏', + docs: 'https://docs.rsshub.app/new-media.html#xiao-zhuan-lan', + source: '/:id', + target: '/xiaozhuanlan/column/:id', + }, + ], + }, +}; diff --git a/lib/v2/xiaozhuanlan/router.js b/lib/v2/xiaozhuanlan/router.js new file mode 100644 index 000000000..9976f6876 --- /dev/null +++ b/lib/v2/xiaozhuanlan/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/column/:id', require('./column')); +};