mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 15:47:48 +08:00
fix(route): HelloGitHub月刊 (#11226)
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
const got = require('@/utils/got');
|
const got = require('@/utils/got');
|
||||||
const { parseDate } = require('@/utils/parse-date');
|
|
||||||
const { art } = require('@/utils/render');
|
const { art } = require('@/utils/render');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const md = require('markdown-it')({
|
const md = require('markdown-it')({
|
||||||
@@ -11,12 +10,8 @@ art.defaults.imports.render = function (string) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = async (ctx) => {
|
module.exports = async (ctx) => {
|
||||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 30;
|
|
||||||
|
|
||||||
const rootUrl = 'https://hellogithub.com';
|
const rootUrl = 'https://hellogithub.com';
|
||||||
const apiRootUrl = 'https://api.hellogithub.com';
|
|
||||||
const currentUrl = `${rootUrl}/periodical/volume/`;
|
const currentUrl = `${rootUrl}/periodical/volume/`;
|
||||||
const apiUrl = `${apiRootUrl}/v1/volume/all/`;
|
|
||||||
|
|
||||||
const buildResponse = await got({
|
const buildResponse = await got({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
@@ -25,38 +20,26 @@ module.exports = async (ctx) => {
|
|||||||
|
|
||||||
const buildId = buildResponse.data.match(/"buildId":"(.*?)",/)[1];
|
const buildId = buildResponse.data.match(/"buildId":"(.*?)",/)[1];
|
||||||
|
|
||||||
|
const apiUrl = `${rootUrl}/_next/data/${buildId}/periodical/volume.json`;
|
||||||
|
|
||||||
const response = await got({
|
const response = await got({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: apiUrl,
|
url: apiUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
let items = response.data.data.slice(0, limit).map((item) => ({
|
const data = response.data;
|
||||||
guid: item.num,
|
const id = data.pageProps.volume.current_num;
|
||||||
title: `No.${item.num}`,
|
|
||||||
link: `${rootUrl}/periodical/volume/${item.guid}`,
|
|
||||||
}));
|
|
||||||
|
|
||||||
items = await Promise.all(
|
const items = [
|
||||||
items.map((item) =>
|
{
|
||||||
ctx.cache.tryGet(item.link, async () => {
|
guid: id,
|
||||||
const detailUrl = `${rootUrl}/_next/data/${buildId}/periodical/volume/${item.guid}.json`;
|
title: `No.${id}`,
|
||||||
|
link: `${rootUrl}/periodical/volume/${id}`,
|
||||||
const detailResponse = await got({
|
description: art(path.join(__dirname, 'templates/volume.art'), {
|
||||||
method: 'get',
|
data: data.pageProps.volume.data,
|
||||||
url: detailUrl,
|
}),
|
||||||
});
|
},
|
||||||
|
];
|
||||||
const data = detailResponse.data;
|
|
||||||
|
|
||||||
item.pubDate = parseDate(data.pageProps.volume.publish_at);
|
|
||||||
item.description = art(path.join(__dirname, 'templates/volume.art'), {
|
|
||||||
data: data.pageProps.volume.data,
|
|
||||||
});
|
|
||||||
|
|
||||||
return item;
|
|
||||||
})
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
ctx.state.data = {
|
ctx.state.data = {
|
||||||
title: 'HelloGithub - 月刊',
|
title: 'HelloGithub - 月刊',
|
||||||
|
|||||||
Reference in New Issue
Block a user