mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-01 14:57:14 +08:00
feat: 增加 Dilbert Daily Strip 漫画全文抓取 (#2274)
* feat: 增加 Dilbert Daily Strip 漫画全文抓取 * fix: 回滚无关提交 * docs: remove redundant docs
This commit is contained in:
@@ -74,6 +74,14 @@ pageClass: routes
|
||||
|
||||
<Route author="kt286" example="/cnbeta" path="/cnbeta"/>
|
||||
|
||||
## Dilbert Comic Strip
|
||||
|
||||
<Route name="Daily Strip" author="Maecenas" example="/dilbert/strip" path="/dilbert/strip">
|
||||
|
||||
通过提取漫画,提供比官方源更佳的阅读体验。
|
||||
|
||||
</Route>
|
||||
|
||||
## DoNews
|
||||
|
||||
### 栏目
|
||||
|
||||
@@ -1371,4 +1371,7 @@ router.get('/maoyan/upcoming', require('./routes/maoyan/upcoming'));
|
||||
// cnBeta
|
||||
router.get('/cnbeta', require('./routes/cnbeta/home'));
|
||||
|
||||
// Dilbert Comic Strip
|
||||
router.get('/dilbert/strip', require('./routes/dilbert/strip'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
const axios = require('@/utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
const Parser = require('rss-parser');
|
||||
const parser = new Parser();
|
||||
|
||||
async function load(link, id) {
|
||||
const response = await axios.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const context = $('.comic-item-container > .meta-info-container');
|
||||
const img = context.find('img.img-comic');
|
||||
const transcript = context.find('.js-toggle-container > p');
|
||||
|
||||
const title = img.attr('alt').replace('Dilbert by Scott Adams', id);
|
||||
const src = 'https:' + img.attr('src');
|
||||
|
||||
const description = `<img referrerpolicy="no-referrer" src="${src}"></br><p>${transcript.html()}</p>`;
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const title = 'Dilbert Daily Strip';
|
||||
const feed_url = 'http://feed.dilbert.com/dilbert/daily_strip';
|
||||
|
||||
const feed = await parser.parseURL(feed_url);
|
||||
const items = await Promise.all(
|
||||
feed.items.slice(0, 7).map(async (item) => {
|
||||
const link = `https://dilbert.com/strip/${item.id}`;
|
||||
|
||||
const single = {
|
||||
pubDate: item.pubDate,
|
||||
link,
|
||||
};
|
||||
|
||||
const other = await ctx.cache.tryGet(link, async () => await load(link, item.id));
|
||||
|
||||
return Promise.resolve(Object.assign({}, single, other));
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title,
|
||||
link: 'https://dilbert.com',
|
||||
description: title,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user