feat(secrss): full text support (#14284)

* feat(secrss): full text support

* fix(secrss): pubDate author category
This commit is contained in:
SunBK201
2024-01-19 09:00:33 +00:00
committed by GitHub
parent d006267ce3
commit ed5c6fff48
4 changed files with 41 additions and 19 deletions
+18 -7
View File
@@ -1,5 +1,6 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const api = 'https://www.secrss.com/api/articles/group?author=';
@@ -8,13 +9,23 @@ module.exports = async (ctx) => {
const res = await got(`${api}${author}`);
const dataArray = res.data.data.list;
const items = dataArray.map((item) => ({
title: item.title,
description: item.summary,
pubDate: parseDate(item.original_timestamp, 'X'),
link: `${host}${item.url}`,
category: item.tag,
}));
const items = await Promise.all(
dataArray.map((item) => {
const itemUrl = `${host}${item.url}`;
return ctx.cache.tryGet(itemUrl, async () => {
const result = await got(itemUrl);
const $ = cheerio.load(result.data);
const description = $('.article-body').html().trim();
return {
title: item.title,
link: itemUrl,
pubDate: parseDate(item.original_timestamp, 'X'),
description,
category: item.tag,
};
});
})
);
ctx.state.data = {
title: `安全内参-${author}`,
+19 -8
View File
@@ -1,6 +1,7 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const api = 'https://www.secrss.com/api/articles?tag=';
@@ -9,14 +10,24 @@ module.exports = async (ctx) => {
const res = await got(`${api}${category}`);
const dataArray = res.data.data;
const items = dataArray.map((item) => ({
title: item.title,
description: item.summary,
pubDate: timezone(parseDate(item.published_at), +8),
link: `${host}/articles/${item.id}`,
author: item.source_author,
category: item.tags.map((t) => t.title),
}));
const items = await Promise.all(
dataArray.map((item) => {
const itemUrl = `${host}/articles/${item.id}`;
return ctx.cache.tryGet(itemUrl, async () => {
const result = await got(itemUrl);
const $ = cheerio.load(result.data);
const description = $('.article-body').html().trim();
return {
title: item.title,
link: itemUrl,
pubDate: timezone(parseDate(item.published_at), 8),
description,
author: item.source_author,
category: item.tags.map((t) => t.title),
};
});
})
);
ctx.state.data = {
title: `安全内参-${category}`,
+2 -2
View File
@@ -1,4 +1,4 @@
module.exports = {
'/author/:author': ['XinRoom'],
'/category/:category?': ['XinRoom'],
'/author/:author': ['XinRoom', 'SunBK201'],
'/category/:category?': ['XinRoom', 'SunBK201'],
};
+2 -2
View File
@@ -809,11 +809,11 @@ Stay up to date on the latest React news, tutorials, resources, and more. Delive
### 分类 {#an-quan-nei-can-fen-lei}
<Route author="XinRoom" example="/secrss/category/产业趋势" path="/secrss/category/:category?" radar="1" />
<Route author="XinRoom SunBK201" example="/secrss/category/产业趋势" path="/secrss/category/:category?" radar="1" />
### 作者 {#an-quan-nei-can-zuo-zhe}
<Route author="XinRoom" example="/secrss/author/网络安全威胁和漏洞信息共享平台" path="/secrss/author/:author" radar="1" />
<Route author="XinRoom SunBK201" example="/secrss/author/网络安全威胁和漏洞信息共享平台" path="/secrss/author/:author" radar="1" />
## 北京智源人工智能研究院 {#bei-jing-zhi-yuan-ren-gong-zhi-neng-yan-jiu-yuan}