mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-07 21:47:57 +08:00
add 观察者风闻话题
This commit is contained in:
@@ -12,6 +12,10 @@
|
||||
|
||||
<Route name="7x24小时快讯" author="occupy5" example="/fx678/kx" path="/fx678/kx" />
|
||||
|
||||
## 观察者风闻话题
|
||||
|
||||
<Route name="观察者风闻话题" author="occupy5" example="/guancha/topic/113" path="/guancha/topic/:id" :paramsDesc="['话题id, 可在URL中找到']" />
|
||||
|
||||
## 99% Invisible
|
||||
|
||||
<Route name="Transcript" author="Ji4n1ng" example="/99percentinvisible/transcript" path="/99percentinvisible/transcript"/>
|
||||
|
||||
@@ -1347,4 +1347,7 @@ router.get('/paidai', require('./routes/paidai/index'));
|
||||
router.get('/paidai/bbs', require('./routes/paidai/bbs'));
|
||||
router.get('/paidai/news', require('./routes/paidai/news'));
|
||||
|
||||
// 观察者风闻话题
|
||||
router.get('/guancha/topic/:id', require('./routes/guancha/topic'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
52
lib/routes/guanchazhe/topic.js
Normal file
52
lib/routes/guanchazhe/topic.js
Normal file
@@ -0,0 +1,52 @@
|
||||
const cheerio = require('cheerio');
|
||||
const axios = require('../../utils/axios');
|
||||
const url = require('url');
|
||||
|
||||
const host = 'https://user.guancha.cn';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const link = `https://user.guancha.cn/topic/attention-topic?follow-topic-id=${id}`;
|
||||
const res = await axios.get(encodeURI(link));
|
||||
const $ = cheerio.load(res.data);
|
||||
// 话题名称
|
||||
const title = $('.topic-main').text();
|
||||
// 文章列表
|
||||
const list = $('.article-list .list-item h4')
|
||||
.find('a')
|
||||
.map((i, e) => $(e).attr('href'))
|
||||
.get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (itemUrl) => {
|
||||
// 将相对链接替换为绝对链接
|
||||
const absoluteUrl = url.resolve(host, itemUrl);
|
||||
const res = await axios.get(absoluteUrl);
|
||||
const $ = cheerio.load(res.data);
|
||||
|
||||
const item = {
|
||||
title: $('.article-content h1').text(),
|
||||
author: $('.user-main h4')
|
||||
.first()
|
||||
.find('a')
|
||||
.text(),
|
||||
link: absoluteUrl,
|
||||
description: $('.article-txt-content').html(),
|
||||
pubDate: $('.user-main .time1').text(),
|
||||
};
|
||||
const cache = await ctx.cache.get(absoluteUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
ctx.cache.set(absoluteUrl, JSON.stringify(item), 24 * 60 * 60);
|
||||
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `风闻话题-${title}`,
|
||||
link: link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user