Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add 时光网 #9443

Merged
merged 20 commits into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/multimedia.md
Original file line number Diff line number Diff line change
Expand Up @@ -1496,3 +1496,9 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
### 综艺

<Route author="pharaoh2012" example="/zyshow/chongchongchong" path="/zyshow/:name" :paramsDesc="['综艺 name,对应综艺的 URL 中找到']" radar="1" rssbud="1"/>

## 时光网

### 资讯

<Route author="TsSmartTT" example="/mtime/news" path="/mtime/news" radar="1" rssbud="1"/>
3 changes: 3 additions & 0 deletions lib/v2/mtime/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/mtime/news': ['TsSmartTT'],
};
48 changes: 48 additions & 0 deletions lib/v2/mtime/news.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const link = 'http://news.mtime.com/';
const response = await got({
method: 'get',
url: link,
});
const $ = cheerio.load(response.data);
const list = $('ul.left-cont.fix li')
.map((_, item) => {
item = $(item);
return {
title: item.find('h4 a').text(),
link: item.find('h4 a').attr('href'),
};
})
.get();

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);

content('.DRE-subject-wrapper').remove();

item.author = content('.editor').text().replace('编辑:', '');
item.description = content('.body').first().html();
item.pubDate = timezone(parseDate(content('.userCreateTime').text()), 8);

return item;
})
)
);

ctx.state.data = {
title: 'Mtime时光网 - 资讯',
link,
item: items,
};
};
13 changes: 13 additions & 0 deletions lib/v2/mtime/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'mtime.com': {
_name: '时光网',
'news': [
{
title: '资讯',
docs: 'https://docs.rsshub.app/multimedia.html#shi-guang-wang',
source: '/',
target: '/mtime/news',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/mtime/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/news', require('./news'));
};