feat: add 北屋 northhouse (#6494)

This commit is contained in:
Ethan Shen
2020-12-23 17:50:35 +00:00
committed by GitHub
parent 98fe3707dc
commit cfef5182ed
3 changed files with 68 additions and 0 deletions
+10
View File
@@ -666,6 +666,16 @@ Supported sub-sites:
<Route author="emdoe" example="/twreporter/category/reviews" path="/twreporter/category/:tid" :paramsDesc="['分类(议题)名称,于主页获取']"/>
## 北屋
<Route author="nczitzk" example="/northhouse" path="/northhouse/:category?" :paramsDesc="['分类,见下表,默认为首页']">
| 首页 | 最新资讯和灾难信息 | 生存主义 survival | 运动户外 | 玩物尚志 | 分享下载 | 知行生活 | 商务服务 |
| ---- | ------------------ | ----------------- | -------- | -------- | -------- | -------- | -------- |
| | 最新资讯和灾难信息 | 生存主义 survival | 运动户外 | 玩物尚志 | 分享下载 | 知行生活 | 商务服务 |
</Route>
## 本地宝
### 焦点资讯
+3
View File
@@ -3733,4 +3733,7 @@ router.get('/dayone/blog', require('./routes/dayone/blog'));
// 滴答清单
router.get('/dida365/habit/checkins', require('./routes/dida365/habit-checkins'));
// 北屋
router.get('/northhouse/:category?', require('./routes/northhouse/index'));
module.exports = router;
+55
View File
@@ -0,0 +1,55 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const category = ctx.params.category || '';
const rootUrl = 'http://www.northhouse.cc';
const currentUrl = `${rootUrl}${category === '' ? '' : `/category/${category}`}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data.replace(/<div class="clear"><\/div>/g, '<div class="clear"></div><time>').replace(/<div class="contents">/g, '</time><div class="contents">'));
const list = $('.entry h2 a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const date = item.parent().parent().find('time').text().trim().replace(/月/, '').split(' ');
return {
title: item.text(),
link: item.attr('href'),
pubDate: new Date(`${date[0]} ${date[2]} GMT+8`).toUTCString(),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
content('.crp_related').remove();
item.description = content('.contents').html();
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};