Merge remote-tracking branch 'origin/master'

This commit is contained in:
DIYgod 2023-12-19 22:03:36 +08:00
commit 95864937f2
No known key found for this signature in database
9 changed files with 59 additions and 32 deletions

View File

@ -26,9 +26,9 @@ router.get('/benedictevans', lazyloadRouteHandler('./routes/benedictevans/recent
router.get('/ziroom/room/:city/:iswhole/:room/:keyword', lazyloadRouteHandler('./routes/ziroom/room'));
// 简书
router.get('/jianshu/home', lazyloadRouteHandler('./routes/jianshu/home'));
router.get('/jianshu/collection/:id', lazyloadRouteHandler('./routes/jianshu/collection'));
router.get('/jianshu/user/:id', lazyloadRouteHandler('./routes/jianshu/user'));
// router.get('/jianshu/home', lazyloadRouteHandler('./routes/jianshu/home'));
// router.get('/jianshu/collection/:id', lazyloadRouteHandler('./routes/jianshu/collection'));
// router.get('/jianshu/user/:id', lazyloadRouteHandler('./routes/jianshu/user'));
// 妹子图
router.get('/mzitu/home/:type?', lazyloadRouteHandler('./routes/mzitu/home'));

View File

@ -0,0 +1,5 @@
module.exports = {
'/collection/:id': ['DIYgod', 'HenryQW', 'JimenezLi'],
'/home': ['DIYgod', 'HenryQW', 'JimenezLi'],
'/user/:id': ['DIYgod', 'HenryQW', 'JimenezLi'],
};

25
lib/v2/jianshu/radar.js Normal file
View File

@ -0,0 +1,25 @@
module.exports = {
'jianshu.com': {
_name: '简书',
www: [
{
title: '首页',
docs: 'https://docs.rsshub.app/routes/social-media#jian-shu',
source: '/',
target: '/jianshu/home',
},
{
title: '专题',
docs: 'https://docs.rsshub.app/routes/social-media#jian-shu',
source: '/c/:id',
target: '/jianshu/collection/:id',
},
{
title: '作者',
docs: 'https://docs.rsshub.app/routes/social-media#jian-shu',
source: '/u/:id',
target: '/jianshu/user/:id',
},
],
},
};

5
lib/v2/jianshu/router.js Normal file
View File

@ -0,0 +1,5 @@
module.exports = (router) => {
router.get('/collection/:id', require('./collection'));
router.get('/home', require('./home'));
router.get('/user/:id', require('./user'));
};

View File

@ -1,18 +1,14 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
// 加载文章页
async function load(link) {
const load = async (link) => {
const response = await got.get(link);
const $ = cheerio.load(response.data);
// 解析日期
const date = new Date($('time').attr('datetime'));
const timeZone = 8;
const serverOffset = date.getTimezoneOffset() / 60;
const pubDate = new Date(date.getTime() - 60 * 60 * 1000 * (timeZone + serverOffset)).toUTCString();
const pubDate = timezone(parseDate($('time').attr('datetime')), +8);
// 去除样式
$('.image-container, .image-container-fill').removeAttr('style');
// 处理视频
@ -30,33 +26,29 @@ async function load(link) {
const description = $('article').html();
return { description, pubDate };
}
};
const ProcessFeed = (list, caches) => {
const host = 'https://www.jianshu.com';
return Promise.all(
list.map(async (item) => {
list.map((item) => {
const $ = cheerio.load(item);
const $title = $('.title');
// 还原相对链接为绝对链接
const itemUrl = url.resolve(host, $title.attr('href'));
// 列表上提取到的信息
const single = {
title: $title.text(),
link: itemUrl,
author: $('.nickname').text(),
guid: itemUrl,
};
const itemUrl = new URL($title.attr('href'), host).toString();
// 使用tryGet方法从缓存获取内容。
// 当缓存中无法获取到链接内容的时候则使用load方法加载文章内容。
const other = await caches.tryGet(itemUrl, () => load(itemUrl));
// 合并解析后的结果集作为该篇文章最终的输出结果
return Promise.resolve(Object.assign({}, single, other));
// 当缓存中无法获取到链接内容的时候则使用load方法加载文章内容
return caches.tryGet(itemUrl, async () => {
const other = await load(itemUrl);
// 合并解析后的结果集作为该篇文章最终的输出结果
return {
title: $title.text(),
link: itemUrl,
author: $('.nickname').text(),
...other,
};
});
})
);
};

View File

@ -1317,15 +1317,15 @@ YouTube provides official RSS feeds for channels, for instance [https://www.yout
### 首页 {#jian-shu-shou-ye}
<Route author="DIYgod HenryQW" example="/jianshu/home" path="/jianshu/home" />
<Route author="DIYgod HenryQW JimenezLi" example="/jianshu/home" path="/jianshu/home" radar="1" />
### 专题 {#jian-shu-zhuan-ti}
<Route author="DIYgod HenryQW" example="/jianshu/collection/xYuZYD" path="/jianshu/collection/:id" paramsDesc={['专题 id, 可在专题页 URL 中找到']} />
<Route author="DIYgod HenryQW JimenezLi" example="/jianshu/collection/xYuZYD" path="/jianshu/collection/:id" paramsDesc={['专题 id, 可在专题页 URL 中找到']} radar="1" />
### 作者 {#jian-shu-zuo-zhe}
<Route author="DIYgod HenryQW" example="/jianshu/user/yZq3ZV" path="/jianshu/user/:id" paramsDesc={['作者 id, 可在作者主页 URL 中找到']} />
<Route author="DIYgod HenryQW JimenezLi" example="/jianshu/user/yZq3ZV" path="/jianshu/user/:id" paramsDesc={['作者 id, 可在作者主页 URL 中找到']} radar="1" />
## 酷安 {#ku-an}