mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
Matters 最新文章的全文輸出 (#1945)
* converts matters-latest into full text * code cleanup * hotfix: cache
This commit is contained in:
@@ -474,7 +474,7 @@
|
||||
|
||||
## Matters
|
||||
|
||||
<Route name="最新排序" author="xyqfer" example="/matters/latest" path="/matters/latest" />
|
||||
<Route name="最新排序" author="xyqfer Cerebrater" example="/matters/latest" path="/matters/latest" />
|
||||
|
||||
<Route name="熱門文章" author="Cerebrater" example="/matters/hot" path="/matters/hot" />
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const cheerio = require('cheerio');
|
||||
const axios = require('../../utils/axios');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
@@ -16,16 +17,26 @@ module.exports = async (ctx) => {
|
||||
},
|
||||
});
|
||||
|
||||
console.log(response.data);
|
||||
const items = response.data.data.viewer.recommendation.feed.edges.map(({ node }) => {
|
||||
const link = `https://matters.news/@${node.author.userName}/${encodeURIComponent(node.slug)}-${node.mediaHash}`;
|
||||
const items = await Promise.all(
|
||||
response.data.data.viewer.recommendation.feed.edges.map(async ({ node }) => {
|
||||
const link = `https://matters.news/@${node.author.userName}/${encodeURIComponent(node.slug)}-${node.mediaHash}`;
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const res = await axios.get(link);
|
||||
const $ = cheerio.load(res.data);
|
||||
const article = $('.u-content').html();
|
||||
const single = {
|
||||
title: node.title,
|
||||
link,
|
||||
description: article,
|
||||
};
|
||||
|
||||
return {
|
||||
title: node.title,
|
||||
link,
|
||||
description: node.summary,
|
||||
};
|
||||
});
|
||||
ctx.cache.set(link, JSON.stringify(single), 24 * 60 * 60);
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'Matters | 最新文章',
|
||||
|
||||
Reference in New Issue
Block a user