feat: add 搜狐号 (#2946)

* feat: add 搜狐号

Close #2926

* docs
This commit is contained in:
Henry Wang
2019-08-28 04:14:46 +01:00
committed by DIYgod
parent 8e68040151
commit 3d72eec3c2
3 changed files with 62 additions and 0 deletions

48
lib/routes/sohu/mp.js Normal file
View File

@@ -0,0 +1,48 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const date = require('@/utils/date');
module.exports = async (ctx) => {
const { id } = ctx.params;
const response = await got.get(`https://v2.sohu.com/author-page-api/author-articles/pc/${id}`);
const list = response.data.data.pcArticleVOS.splice(0, 10);
let author, link;
const items = await Promise.all(
list.map(async (e) => {
const response = await ctx.cache.tryGet(e.link, async () => (await got.get(e.link)).data);
const $ = cheerio.load(response);
if (!author) {
const meta = $('#article-container h4 > a');
author = meta.text();
link = meta.attr('href').split('==')[0];
}
const article = $('#mp-editor');
article.find('#backsohucom, p[data-role="editor-name"]').each((i, e) => {
$(e).remove();
});
const single = {
title: e.title,
link: e.link,
description: article.html(),
pubDate: date(e.publicTimeStr, 8),
author,
};
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `搜狐号 - ${author}`,
link,
description: '',
item: items,
};
};