Skip to content

Commit

Permalink
feat: Matters 熱議 & 精华 #6130 (DIYgod#6199)
Browse files Browse the repository at this point in the history
  • Loading branch information
laampui authored Nov 24, 2020
1 parent 3451909 commit d16439e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
14 changes: 10 additions & 4 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,20 @@ Tag

## Matters

### 最新排序

<Route author="xyqfer Cerebrater" example="/matters/latest" path="/matters/latest" radar="1" rssbud="1"/>

### 熱門文章

<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">

| 最新 | 熱議 | 精華 |
| ------ | ---- | ------- |
| latest | heat | essence |

</Route>

### 标签

<Route author="Cerebrater" example="/matters/tags/VGFnOjk3Mg" path="/matters/tags/:tid" :paramsDesc="['標籤 id,可在標籤所在的 URL 找到']" radar="1" rssbud="1"/>
Expand Down
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ router.get('/zaker/focusread', require('./routes/zaker/focusread'));

// Matters
router.get('/matters/topics', require('./routes/matters/topics'));
router.get('/matters/latest', require('./routes/matters/latest'));
router.get('/matters/latest/:type?', require('./routes/matters/latest'));
router.get('/matters/hot', require('./routes/matters/hot'));
router.get('/matters/tags/:tid', require('./routes/matters/tags'));
router.get('/matters/author/:uid', require('./routes/matters/author'));
Expand Down
43 changes: 23 additions & 20 deletions lib/routes/matters/latest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@ const cheerio = require('cheerio');
const got = require('@/utils/got');

module.exports = async (ctx) => {
const type = ctx.params.type || 'latest';
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`,
},
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`,
},
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`,
},
};

const response = await got({
method: 'post',
url: 'https://server.matters.news/graphql',
json: {
operationName: 'NewestFeed',
variables: {
hasArticleDigestActionAuthor: false,
hasArticleDigestActionBookmark: true,
hasArticleDigestActionTopicScore: false,
},
extensions: {
persistedQuery: {
version: 1,
sha256Hash: '08291b314126ef9011592f1b04652a6960fa01a5de68965451c7552188381774',
},
},
query:
'query NewestFeed($after: String, $hasArticleDigestActionAuthor: Boolean = false, $hasArticleDigestActionBookmark: Boolean = true, $hasArticleDigestActionTopicScore: Boolean = false) {\n viewer {\n id\n recommendation {\n feed: newest(input: {first: 10, after: $after}) {\n ...FeedArticleConnection\n __typename\n }\n __typename\n }\n __typename\n }\n}\n\nfragment FeedArticleConnection on ArticleConnection {\n pageInfo {\n startCursor\n endCursor\n hasNextPage\n __typename\n }\n edges {\n cursor\n node {\n ...FeedDigestArticle\n __typename\n }\n __typename\n }\n __typename\n}\n\nfragment FeedDigestArticle on Article {\n id\n title\n slug\n cover\n summary\n mediaHash\n live\n author {\n id\n userName\n ...UserDigestMiniUser\n __typename\n }\n ...DigestActionsArticle\n ...FingerprintArticle\n ...DropdownActionsArticle\n __typename\n}\n\nfragment UserDigestMiniUser on User {\n id\n userName\n displayName\n ...AvatarUser\n __typename\n}\n\nfragment AvatarUser on User {\n avatar\n __typename\n}\n\nfragment DigestActionsArticle on Article {\n author {\n ...UserDigestMiniUser @include(if: $hasArticleDigestActionAuthor)\n __typename\n }\n createdAt\n ...AppreciationArticle\n ...ResponseCountArticle\n ...BookmarkArticle @include(if: $hasArticleDigestActionBookmark)\n ...TopicScoreArticle @include(if: $hasArticleDigestActionTopicScore)\n ...StateActionsArticle\n __typename\n}\n\nfragment AppreciationArticle on Article {\n appreciationsReceivedTotal\n __typename\n}\n\nfragment ResponseCountArticle on Article {\n id\n slug\n mediaHash\n responseCount\n author {\n userName\n __typename\n }\n __typename\n}\n\nfragment BookmarkArticle on Article {\n id\n subscribed\n __typename\n}\n\nfragment TopicScoreArticle on Article {\n topicScore\n __typename\n}\n\nfragment StateActionsArticle on Article {\n state\n __typename\n}\n\nfragment FingerprintArticle on Article {\n id\n dataHash\n __typename\n}\n\nfragment DropdownActionsArticle on Article {\n id\n ...ArchiveButtonArticle\n ...StickyButtonArticle\n __typename\n}\n\nfragment StickyButtonArticle on Article {\n id\n sticky\n author {\n id\n userName\n __typename\n }\n __typename\n}\n\nfragment ArchiveButtonArticle on Article {\n id\n state\n author {\n id\n userName\n __typename\n }\n __typename\n}\n',
method: 'get',
url: options[type].url,
headers: {
referer: `https://matters.news/`,
},
});

const items = await Promise.all(
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);
Expand All @@ -47,8 +50,8 @@ module.exports = async (ctx) => {
);

ctx.state.data = {
title: 'Matters | 最新文章',
title: `Matters | ${options[type].title}`,
link: 'https://matters.news/',
item: items,
item,
};
};

0 comments on commit d16439e

Please sign in to comment.