mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-15 01:30:33 +08:00
feat: 微信公众号(tgchanel)全文 (#2208)
* enhance: 微信公众号(tgchanel)全文 fix 2 typos * enhance: 添加作者并兼容多个公众号情况
This commit is contained in:
@@ -640,7 +640,7 @@ pageClass: routes
|
|||||||
|
|
||||||
<Route author="HenryQW" example="/wechat/csm/huxiu_com" path="/wechat/csm/:id" :paramsDesc="['公众号 id, 打开公众号页, 在 URL 中找到 id']"/>
|
<Route author="HenryQW" example="/wechat/csm/huxiu_com" path="/wechat/csm/:id" :paramsDesc="['公众号 id, 打开公众号页, 在 URL 中找到 id']"/>
|
||||||
|
|
||||||
### 公众号(Telegrame 频道来源)
|
### 公众号(Telegram 频道来源)
|
||||||
|
|
||||||
<Route author="LogicJake" example="/wechat/tgchannel/lifeweek" path="/wechat/tgchannel/:id" :paramsDesc="['公众号绑定频道 id']">
|
<Route author="LogicJake" example="/wechat/tgchannel/lifeweek" path="/wechat/tgchannel/:id" :paramsDesc="['公众号绑定频道 id']">
|
||||||
|
|
||||||
|
|||||||
@@ -6,25 +6,52 @@ module.exports = async (ctx) => {
|
|||||||
|
|
||||||
const { data } = await axios.get(`https://t.me/s/${id}`);
|
const { data } = await axios.get(`https://t.me/s/${id}`);
|
||||||
const $ = cheerio.load(data);
|
const $ = cheerio.load(data);
|
||||||
const list = $('.tgme_widget_message_wrap');
|
const list = $('.tgme_widget_message_wrap').slice(-10);
|
||||||
|
|
||||||
const out = await Promise.all(
|
const out = await Promise.all(
|
||||||
list
|
list
|
||||||
.map((index, item) => {
|
.map(async (index, item) => {
|
||||||
item = $(item);
|
item = $(item);
|
||||||
const title = item.find('.tgme_widget_message_text > a:nth-child(2)').text();
|
|
||||||
const link = item.find('.tgme_widget_message_text > a:nth-child(2)').attr('href');
|
let author;
|
||||||
|
let title = item.find('.tgme_widget_message_text > a:nth-child(5)').text() || item.find('.tgme_widget_message_text > a:nth-child(2)').text();
|
||||||
|
|
||||||
|
const all_text = item.find('.tgme_widget_message_text').text();
|
||||||
|
if (all_text.indexOf(':') !== -1) {
|
||||||
|
author = all_text.split(':')[0].split(' ')[1];
|
||||||
|
title = author + ': ' + title;
|
||||||
|
}
|
||||||
|
|
||||||
|
const link = item.find('.tgme_widget_message_text > a:nth-child(5)').attr('href') || item.find('.tgme_widget_message_text > a:nth-child(2)').attr('href');
|
||||||
const pubDate = new Date(item.find('.tgme_widget_message_date time').attr('datetime')).toUTCString();
|
const pubDate = new Date(item.find('.tgme_widget_message_date time').attr('datetime')).toUTCString();
|
||||||
const description = item.find('.tgme_widget_message_text').html();
|
|
||||||
|
|
||||||
const single = {
|
const single = {
|
||||||
title,
|
title,
|
||||||
pubDate,
|
pubDate,
|
||||||
link,
|
link,
|
||||||
description,
|
author,
|
||||||
};
|
};
|
||||||
|
|
||||||
return single;
|
if (link !== undefined) {
|
||||||
|
const value = await ctx.cache.get(link);
|
||||||
|
if (value) {
|
||||||
|
single.description = value;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
const reponse = await axios.get(link);
|
||||||
|
const $ = cheerio.load(reponse.data);
|
||||||
|
|
||||||
|
single.description = $('.rich_media_content')
|
||||||
|
.html()
|
||||||
|
.replace(/data-src/g, 'src');
|
||||||
|
ctx.cache.set(link, single.description, 12 * 60 * 60);
|
||||||
|
} catch (err) {
|
||||||
|
single.description = item.find('.tgme_widget_message_text').html();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve(single);
|
||||||
})
|
})
|
||||||
.get()
|
.get()
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user