feat: 更新部分页面排版、增加新上线的政策文件库 (#3684)
* 更新部分页面排版、增加新上线的政策文件库 * 修复bug * 格式调整
This commit is contained in:
parent
543a6cd1c0
commit
fc81e047ff
|
|
@ -69,9 +69,9 @@ pageClass: routes
|
|||
|
||||
<Route author="EsuRt" example="/gov/news/:uid" path="/gov/news" :paramsDesc="['分类名']">
|
||||
|
||||
| 政务部门 | 滚动新闻 | 新闻要闻 | 国务院新闻 |
|
||||
| :------: | :------: | :------: | :--------: |
|
||||
| bm | gd | yw | gwy |
|
||||
| 政务部门 | 滚动新闻 | 新闻要闻 | 国务院新闻 | 政策文件 |
|
||||
| :------: | :------: | :------: | :--------: | :------: |
|
||||
| bm | gd | yw | gwy | zhengce |
|
||||
|
||||
</Route>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ module.exports = async (ctx) => {
|
|||
const uid = ctx.params.uid;
|
||||
let url = '';
|
||||
let title = '';
|
||||
let list = '';
|
||||
switch (uid) {
|
||||
case 'bm':
|
||||
url = `http://www.gov.cn/xinwen/lianbo/bumen.htm`;
|
||||
|
|
@ -23,46 +24,75 @@ module.exports = async (ctx) => {
|
|||
url = 'http://www.gov.cn/pushinfo/v150203/';
|
||||
title = '中国政府网 - 国务院信息';
|
||||
break;
|
||||
case 'zhengce':
|
||||
url = 'http://sousuo.gov.cn/s.htm?t=zhengcelibrary';
|
||||
title = '中国政府网 - 政策文件';
|
||||
break;
|
||||
default:
|
||||
logger.error('pattern not matched');
|
||||
}
|
||||
const listData = await got.get(url);
|
||||
const $ = cheerio.load(listData.data);
|
||||
const list = $('.news_box .list li:not(.line)');
|
||||
if (url.search(/zhengcelibrary/g) !== -1) {
|
||||
list = $('.dys_middle_result_content_item');
|
||||
} else {
|
||||
list = $('.news_box .list li:not(.line)');
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: title,
|
||||
link: url,
|
||||
item: await Promise.all(
|
||||
list &&
|
||||
list
|
||||
.slice(1, 12)
|
||||
.map(async (index, item) => {
|
||||
item = $(item);
|
||||
let fullText = '';
|
||||
const href = item.find('a').attr('href');
|
||||
const contenlUrl = href.startsWith('/') ? `http://www.gov.cn${href}` : href;
|
||||
const description = await ctx.cache.tryGet(contenlUrl, async () => {
|
||||
const fullTextGet = await got.get(contenlUrl);
|
||||
const fullTextData = cheerio.load(fullTextGet.data);
|
||||
const $1 = fullTextData.html();
|
||||
if ($1.search(/UCAP-CONTENT/g) === -1) {
|
||||
fullText = fullTextData('body').html();
|
||||
list
|
||||
.slice(1, 12)
|
||||
.map(async (index, item) => {
|
||||
item = $(item);
|
||||
let fullText = '';
|
||||
let href = '';
|
||||
let contenlUrl = '';
|
||||
let description = '';
|
||||
let fullTextData = '';
|
||||
let fullTextGet = '';
|
||||
if (item.html().search(/dysMiddleResultConItemTitle/g) !== -1) {
|
||||
contenlUrl = item.find('a').attr('href');
|
||||
description = await ctx.cache.tryGet(contenlUrl, async () => {
|
||||
fullTextGet = await got.get(contenlUrl);
|
||||
fullTextData = cheerio.load(fullTextGet.data);
|
||||
if (fullTextData.html().search(/pages_content/g) !== -1) {
|
||||
return fullTextData('.pages_content').html();
|
||||
} else {
|
||||
fullText = fullTextData('#UCAP-CONTENT').html();
|
||||
return fullTextData('#UCAP-CONTENT').html();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
href = item.find('a').attr('href');
|
||||
contenlUrl = href.startsWith('/') ? `http://www.gov.cn${href}` : href;
|
||||
description = await ctx.cache.tryGet(contenlUrl, async () => {
|
||||
fullTextGet = await got.get(contenlUrl);
|
||||
fullTextData = cheerio.load(fullTextGet.data);
|
||||
const $1 = fullTextData.html();
|
||||
if (contenlUrl.search(/zhengceku/g) !== -1) {
|
||||
fullText = fullTextData('.pages_content').html();
|
||||
} else {
|
||||
if ($1.search(/UCAP-CONTENT/g) === -1) {
|
||||
fullText = fullTextData('body').html();
|
||||
} else {
|
||||
fullText = fullTextData('#UCAP-CONTENT').html();
|
||||
}
|
||||
}
|
||||
const regImg = /(img src=")(.*)(".*)/g;
|
||||
const regUrl = /(http.*\/)(content.*)/;
|
||||
const urlSplit = contenlUrl.replace(regUrl, '$1');
|
||||
return fullText.replace(regImg, '$1' + urlSplit + '$2' + '$3');
|
||||
});
|
||||
return {
|
||||
title: item.find('a').text(),
|
||||
description: description,
|
||||
link: contenlUrl,
|
||||
};
|
||||
})
|
||||
.get()
|
||||
}
|
||||
return {
|
||||
title: item.find('a').text(),
|
||||
description: description,
|
||||
link: contenlUrl,
|
||||
};
|
||||
})
|
||||
.get()
|
||||
),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue