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 东立出版 #7516

Merged
merged 4 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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/reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ count 的取值范围为 1-12,为防止请求次数过多,推荐设置为 5

<Route author="x1a0xv4n" example="/novel/d1bz/2/2608_6" path="/novel/d1bz/:category/:id" :paramsDesc="['小说分类,可在对应小说页 URL 中找到,例如`2`', '小说id,可在对应小说页 URL 中找到,例如`2608_6`']"/>

## 东立出版

### NEWS 资讯

<Route author="CokeMine" example="/tongli/news/6" path="/tongli/news/:type" :paramsDesc="['分类, 可以在“話題新聞”链接中找到']"/>

## 飞地

### 分类
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4081,4 +4081,7 @@ router.get('/bandcamp/tag/:tag?', require('./routes/bandcamp/tag'));
// Hugo 更新日志
router.get('/hugo/releases', require('./routes/hugo/releases'));

// 东立出版
router.get('/tongli/news/:type', require('./routes/tongli/news'));

module.exports = router;
45 changes: 45 additions & 0 deletions lib/routes/tongli/news.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const { type } = ctx.params;
const baseURL = 'https://www.tongli.com.tw/';
const link = `${baseURL}TNews_List.aspx?Type=${type}&Page=1`;
const res = await got.get(link);
const $ = cheerio.load(res.data);
const title = $('entry_title .n1').text();
const _list = $('.news_list ul li')
.map(function () {
let link = $(this).find('.title a').attr('href');
/^https?:\/\//.test(link) || (link = baseURL + link);
return {
title: $(this).find('.title a').text(),
link,
pubDate: new Date($(this).find('.date').text()),
};
})
.get();
const list = await Promise.all(
_list.map(async (item) => {
const { title, link, pubDate } = item;
const description = await ctx.cache.tryGet(link, async () => {
const res = await got.get(link);
const $ = cheerio.load(res.data);
if (/^https:\/\/tonglinv\.pixnet\.net/.test(link)) {
return $('.article-content-inner').html();
} else if (/^https?:\/\/blog\.xuite\.net\//.test(link)) {
return $('#content_all').html();
} else if (/TNews_View\.aspx/.test(link)) {
return $('#ContentPlaceHolder1_TNewsContent').html();
} else {
return '';
}
});
return Promise.resolve({ title, link, description, pubDate });
})
);
ctx.state.data = {
title,
link,
item: list,
};
};