Skip to content

Commit

Permalink
Bangumi话题 (#884)
Browse files Browse the repository at this point in the history
* 大连大学

* Format code

* Format code

* Add DLU router

* Bangumi topic
  • Loading branch information
SettingDust authored and DIYgod committed Oct 14, 2018
1 parent 0cf6dbf commit 4ba7c67
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,8 @@ GitHub 官方也提供了一些 RSS:

<route name="小组话题的新回复" author="ylc395" example="/bangumi/topic/24657" path="/bangumi/topic/:id" :paramsDesc="['话题 id, 在话题页面地址栏查看']"/>

<route name="小组话题" author="SettingDust" example="/bangumi/group/boring" path="/bangumi/group/:id" :paramsDesc="['小组 id, 在小组页面地址栏查看']"/>

### 米哈游

<route name="崩坏 2-游戏公告" author="deepred5" example="/mihoyo/bh2/gach" path="/mihoyo/bh2/:type" :paramsDesc="['公告种类']">
Expand Down
1 change: 1 addition & 0 deletions router.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ router.get('/bangumi/calendar/today', require('./routes/bangumi/calendar/today')
router.get('/bangumi/subject/:id/:type', require('./routes/bangumi/subject'));
router.get('/bangumi/person/:id', require('./routes/bangumi/person'));
router.get('/bangumi/topic/:id', require('./routes/bangumi/group/reply.js'));
router.get('/bangumi/group/:id', require('./routes/bangumi/group/topic.js'));

// 微博
router.get('/weibo/user/:uid', require('./routes/weibo/user'));
Expand Down
27 changes: 27 additions & 0 deletions routes/bangumi/group/topic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const axios = require('../../../utils/axios');
const cheerio = require('cheerio');
const DateTime = require('luxon').DateTime;
const resolve_url = require('url').resolve;

const base_url = 'https://bgm.tv/';

module.exports = async (ctx) => {
const groupID = ctx.params.id;
const link = 'https://bgm.tv/group/' + groupID + '/forum';
const html = (await axios.get(link)).data;
const $ = cheerio.load(html);
const title = 'Bangumi - ' + $('.SecondaryNavTitle').text();

ctx.state.data = {
title: `${title}`,
link: link,
item: $('.topic_list .topic')
.map((_, elem) => ({
link: resolve_url(base_url, $('.subject a', elem).attr('href')),
title: $('.subject a', elem).attr('title'),
pubDate: DateTime.fromFormat($('.time', elem).text(), 'yyyy-L-dd'),
description: 'Author: ' + $('.author a', elem).text() + '<br>' + 'Replay: ' + $('.posts', elem).text(),
}))
.get(),
};
};

0 comments on commit 4ba7c67

Please sign in to comment.