parent
40dd6b84d5
commit
a38917adee
|
|
@ -330,6 +330,16 @@ category 对应的关键词有
|
|||
|
||||
<Route author="LogicJake" example="/people/xjpjh" path="/people/xjpjh/:keyword?/:year?" :paramsDesc="['关键词,默认不填','年份,默认all']"/>
|
||||
|
||||
## 人民日报社 国际金融报
|
||||
|
||||
### 栏目
|
||||
|
||||
<Route author="Origami404" example="/ifnews/48" path="/ifnews/:cid" :paramsDesc="['栏目ID']">
|
||||
|
||||
`cid`可在对应栏目的 url 后的参数中获取, 如`热点快报`的栏目 url 为`http://www.ifnews.com/column.html?cid=48`, `cid`即为`48`.
|
||||
|
||||
</Route>
|
||||
|
||||
## 日本経済新聞
|
||||
|
||||
### ホームページ
|
||||
|
|
|
|||
|
|
@ -2257,6 +2257,9 @@ router.get('/discuz/:link(.*)', require('./routes/discuz/discuz'));
|
|||
router.get('/chinadialogue/topics/:topic', require('./routes/chinadialogue/topics'));
|
||||
router.get('/chinadialogue/:column', require('./routes/chinadialogue/column'));
|
||||
|
||||
// 人民日报社 国际金融报
|
||||
router.get('/ifnews/:cid', require('./routes/ifnews/column'));
|
||||
|
||||
// Scala Blog
|
||||
router.get('/scala/blog/:part?', require('./routes/scala-blog/scala-blog'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,75 @@
|
|||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
const date = require('@/utils/date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const cid = ctx.params.cid;
|
||||
const url = 'http://www.ifnews.com';
|
||||
const respones = await got({
|
||||
method: 'get',
|
||||
url: `http://api.ifnews.com/api/getArticles?cid=${cid}`,
|
||||
headers: {
|
||||
Referer: `${url}/column.html?cid=${cid}`,
|
||||
},
|
||||
});
|
||||
const data = respones.data;
|
||||
|
||||
const list = data.list.map((item) => ({
|
||||
title: item.title,
|
||||
author: item.createUser,
|
||||
link: `${url}/news.html?aid=${item.fileID}`,
|
||||
pubDate: date(item.publishTime),
|
||||
aid: item.fileID,
|
||||
}));
|
||||
|
||||
const result = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const link = item.link;
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
// 页面数据
|
||||
const contentResponse = await got({
|
||||
method: 'get',
|
||||
url: `http://api.ifnews.com/api/getArticle?aid=${item.aid}`,
|
||||
headers: {
|
||||
Referer: item.link,
|
||||
},
|
||||
});
|
||||
const content = contentResponse.data;
|
||||
|
||||
// 页面框架
|
||||
const pageResponse = await got.get(item.link);
|
||||
const pageElement = cheerio.load(pageResponse.data);
|
||||
const pageHTML = pageElement('.content').html();
|
||||
|
||||
// 填充页面框架使其变成真正的文章
|
||||
// 主要处理一些被{{xxx}}框起来的变量
|
||||
// 确实, 一排replace看起来很吓人, 如果有人有更好的方法实现就好了
|
||||
// 我也试过用MDN上eval()页面教的构造function对象的方法来直接执行{{}}内的js代码, 但是好像效果不佳...
|
||||
item.description = pageHTML
|
||||
.replace(/<div class="shareBox">[\s\S]*<\/ul>/, '') // 去掉后面的评论区跟分享区
|
||||
.replace('{{content.leadTitle}}', content.leadTitle)
|
||||
.replace('{{content.title}}', content.title)
|
||||
.replace('{{content.subTitle}}', content.subTitle)
|
||||
.replace(/\{\{content\.publishTime\?.*?\}\}/, content.publishTime)
|
||||
.replace('{{content.source}}', content.source)
|
||||
.replace('{{content.author}}', content.author)
|
||||
.replace('{{content.abstract}}', content.abstract)
|
||||
.replace('{{content.editor}}', content.editor)
|
||||
.replace('<div class="centerText" v-html="content.content"></div>', content.content);
|
||||
|
||||
ctx.cache.set(link, JSON.stringify(item));
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `人民日报社 国际金融报 ${data.column.columnName}`,
|
||||
link: url,
|
||||
item: result,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue