diff --git a/docs/government.md b/docs/government.md index 787ea638b7..9d0da35982 100644 --- a/docs/government.md +++ b/docs/government.md @@ -20,6 +20,18 @@ pageClass: routes +### 滚动新闻 + + + +### 新闻要闻 + + + +### 国务院信息 + + + ### 江苏省人民政府 diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 1aaebaa691..73c4f4118e 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -120,6 +120,10 @@ Category 列表: +### 首页新闻 + + + ## 东方网 ### 上海新闻 diff --git a/lib/router.js b/lib/router.js index 4ff09e2462..2f8251103e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -328,6 +328,8 @@ router.get('/cctv/:category', require('./routes/cctv/category')); router.get('/caixin/blog/:column', require('./routes/caixin/blog')); // 财新 router.get('/caixin/:column/:category', require('./routes/caixin/category')); +//财新首页 +router.get('/caixin/article', require('./routes/caixin/article')); // 草榴社区 router.get('/t66y/post/:tid', require('./routes/t66y/post')); @@ -1006,6 +1008,9 @@ router.get('/gov/zhengce/zuixin', require('./routes/gov/zhengce/zuixin')); router.get('/gov/zhengce/wenjian/:pcodeJiguan?', require('./routes/gov/zhengce/wenjian')); router.get('/gov/province/:name/:category', require('./routes/gov/province')); router.get('/gov/city/:name/:category', require('./routes/gov/city')); +router.get('/gov/xinwen/gundong', require('./routes/gov/xinwen/gundong')); +router.get('/gov/xinwen/yaowen', require('./routes/gov/xinwen/yaowen')); +router.get('/gov/statecouncil/news', require('./routes/gov/statecouncil/news')); // 中华人民共和国生态环境部 router.get('/gov/mee/gs', require('./routes/gov/mee/gs')); diff --git a/lib/routes/caixin/article.js b/lib/routes/caixin/article.js new file mode 100644 index 0000000000..5d8b2747bb --- /dev/null +++ b/lib/routes/caixin/article.js @@ -0,0 +1,27 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: 'http://mapiv5.caixin.com//m/api/getWapIndexListByPage?page=1&callback=jQuery213030389065931348935_1560140003113&_=1560140003179', + headers: { + Referer: `http://mapiv5.caixin.com/`, + Host: 'mapiv5.caixin.com', + }, + }); + + const reg = /(.*jQuery.*\()([\s\S]*)(\))/; + const datatmp = response.data.replace(reg, '$2'); + const data = JSON.parse(datatmp).data.list; + + ctx.state.data = { + title: `财新网 - 首页`, + link: `http://www.caixin.com/`, + description: '财新网 - 首页', + item: data.map((item) => ({ + title: item.title, + description: item.summary, + link: item.web_url, + })), + }; +}; diff --git a/lib/routes/gov/statecouncil/news.js b/lib/routes/gov/statecouncil/news.js new file mode 100644 index 0000000000..3a68c37d59 --- /dev/null +++ b/lib/routes/gov/statecouncil/news.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const link = `http://www.gov.cn/pushinfo/v150203/`; + const listData = await got.get(link); + const $list = cheerio.load(listData.data); + + ctx.state.data = { + title: '中国政府网 - 国务院信息', + link, + item: await Promise.all( + $list('.news_box .list li:not(.line)') + .slice(1, 12) + .map(async (_, el) => { + const $el = $list(el); + const $a = $el.find('h4 a'); + const href = $a.attr('href'); + const key = `gov_statecouncil: ${href}`; + let description; + let dataEncode; + let dataDecode; + let urlSplit; + const value = await ctx.cache.get(key); + + if (value) { + description = value; + } else { + const contentUrl = href.startsWith('/') ? `http://www.gov.cn${href}` : href; + const contentData = await got.get(contentUrl); + const $content = cheerio.load(contentData.data); + const regImg = /(img src=")(.*)(".*)/g; + const regUrl = /(http.*\/)(content.*)/; + if (contentData.data.indexOf('UCAP-CONTENT') !== -1) { + dataEncode = $content('#UCAP-CONTENT').html(); + } else { + dataEncode = $content('body').html(); + } + dataDecode = unescape(dataEncode.replace(/&#x/g, '%u').replace(/;/g, '')); + urlSplit = contentUrl.replace(regUrl, '$1'); + description = dataDecode.replace(regImg, '$1' + urlSplit + '$2' + '$3'); + ctx.cache.set(key, description); + } + + return { + title: $a.text(), + description, + link: $a.attr('href'), + pubDate: new Date($el.find('.date').text()).toUTCString(), + }; + }) + .get() + ), + }; +}; diff --git a/lib/routes/gov/xinwen/gundong.js b/lib/routes/gov/xinwen/gundong.js new file mode 100644 index 0000000000..73818415b0 --- /dev/null +++ b/lib/routes/gov/xinwen/gundong.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const link = `http://www.gov.cn/xinwen/gundong.htm`; + const listData = await got.get(link); + const $list = cheerio.load(listData.data); + + ctx.state.data = { + title: '中国政府网 - 滚动新闻', + link, + item: await Promise.all( + $list('.news_box .list li:not(.line)') + .slice(1, 12) + .map(async (_, el) => { + const $el = $list(el); + const $a = $el.find('h4 a'); + const href = $a.attr('href'); + const key = `gov_gundong: ${href}`; + let description; + let dataEncode; + let dataDecode; + let urlSplit; + const value = await ctx.cache.get(key); + + if (value) { + description = value; + } else { + const contentUrl = href.startsWith('/') ? `http://www.gov.cn${href}` : href; + const contentData = await got.get(contentUrl); + const $content = cheerio.load(contentData.data); + const regImg = /(img src=")(.*)(".*)/g; + const regUrl = /(http.*\/)(content.*)/; + if (contentData.data.indexOf('UCAP-CONTENT') !== -1) { + dataEncode = $content('#UCAP-CONTENT').html(); + } else { + dataEncode = $content('body').html(); + } + dataDecode = unescape(dataEncode.replace(/&#x/g, '%u').replace(/;/g, '')); + urlSplit = contentUrl.replace(regUrl, '$1'); + description = dataDecode.replace(regImg, '$1' + urlSplit + '$2' + '$3'); + ctx.cache.set(key, description); + } + + return { + title: $a.text(), + description, + link: $a.attr('href'), + pubDate: new Date($el.find('.date').text()).toUTCString(), + }; + }) + .get() + ), + }; +}; diff --git a/lib/routes/gov/xinwen/yaowen.js b/lib/routes/gov/xinwen/yaowen.js new file mode 100644 index 0000000000..d920f21ac4 --- /dev/null +++ b/lib/routes/gov/xinwen/yaowen.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const link = `http://www.gov.cn/xinwen/yaowen.htm`; + const listData = await got.get(link); + const $list = cheerio.load(listData.data); + + ctx.state.data = { + title: '中国政府网 - 要闻', + link, + item: await Promise.all( + $list('.news_box .list li:not(.line)') + .slice(1, 12) + .map(async (_, el) => { + const $el = $list(el); + const $a = $el.find('h4 a'); + const href = $a.attr('href'); + const key = `gov_yaowen: ${href}`; + let description; + let dataEncode; + let dataDecode; + let urlSplit; + const value = await ctx.cache.get(key); + + if (value) { + description = value; + } else { + const contentUrl = href.startsWith('/') ? `http://www.gov.cn${href}` : href; + const contentData = await got.get(contentUrl); + const $content = cheerio.load(contentData.data); + const regImg = /(img src=")(.*)(".*)/g; + const regUrl = /(http.*\/)(content.*)/; + if (contentData.data.indexOf('UCAP-CONTENT') !== -1) { + dataEncode = $content('#UCAP-CONTENT').html(); + } else { + dataEncode = $content('body').html(); + } + dataDecode = unescape(dataEncode.replace(/&#x/g, '%u').replace(/;/g, '')); + urlSplit = contentUrl.replace(regUrl, '$1'); + description = dataDecode.replace(regImg, '$1' + urlSplit + '$2' + '$3'); + ctx.cache.set(key, description); + } + + return { + title: $a.text(), + description, + link: $a.attr('href'), + pubDate: new Date($el.find('.date').text()).toUTCString(), + }; + }) + .get() + ), + }; +};