feat(add): 深圳新闻网深圳市政府新闻发布厅 (#7733)

This commit is contained in:
Ethan Shen
2021-06-27 08:01:25 +08:00
committed by GitHub
parent 70da5d32ef
commit 150883ca14
4 changed files with 57 additions and 1 deletions

View File

@@ -1806,6 +1806,10 @@ column 为 third 时可选的 category:
## 深圳新闻网
### 深圳市政府新闻发布厅
<Route author="nczitzk" example="/sznews/press" path="/sznews/press"/>
### 排行榜
<Route author="nczitzk" example="/sznews/ranking" path="/sznews/ranking"/>

View File

@@ -3964,6 +3964,7 @@ router.get('/babehub/search/:keyword?', require('./routes/babehub/search'));
router.get('/babehub/:category?', require('./routes/babehub/index'));
// 深圳新闻网
router.get('/sznews/press', require('./routes/sznews/press'));
router.get('/sznews/ranking', require('./routes/sznews/ranking'));
// Shuax

View File

@@ -0,0 +1,51 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const rootUrl = 'http://www.sznews.com';
const currentUrl = `${rootUrl}/zhuanti/node_210611.htm`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.list-pt-li a h3')
.slice(0, 10)
.map((_, item) => {
item = $(item).parent();
return {
title: item.text(),
link: item.attr('href'),
pubDate: timezone(new Date(item.parent().find('.date').text()), +8),
};
})
.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);
item.description = content('#picBox').html() + content('.pos').html();
return item;
})
)
);
ctx.state.data = {
title: '往期回顾 - 深圳市政府新闻发布厅',
link: currentUrl,
item: items,
};
};

View File

@@ -42,7 +42,7 @@ module.exports = async (ctx) => {
item.description = content('.article-content').html();
item.author = content('.a_source').text().replace('来源: ', '');
item.pubDate = new Date(content('.a_time').text() + ' GMT+8').toUTCString();
item.pubDate = Date.parse(content('.a_time').text());
return item;
})