commit
d4f0ca8589
|
|
@ -185,6 +185,18 @@ pageClass: routes
|
|||
|
||||
<Route author="Yoge-Code" example="/gov/cnca/zxtz" path="/gov/cnca/zxtz"/>
|
||||
|
||||
## 中国农工民主党
|
||||
|
||||
### 新闻中心
|
||||
|
||||
<Route author="nczitzk" example="/ngd" path="/ngd/:slug?" :paramsDesc="['见下文']">
|
||||
|
||||
将目标栏目的网址拆解为 `http://www.ngd.org.cn/` 和后面的字段,去掉 `.htm` 后,把后面的字段中的 `/` 替换为 `-`,即为该路由的 slug
|
||||
|
||||
如:(要闻动态)[http://www.ngd.org.cn/xwzx/ywdt/index.htm] 的网址在 `http://www.ngd.org.cn/` 后的字段是 `xwzx/ywdt/index.htm`,则对应的 slug 为 `xwzx-ywdt-index`,对应的路由即为 `/ngd/xwzx-ywdt-index`
|
||||
|
||||
</Route>
|
||||
|
||||
## 中国人大网
|
||||
|
||||
<Route author="233yeee" example="/npc/c183" path="/npc/:caty" :paramsDesc="['分类名,支持形如`http://www.npc.gov.cn/npc/*/list.shtml`的网站,传入 npc 之后的参数']">
|
||||
|
|
|
|||
|
|
@ -3785,6 +3785,9 @@ router.get('/nace/blog/:sort?', require('./routes/nace/blog'));
|
|||
// Caixin Latest
|
||||
router.get('/caixin/latest', require('./routes/caixin/latest'));
|
||||
|
||||
// 中国农工民主党
|
||||
router.get('/ngd/:slug?', require('./routes/gov/ngd/index'));
|
||||
|
||||
// SimpRead-消息通知
|
||||
router.get('/simpread/notice', require('./routes/simpread/notice'));
|
||||
// SimpRead-更新日志
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const slug = ctx.params.slug || 'xwzx-ywdt-index';
|
||||
|
||||
const rootUrl = 'http://www.ngd.org.cn';
|
||||
const currentUrl = `${rootUrl}/${slug.replace(/-/g, '/')}.htm`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('.gp-ellipsis a')
|
||||
.slice(0, 15)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
link: `${currentUrl.replace('/index.htm', '')}/${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);
|
||||
const info = content('.articleAuthor').text().split('|');
|
||||
|
||||
item.author = info[0].replace('来源:', '');
|
||||
item.description = content('.gp-article').html();
|
||||
item.pubDate = new Date(info[info.length - 1].replace('发布时间:', '')).toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue