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
38 lines
1.2 KiB
JavaScript
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,
|
|
};
|
|
};
|