Files
RSSHub/lib/v2/sspai/index.js
Henry Wang 1a547caf3b feat(route): 更新少数派全文支持 (#9653)
* feat: 少数派首页全文输出

* feat: 少数派全路由全文

* feat: 少数派专栏全文

* refactor: migrate to v2

* fix: cache key
2022-05-01 17:34:45 +08:00

38 lines
1.2 KiB
JavaScript

const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const api_url = 'https://sspai.com/api/v1/article/index/page/get?limit=10&offset=0&created_at=0';
const resp = await got({
method: 'get',
url: api_url,
});
const items = await Promise.all(
resp.data.data.map((item) => {
const link = `https://sspai.com/api/v1/article/info/get?id=${item.id}&view=second`;
let description = '';
const key = `sspai: ${item.id}`;
return ctx.cache.tryGet(key, async () => {
const response = await got({ method: 'get', url: link });
description = response.data.data.body;
return {
title: item.title.trim(),
description,
link: `https://sspai.com/post/${item.id}`,
pubDate: parseDate(item.released_time * 1000),
author: item.author.nickname,
};
});
})
);
ctx.state.data = {
title: '少数派 -- 首页',
link: 'https://sspai.com',
description: '少数派 -- 首页',
item: items,
};
};