mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-02 10:08:02 +08:00
feat(route): add tokeninsight (#8725)
* feat: add tokeninsight's bulletin * feat: add tokeninsight's report and blog * 🔧 Add Limit for tokeninsight * refactor: migrate to v2 * fix: maintainer path Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
This commit is contained in:
52
lib/v2/tokeninsight/blog.js
Normal file
52
lib/v2/tokeninsight/blog.js
Normal file
@@ -0,0 +1,52 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const baseURL = 'https://www.tokeninsight.com/';
|
||||
const title = 'TokenInsight';
|
||||
const link = 'https://www.tokeninsight.com/';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const lang = ctx.params.lang ?? 'zh';
|
||||
|
||||
const getBlogs = async () => {
|
||||
const url = `${baseURL}api/user/search/getAllList`;
|
||||
const response = (
|
||||
await got.post(url, {
|
||||
form: {
|
||||
isRecommend: 2,
|
||||
language: lang === 'zh' ? 'cn' : lang,
|
||||
},
|
||||
})
|
||||
).data;
|
||||
return response.data.blogsList;
|
||||
};
|
||||
|
||||
const getBlogInfomation = async (blog) => {
|
||||
const { publishDate, title, id } = blog;
|
||||
const blogUrl = `${baseURL}${lang}/blogs/${id}`;
|
||||
const description = await ctx.cache.tryGet(blogUrl, async () => {
|
||||
const res = await got(blogUrl);
|
||||
const $ = cheerio.load(res.data);
|
||||
const description = $('.detail_html_box').html();
|
||||
return description;
|
||||
});
|
||||
return {
|
||||
// 文章标题
|
||||
title,
|
||||
// 文章正文
|
||||
description,
|
||||
// 文章发布时间
|
||||
pubDate: parseDate(publishDate),
|
||||
// 文章链接
|
||||
link: blogUrl,
|
||||
};
|
||||
};
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 30;
|
||||
const blogs = (await getBlogs()).slice(0, limit);
|
||||
const list = await Promise.all(blogs.map(getBlogInfomation));
|
||||
ctx.state.data = {
|
||||
title: `${lang === 'zh' ? '博客' : 'Blogs'} | ${title}`,
|
||||
link: `${link}${lang}/blogs`,
|
||||
item: list,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user