Files
RSSHub/lib/v2/sspai/topics.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.3 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/topics?offset=0&limit=20&include_total=false`;
const resp = await got({
method: 'get',
url: api_url,
});
const data = resp.data.list;
const items = await Promise.all(
data.map((item) => {
const link = `https://sspai.com/topic/${item.id}`;
let description = '';
const key = `sspai:topics:${item.id}`;
return ctx.cache.tryGet(key, () => {
description = `${item.intro}<br><img src="https://cdn.sspai.com/${item.banner}" /><br>如有兴趣,请复制链接订阅 <br> <h3>https://rsshub.app/sspai/topic/${item.id}</h3>`;
return {
title: item.title.trim(),
description,
link,
pubDate: parseDate(item.released_at * 1000),
author: item.author.nickname,
};
});
})
);
ctx.state.data = {
title: `少数派专题广场更新推送`,
link: `https://sspai.com/topics`,
description: `仅仅推送新的专题(集合型而非具体文章) `,
item: items,
};
};