mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 06:30:40 +08:00
* feat: 少数派首页全文输出 * feat: 少数派全路由全文 * feat: 少数派专栏全文 * refactor: migrate to v2 * fix: cache key
63 lines
1.7 KiB
JavaScript
63 lines
1.7 KiB
JavaScript
const got = require('@/utils/got');
|
|
const { parseDate } = require('@/utils/parse-date');
|
|
|
|
module.exports = async (ctx) => {
|
|
const id = ctx.params.id;
|
|
const link = `https://sspai.com/column/${id}`;
|
|
|
|
const desApi = `https://sspai.com/api/v1/special_columns/${id}`;
|
|
let response = await got({
|
|
method: 'get',
|
|
url: desApi,
|
|
headers: {
|
|
Referer: link,
|
|
},
|
|
});
|
|
|
|
const result = response.data;
|
|
const title = result.title;
|
|
const description = result.intro;
|
|
|
|
const api = `https://sspai.com/api/v1/articles?offset=0&limit=10&special_column_ids=${id}&include_total=false`;
|
|
response = await got({
|
|
method: 'get',
|
|
url: api,
|
|
headers: {
|
|
Referer: link,
|
|
},
|
|
});
|
|
|
|
const list = response.data.list;
|
|
|
|
const out = await Promise.all(
|
|
list.map((item) => {
|
|
const title = item.title;
|
|
const date = item.created_at;
|
|
const link = `https://sspai.com/api/v1/article/info/get?id=${item.id}&view=second`;
|
|
const itemUrl = `https://sspai.com/post/${item.id}`;
|
|
const author = item.author.nickname;
|
|
|
|
return ctx.cache.tryGet(`sspai: ${item.id}`, async () => {
|
|
const response = await got(link);
|
|
const description = response.data.data.body;
|
|
|
|
const single = {
|
|
title,
|
|
link: itemUrl,
|
|
author,
|
|
description,
|
|
pubDate: parseDate(date * 1000),
|
|
};
|
|
return single;
|
|
});
|
|
})
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: `少数派专栏-${title}`,
|
|
link,
|
|
description,
|
|
item: out,
|
|
};
|
|
};
|