feat: add 广告门文章与话题分类 (#4690)

This commit is contained in:
Ethan Shen 2020-05-08 11:29:13 +08:00 committed by GitHub
parent 3e846e6919
commit b0fca02e4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 0 deletions

View File

@ -501,6 +501,18 @@ Supported sub-sites:
<Route author="Jeason0228" example="/guanchazhe/personalpage/243983" path="/guanchazhe/personalpage/:uid" :paramsDesc="['用户id 可在URL中找到']" />
## 广告门
### 板块
<Route author="nczitzk" example="/adquan/info" path="/adquan/:type?" :paramsDesc="['分类, 置空为首页']">
| 行业观察 | 案例库 |
| -------- | -------- |
| info | creative |
</Route>
## 果壳网
### 科学人

View File

@ -2644,6 +2644,9 @@ router.get('/slu/csggxy/:id', require('./routes/universities/slu/csggxy'));
router.get('/ruby-china/topics/:type?', require('./routes/ruby-china/topics'));
router.get('/ruby-china/jobs', require('./routes/ruby-china/jobs'));
// 广告网
router.get('/adquan/:type?', require('./routes/adquan/index'));
// 齐鲁晚报
router.get('/qlwb/news', require('./routes/qlwb/news'));
router.get('/qlwb/city/:city', require('./routes/qlwb/city'));

View File

@ -0,0 +1,73 @@
const url = require('url');
const got = require('@/utils/got');
const cheerio = require('cheerio');
const config = {
index: {
link: 'https://www.adquan.com/',
title: '首页',
},
info: {
link: 'https://www.adquan.com/info',
title: '行业观察',
},
creative: {
link: 'https://creative.adquan.com/',
title: '案例库',
},
};
module.exports = async (ctx) => {
let cfg;
if (ctx.params.type) {
cfg = config[ctx.params.type];
} else {
cfg = config.index;
}
const response = await got({
method: 'get',
url: cfg.link,
});
const $ = cheerio.load(response.data);
let where;
switch (cfg.title) {
case '首页':
where = $('div.w_l_inner h2.wrok_l_title a');
break;
case '行业观察':
where = $('div.article_rel div.rel_write a p').parent();
break;
case '案例库':
where = $('#showcontent li h2 a');
break;
}
const list = where
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: url.resolve(cfg.link, item.attr('href')),
};
})
.get();
ctx.state.data = {
title: `广告网 - ${cfg.title}`,
link: cfg.link,
item: 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);
item.pubDate = new Date(content('p.text_time2 span').eq(0).text()).toUTCString();
item.description = content('div.con_Text').html();
return item;
})
)
),
};
};