Skip to content

Commit

Permalink
feat: add 中国政府网图解 & 漫画 (DIYgod#5550)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Shen authored and luyuhuang committed Sep 9, 2020
1 parent 10649ed commit 7100310
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/government.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ pageClass: routes

</Route>

### 图解

<Route author="nczitzk" example="/gov/xinwen/tujie/zhengce" path="/gov/xinwen/tujie/:caty" :paramsDesc="['图解分类,见下表']">

| 总理活动图解 | 每周一画 | 其他漫画 | 图解政策 | 其他图解 |
| ------------ | -------- | -------- | -------- | -------- |
| zlhd | mzyh | qtmh | zhengce | qttj |

全部分类参见 [图解图表](http://www.gov.cn/xinwen/tujie/index.htm)

</Route>

### 最新政策

<Route author="SettingDust" example="/gov/zhengce/zuixin" path="/gov/zhengce/zuixin"/>
Expand Down
1 change: 1 addition & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,7 @@ router.get('/gov/city/:name/:category', require('./routes/gov/city'));
router.get('/gov/statecouncil/briefing', require('./routes/gov/statecouncil/briefing'));
router.get('/gov/news/:uid', require('./routes/gov/news'));
router.get('/gov/shuju/:caty/:item', require('./routes/gov/shuju'));
router.get('/gov/xinwen/tujie/:caty', require('./routes/gov/xinwen/tujie'));

// 苏州
router.get('/gov/suzhou/news/:uid', require('./routes/gov/suzhou/news'));
Expand Down
76 changes: 76 additions & 0 deletions lib/routes/gov/xinwen/tujie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');

const config = {
zlhd: {
link: '/tujie/zlhd.htm',
title: '总理活动图解',
},
mzyh: {
link: '/manhua/mzyh.htm',
title: '每周一画',
},
qtmh: {
link: '/manhua/qita.htm',
title: '其他漫画',
},
zhengce: {
link: '/tujie/zhengce.htm',
title: '图解政策',
},
qttj: {
link: '/tujie/qita.htm',
title: '其他图解',
},
};

module.exports = async (ctx) => {
const cfg = config[ctx.params.caty];
if (!cfg) {
throw Error('Bad category. See <a href="https://docs.rsshub.app/government.html#zhong-guo-zheng-fu-tu-jie">docs</a>');
}

const rootUrl = 'http://www.gov.cn/xinwen';
const currentUrl = rootUrl + cfg.link;
const response = await got({
method: 'get',
url: currentUrl,
});

const $ = cheerio.load(response.data);
const list = $('div.Video_pane div.tplgd')
.slice(0, 15)
.map((_, item) => {
item = $(item);
const a = item.find('a').eq(1);
return {
title: a.text(),
link: `http://www.gov.cn${a.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);

item.description = content('div.pages_content').html();
item.pubDate = new Date(content('div.pages-date').text().split('来源:')[0] + ' GMT+8').toUTCString();

return item;
})
)
);

ctx.state.data = {
title: `${cfg.title} - 中国政府网`,
link: currentUrl,
item: items,
};
};

0 comments on commit 7100310

Please sign in to comment.