feat: add 科技島讀 (#6078)
This commit is contained in:
parent
74f0dc0d99
commit
c91ec137ea
|
|
@ -981,6 +981,18 @@ column 为 third 时可选的 category:
|
|||
|
||||
<Route author="nczitzk" example="/kuaibao" path="/kuaibao/index"/>
|
||||
|
||||
## 科技島讀
|
||||
|
||||
### 分類
|
||||
|
||||
<Route author="nczitzk" example="/daodu" path="/daodu/:caty?" :paramsDesc="['分類,默認為全部']">
|
||||
|
||||
| 全部 | 文章 | Podcast |
|
||||
| ---- | ------- | ------- |
|
||||
| all | article | podcast |
|
||||
|
||||
</Route>
|
||||
|
||||
## 快科技(原驱动之家)
|
||||
|
||||
### 最新新闻
|
||||
|
|
|
|||
|
|
@ -3453,6 +3453,9 @@ router.get('/wsj/:lang/:category', require('./routes/wsj/index'));
|
|||
// China File
|
||||
router.get('/chinafile/:category?', require('./routes/chinafile/index'));
|
||||
|
||||
// 科技島讀
|
||||
router.get('/daodu/:caty?', require('./routes/daodu/index'));
|
||||
|
||||
// CNTV
|
||||
router.get('/cntv/:column', require('./routes/cntv/cntv'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const caty = ctx.params.caty || 'all';
|
||||
|
||||
const rootUrl = 'https://daodu.tech';
|
||||
const currentUrl = `${rootUrl}${caty === 'all' ? '' : '/archive_' + caty}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('h2[itemprop="headline"] a, .post-header .archive__article__title a')
|
||||
.slice(0, 15)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
link: item.attr('href'),
|
||||
};
|
||||
})
|
||||
.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('.member-only').remove();
|
||||
|
||||
item.description = content('.post-entry-text').html();
|
||||
item.pubDate = new Date(content('meta[property="article:published_time"]').attr('content')).toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text().replace('一覽表', ''),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue