Skip to content

Commit

Permalink
feat(route): 微信公众号新增 wechat-feeds 来源 (DIYgod#7419)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
tylinux and actions-user authored May 15, 2021
1 parent ac0e922 commit 39db632
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/en/picture.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pageClass: routes

### Home

<RouteEn author="nczitzk" example="/elitebabes" path="/elitebabes/:category?" :paramsDesc="['Category, see below, Home by default']">
<RouteEn author="nczitzk" example="/elitebabes" path="/elitebabes/:category?" :paramsDesc="['Category, see below, Home by default']"/>

| Home | Hot | Popular | Recent |
| ---- | --- | ------- | ------ |
Expand All @@ -84,7 +84,7 @@ pageClass: routes

### Videos

<RouteEn author="nczitzk" example="/elitebabes/videos" path="/elitebabes/videos/:sort?" :paramsDesc="['Sort, see below, Popular by default']">
<RouteEn author="nczitzk" example="/elitebabes/videos" path="/elitebabes/videos/:sort?" :paramsDesc="['Sort, see below, Popular by default']" />

| Popular | Recent |
| ------- | ------ |
Expand Down
4 changes: 4 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -2066,6 +2066,10 @@ column 为 third 时可选的 category:

<Route author="laampui" example="/wechat/wxnmh/51798" path="/wechat/wxnmh/:id" :paramsDesc="['公众号 id, 打开 wxnmh.com, 在 URL 中找到 id']"/>

### 公众号 (wechat-feeds 来源)

<Route author="tylinux" example="/wechat/feeds/MzIwMzAwMzQxNw==" path="/wechat/feeds/:id" :paramsDesc="['公众号 id, 打开 `https://wechat.privacyhide.com/`, 在选定公众号的订阅 URL 中找到 id, 不包含最后的 .xml']"/>

### 公众号栏目 (非推送 & 历史消息)

<Route author="MisteryMonster" example="/wechat/mp/homepage/MzA3MDM3NjE5NQ==/16" path="/wechat/mp/homepage/:biz/:hid/:cid?" :paramsDesc="['公众号id', '分页id', '页内栏目']" radar="1" rssbud="1" anticrawler="1">
Expand Down
6 changes: 3 additions & 3 deletions docs/picture.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pageClass: routes

## Dilbert Comic Strip

<Route name="Daily Strip" author="Maecenas" example="/dilbert/strip" path="/dilbert/strip">
<Route name="Daily Strip" author="Maecenas" example="/dilbert/strip" path="/dilbert/strip" />

通过提取漫画,提供比官方源更佳的阅读体验。

Expand All @@ -98,7 +98,7 @@ pageClass: routes

### Home

<Route author="nczitzk" example="/elitebabes" path="/elitebabes/:category?" :paramsDesc="['分类,见下表,默认为 Home']">
<Route author="nczitzk" example="/elitebabes" path="/elitebabes/:category?" :paramsDesc="['分类,见下表,默认为 Home']" />

| Home | Hot | Popular | Recent |
| ---- | --- | ------- | ------ |
Expand All @@ -108,7 +108,7 @@ pageClass: routes

### Videos

<Route author="nczitzk" example="/elitebabes/videos" path="/elitebabes/videos/:sort?" :paramsDesc="['排序,见下表,默认为 Popular']">
<Route author="nczitzk" example="/elitebabes/videos" path="/elitebabes/videos/:sort?" :paramsDesc="['排序,见下表,默认为 Popular']"/>

| Popular | Recent |
| ------- | ------ |
Expand Down
1 change: 1 addition & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ router.get('/wechat/wjdn/:id', require('./routes/tencent/wechat/wjdn'));
router.get('/wechat/wxnmh/:id', require('./routes/tencent/wechat/wxnmh'));
router.get('/wechat/mp/homepage/:biz/:hid/:cid?', require('./routes/tencent/wechat/mp'));
router.get('/wechat/mp/msgalbum/:biz/:aid', require('./routes/tencent/wechat/msgalbum'));
router.get('/wechat/feeds/:id', require('./routes/tencent/wechat/feeds'));

// All the Flight Deals
router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index'));
Expand Down
47 changes: 47 additions & 0 deletions lib/routes/tencent/wechat/feeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const parser = require('@/utils/rss-parser');
const got = require('@/utils/got');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const { id } = ctx.params;
const link = `https://github.com/hellodword/wechat-feeds/raw/feeds/${id}.xml`;
const feed = await parser.parseURL(link);

const items = await Promise.all(
feed.items.map(async (item) => {
const cache = await ctx.cache.get(item.link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}

const response = await got.get(item.link);

const $ = cheerio.load(response.data);
const post = $('#js_content');

post.find('img').each((_, img) => {
const dataSrc = $(img).attr('data-src');
if (dataSrc) {
$(img).attr('src', dataSrc);
}
});

const single = {
title: item.title,
description: post.html(),
pubDate: new Date(item.pubDate),
link: item.link,
};

ctx.cache.set(item.link, JSON.stringify(single));
return Promise.resolve(single);
})
);

ctx.state.data = {
title: `${feed.title}`,
link,
description: feed.description,
item: items,
};
};

0 comments on commit 39db632

Please sign in to comment.