feat: add archdaily fulltext (#2538)

* feat: add archdaily fulltext

* feat: add archdaily fulltext

* feat: add archdaily fulltext
This commit is contained in:
Cloud 2019-07-03 12:02:17 +08:00 committed by DIYgod
parent 059674ead2
commit e828709100
3 changed files with 62 additions and 0 deletions

View File

@ -39,6 +39,12 @@ pageClass: routes
见 [#app-store-mac-app-store](/program-update.html#app-store-mac-app-store)
## archdaily
### 首页
<Route author="kt286" example="/archdaily" path="/archdaily"/>
## AutoTrader
### 搜索结果

View File

@ -1464,4 +1464,7 @@ router.get('/tprtc/cqzr', require('./routes/tprtc/cqzr'));
router.get('/tprtc/qyzc', require('./routes/tprtc/qyzc'));
router.get('/tprtc/news', require('./routes/tprtc/news'));
// ArchDaily
router.get('/archdaily', require('./routes/archdaily/home'));
module.exports = router;

View File

@ -0,0 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const parser = require('@/utils/rss-parser');
module.exports = async (ctx) => {
const feed = await parser.parseURL('https://feeds.feedburner.com/ArchdailyCN');
const ProcessFeed = async (link) => {
const response = await got({
method: 'get',
url: link,
});
const $ = cheerio.load(response.data);
// 还原图片地址
$('img').each((index, elem) => {
const $elem = $(elem);
$elem.attr('referrerpolicy', 'no-referrer');
});
// 提取内容
return $('#single-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,
};
};