diff --git a/lib/routes/sspai/series.js b/lib/routes/sspai/series.js
index 785a38c6c..f3b366b1d 100644
--- a/lib/routes/sspai/series.js
+++ b/lib/routes/sspai/series.js
@@ -1,28 +1,47 @@
const got = require('@/utils/got');
-const { JSDOM } = require('jsdom');
+const cheerio = require('cheerio');
module.exports = async (ctx) => {
- const response = await got({
- method: 'get',
- url: 'https://sspai.com/series',
- });
+ const response = await got.get('https://sspai.com/api/v1/series/tag/all/get');
- const dom = new JSDOM(response.data, {
- runScripts: 'dangerously',
- });
+ const products = response.data.data.reduce((acc, cate) => {
+ if (Array.isArray(cate.children)) {
+ const result = cate.children
+ .filter((item) => item.sell_status)
+ .map((item) => {
+ const price = item.price / 100;
+ return {
+ id: item.id,
+ title: `¥${price} - ${item.title}`,
+ link: `https://sspai.com/series/${item.id}`,
+ author: item.author.nickname,
+ };
+ });
+ return [...acc, ...result];
+ } else {
+ return acc;
+ }
+ }, []);
- const data = dom.window.__INITIAL_STATE__.seriesHomeModule.seriesSearchpage;
+ const item = await Promise.all(
+ products.map(
+ async (item) =>
+ await ctx.cache.tryGet(item.link, async () => {
+ const res = await got.get(`https://sspai.com/api/v1/series/info/get?id=${item.id}&view=second`);
+ const banner = `
`;
+ const description = banner + res.data.data.intro;
+ const $ = cheerio.load(description);
+ $('img').css('max-width', '100%');
+ item.description = $.html();
+ return item;
+ })
+ )
+ );
ctx.state.data = {
title: '少数派 -- 最新上架付费专栏',
link: 'https://sspai.com/series',
description: '少数派 -- 最新上架付费专栏',
- item: data.map((item) => ({
- title: item.title,
- description: `
${item.description}`,
- link: `https://sspai.com/series/${item.id}`,
- author: item.author.nickname,
- pubDate: new Date(item.released_at * 1000),
- })),
+ item,
};
};