mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix(route): latest of Matters & redirect hot to it (#7116)
This commit is contained in:
@@ -1803,12 +1803,6 @@
|
||||
source: '',
|
||||
target: '/matters/latest',
|
||||
},
|
||||
{
|
||||
title: '熱門文章',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#matters',
|
||||
source: '',
|
||||
target: '/matters/hot',
|
||||
},
|
||||
{
|
||||
title: '标签',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#matters',
|
||||
|
||||
@@ -227,11 +227,7 @@ Provides a better reading experience (full text articles) over the official one.
|
||||
|
||||
### Latest
|
||||
|
||||
<RouteEn author="xyqfer Cerebrater" example="/matters/latest" path="/matters/latest" radar="1" rssbud="1"/>
|
||||
|
||||
### Hot
|
||||
|
||||
<RouteEn author="Cerebrater" example="/matters/hot" path="/matters/hot" radar="1" rssbud="1"/>
|
||||
<RouteEn author="xyqfer Cerebrater xosdy" example="/matters/latest" path="/matters/latest" radar="1" rssbud="1"/>
|
||||
|
||||
### Tags
|
||||
|
||||
|
||||
+1
-5
@@ -421,13 +421,9 @@ IPFS 网关有可能失效,那时候换成其他网关。
|
||||
|
||||
## Matters
|
||||
|
||||
### 熱門文章
|
||||
|
||||
<Route author="Cerebrater" example="/matters/hot" path="/matters/hot" radar="1" rssbud="1"/>
|
||||
|
||||
### 最新、熱議、精華
|
||||
|
||||
<Route author="xyqfer Cerebrater" example="/matters/latest/heat" path="/matters/latest/:type?" :paramsDesc="['默認爲 latest, 見下表']" radar="1" rssbud="1">
|
||||
<Route author="xyqfer Cerebrater xosdy" example="/matters/latest/heat" path="/matters/latest/:type?" :paramsDesc="['默認爲 latest, 見下表']" radar="1" rssbud="1">
|
||||
|
||||
| 最新 | 熱議 | 精華 |
|
||||
| ------ | ---- | ------- |
|
||||
|
||||
+1
-1
@@ -1612,7 +1612,7 @@ router.get('/zaker/focusread', require('./routes/zaker/focusread'));
|
||||
// Matters
|
||||
router.get('/matters/topics', require('./routes/matters/topics'));
|
||||
router.get('/matters/latest/:type?', require('./routes/matters/latest'));
|
||||
router.get('/matters/hot', require('./routes/matters/hot'));
|
||||
router.redirect('/matters/hot', '/matters/latest/heat'); // Deprecated
|
||||
router.get('/matters/tags/:tid', require('./routes/matters/tags'));
|
||||
router.get('/matters/author/:uid', require('./routes/matters/author'));
|
||||
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = `https://matters.news/`;
|
||||
|
||||
const res = await got.get(url);
|
||||
const $ = cheerio.load(res.data);
|
||||
const list = $('article section.list-item').get();
|
||||
|
||||
const proList = [];
|
||||
const indexList = [];
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item, i) => {
|
||||
const $ = cheerio.load(item);
|
||||
const time = $('time').attr('datetime');
|
||||
const title = $('h2').text();
|
||||
const author = $('span.displayname').text();
|
||||
const partial = encodeURI($('section.title > a').attr('href'));
|
||||
const completeUrl = `https://matters.news${partial}`;
|
||||
const cache = await ctx.cache.get(completeUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const single = {
|
||||
title,
|
||||
pubDate: new Date(time).toUTCString(),
|
||||
author,
|
||||
link: completeUrl,
|
||||
guid: completeUrl,
|
||||
};
|
||||
proList.push(got.get(completeUrl));
|
||||
indexList.push(i);
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
const responses = await got.all(proList);
|
||||
for (let i = 0; i < responses.length; i++) {
|
||||
const res = responses[i];
|
||||
const $ = cheerio.load(res.data);
|
||||
out[indexList[i]].description = $('.u-content').html();
|
||||
ctx.cache.set(out[indexList[i]].link, JSON.stringify(out[i]));
|
||||
}
|
||||
ctx.state.data = {
|
||||
title: `熱門文章 - ${$('title').text()}`,
|
||||
link: url,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
@@ -1,53 +1,64 @@
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type || 'latest';
|
||||
const url = `https://server.matters.news/graphql`;
|
||||
const options = {
|
||||
latest: {
|
||||
title: '最新',
|
||||
url: `https://server.matters.news/graphql?operationName=NewestFeedPublic&variables=%7B%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%22e92b760b24751d2fd2f1664e5bfe3d26518fc6e59fe81678de88e1aa3c37bcdc%22%7D%7D`,
|
||||
apiType: 'newest',
|
||||
},
|
||||
heat: {
|
||||
title: '熱議',
|
||||
url: `https://server.matters.news/graphql?operationName=TopicsFeedPublic&variables=%7B%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%2292b779fe8f47f0c9ed8b0876c905b4ca2dd75b8cd733f1984294cd3893b50949%22%7D%7D`,
|
||||
apiType: 'hottest',
|
||||
},
|
||||
essence: {
|
||||
title: '精華',
|
||||
url: `https://server.matters.news/graphql?operationName=IcymiFeedPublic&variables=%7B%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%22c2175d06bc033da1598acfb99100ebae2eed52a913f9f7c862b675e7688bdee1%22%7D%7D`,
|
||||
apiType: 'icymi',
|
||||
},
|
||||
};
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: options[type].url,
|
||||
headers: {
|
||||
referer: `https://matters.news/`,
|
||||
method: 'post',
|
||||
url: url,
|
||||
json: {
|
||||
query: `
|
||||
{
|
||||
viewer {
|
||||
id
|
||||
recommendation {
|
||||
feed: ${options[type].apiType}(input: { first: 10 }) {
|
||||
edges {
|
||||
node {
|
||||
author {
|
||||
userName
|
||||
displayName
|
||||
}
|
||||
slug
|
||||
mediaHash
|
||||
title
|
||||
content
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`,
|
||||
},
|
||||
});
|
||||
|
||||
const item = 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 got.get(link);
|
||||
const $ = cheerio.load(res.data);
|
||||
const article = $('.u-content').html();
|
||||
const single = {
|
||||
title: node.title,
|
||||
link,
|
||||
description: article,
|
||||
author: node.author.userName,
|
||||
pubDate: node.createdAt,
|
||||
};
|
||||
|
||||
ctx.cache.set(link, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
const item = response.data.data.viewer.recommendation.feed.edges.map(({ node }) => {
|
||||
const link = `https://matters.news/@${node.author.userName}/${node.slug}-${node.mediaHash}`;
|
||||
const article = node.content;
|
||||
return {
|
||||
title: node.title,
|
||||
link,
|
||||
description: article,
|
||||
author: node.author.displayName,
|
||||
pubDate: node.createdAt,
|
||||
};
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: `Matters | ${options[type].title}`,
|
||||
|
||||
Reference in New Issue
Block a user