mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-15 10:15:23 +08:00
Show fulltext description for Sspai Matrix (#1450)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const api_url = 'https://sspai.com/api/v1/articles?offset=0&limit=20&is_matrix=1&sort=matrix_at&include_total=false';
|
||||
@@ -7,17 +8,37 @@ module.exports = async (ctx) => {
|
||||
url: api_url,
|
||||
});
|
||||
const data = resp.data.list;
|
||||
const items = await Promise.all(
|
||||
data.map(async (item) => {
|
||||
const link = `https://sspai.com/post/${item.id}`;
|
||||
let description = '';
|
||||
|
||||
const key = `sspai: ${item.id}`;
|
||||
const value = await ctx.cache.get(key);
|
||||
|
||||
if (value) {
|
||||
description = value;
|
||||
} else {
|
||||
const response = await axios({ method: 'get', url: link });
|
||||
const $ = cheerio.load(response.data);
|
||||
description = $('#article-content > div').html();
|
||||
ctx.cache.set(key, description, 24 * 60 * 60);
|
||||
}
|
||||
|
||||
return {
|
||||
title: item.title.trim(),
|
||||
description: description,
|
||||
link: link,
|
||||
pubDate: new Date(item.released_at * 1000).toUTCString(),
|
||||
author: item.author.nickname,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '少数派 -- Matrix',
|
||||
link: 'https://sspai.com/matrix',
|
||||
description: '少数派 -- Matrix',
|
||||
item: data.map((item) => ({
|
||||
title: item.title.trim(),
|
||||
description: item.summary.trim(),
|
||||
link: `https://sspai.com/post/${item.id}`,
|
||||
pubDate: new Date(item.released_at * 1000).toUTCString(),
|
||||
author: item.author.nickname,
|
||||
})),
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user