feat: add daxiaamu fulltext (#2643)

This commit is contained in:
Cloud
2019-07-18 18:12:16 +08:00
committed by DIYgod
parent 387e27167b
commit fc3a2a760d
3 changed files with 56 additions and 0 deletions

View File

@@ -367,6 +367,12 @@ type 为 all 时category 参数不支持 cost 和 free
<Route author="LogicJake" example="/cyzone/label/创业邦周报" path="/cyzone/label/:name" :paramsDesc="['标签名称']"/>
## 大侠阿木
### 首页
<Route author="kt286" example="/daxiaamu/home" path="/daxiaamu/home"/>
## 大众点评
### 用户

View File

@@ -1512,6 +1512,9 @@ router.get('/ccdi/scdc', require('./routes/ccdi/scdc'));
router.get('/nosetime/:id/:type/:sort?', require('./routes/nosetime/comment'));
router.get('/nosetime/home', require('./routes/nosetime/home'));
// 大侠阿木
router.get('/daxiaamu/home', require('./routes/daxiaamu/home'));
// 美团技术团队
router.get('/meituan/tech/home', require('./routes//meituan/tech/home'));

View File

@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const parser = require('@/utils/rss-parser');
const { addNoReferrer } = require('@/utils/common-utils');
module.exports = async (ctx) => {
const feed = await parser.parseURL('http://www.daxiaamu.com/rss');
const ProcessFeed = async (link) => {
const response = await got({
method: 'get',
url: link,
});
const $ = cheerio.load(response.data);
addNoReferrer($, '.main-content');
return $('.main-content').html();
};
const items = await Promise.all(
feed.items.map(async (item) => {
const cache = await ctx.cache.get(item.link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const description = await ProcessFeed(item.link);
const single = {
title: item.title,
description,
pubDate: item.pubDate,
link: item.link,
author: item.author,
};
ctx.cache.set(item.link, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: feed.title,
link: feed.link,
description: feed.description,
item: items,
};
};