mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-25 10:14:31 +08:00
@@ -25,8 +25,7 @@ module.exports = async (ctx) => {
|
||||
description: each.find('p', '.description').text(),
|
||||
link: originalUrl,
|
||||
};
|
||||
if (/^\/news\/.*$/.test(originalUrl)) {
|
||||
item.link = 'https://www.oschina.net' + originalUrl;
|
||||
if (/^https:\/\/www.oschina.net\/news\/.*$/.test(originalUrl)) {
|
||||
const key = 'oschina' + item.link;
|
||||
const value = await ctx.cache.get(key);
|
||||
|
||||
@@ -41,6 +40,7 @@ module.exports = async (ctx) => {
|
||||
},
|
||||
});
|
||||
const content = cheerio.load(detail.data);
|
||||
content('.ad-wrap').remove();
|
||||
item.description = content('#articleContent').html();
|
||||
ctx.cache.set(key, item.description, 24 * 60 * 60);
|
||||
}
|
||||
|
||||
@@ -8,13 +8,19 @@ module.exports = {
|
||||
ProcessImage: function(content) {
|
||||
const $ = cheerio.load(content, { xmlMode: true });
|
||||
|
||||
$('img.content_image, img.origin_image, img.content-image').each((i, e) => {
|
||||
$('img.content_image, img.origin_image, img.content-image, img.data-actualsrc').each((i, e) => {
|
||||
if (e.attribs['data-original']) {
|
||||
$(e).attr({
|
||||
src: e.attribs['data-original'],
|
||||
width: null,
|
||||
height: null,
|
||||
});
|
||||
} else if (!e.attribs['data-original'] && e.attribs['data-actualsrc']) {
|
||||
$(e).attr({
|
||||
src: e.attribs['data-actualsrc'],
|
||||
width: null,
|
||||
height: null,
|
||||
});
|
||||
} else {
|
||||
$(e).attr({
|
||||
src: e.attribs.src.replace('_b.jpg', '_r.jpg'),
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
const axios = require('../../utils/axios');
|
||||
const utils = require('./utils');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const listRes = await axios({
|
||||
method: 'get',
|
||||
url: `https://zhuanlan.zhihu.com/api/columns/${id}/posts?limit=20`,
|
||||
url: `https://zhuanlan.zhihu.com/api2/columns/${id}/articles`,
|
||||
headers: {
|
||||
...utils.header,
|
||||
Referer: `https://zhuanlan.zhihu.com/${id}`,
|
||||
@@ -29,22 +30,56 @@ module.exports = async (ctx) => {
|
||||
throw 'info resource api returned status code ' + infoRes.status;
|
||||
}
|
||||
|
||||
const list = listRes.data;
|
||||
const list = listRes.data.data;
|
||||
const info = infoRes.data;
|
||||
|
||||
const articles = await Promise.all(
|
||||
list.map(async (article) => {
|
||||
const url = article.url;
|
||||
const item = {
|
||||
title: article.title,
|
||||
description: '',
|
||||
link: article.url,
|
||||
};
|
||||
const key = 'zhuanlan' + article.url;
|
||||
const value = await ctx.cache.get(key);
|
||||
|
||||
if (value) {
|
||||
item.description = value;
|
||||
} else {
|
||||
const articleOriginal = await axios({
|
||||
method: 'get',
|
||||
url: url,
|
||||
headers: {
|
||||
Referer: url,
|
||||
},
|
||||
});
|
||||
item.description = utils.ProcessImage(
|
||||
cheerio
|
||||
.load(articleOriginal.data)('.Post-RichText')
|
||||
.html()
|
||||
);
|
||||
ctx.cache.set(key, item.description, 24 * 60 * 60);
|
||||
}
|
||||
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
|
||||
if (!Array.isArray(list)) {
|
||||
throw JSON.stringify(list);
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: `知乎专栏-${info.name}`,
|
||||
title: `知乎专栏-${info.title}`,
|
||||
link: `https://zhuanlan.zhihu.com/${id}`,
|
||||
description: info.description,
|
||||
item: list.map((item) => ({
|
||||
title: item.title,
|
||||
description: item.content.replace(/ src="/g, ' referrerpolicy="no-referrer" src="https://pic4.zhimg.com/'),
|
||||
pubDate: new Date(item.publishedTime).toUTCString(),
|
||||
link: `https://zhuanlan.zhihu.com${item.url}`,
|
||||
})),
|
||||
item: articles,
|
||||
// list.map((item) => ({
|
||||
// title: item.title,
|
||||
// description: item.content.replace(/ src="/g, ' referrerpolicy="no-referrer" src="https://pic4.zhimg.com/'),
|
||||
// pubDate: new Date(item.publishedTime).toUTCString(),
|
||||
// link: `https://zhuanlan.zhihu.com${item.url}`,
|
||||
// })),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user