Skip to content

Commit

Permalink
feat(route): add 东立出版 (DIYgod#7516)
Browse files Browse the repository at this point in the history
Co-authored-by: NeverBehave <[email protected]>
  • Loading branch information
cokemine and NeverBehave authored May 25, 2021
1 parent 472b293 commit 9e5baaa
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
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 @@ -4089,6 +4089,9 @@ 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'));

// OR
router.get('/or/:id?', require('./routes/or'));

Expand Down
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,
};
};

0 comments on commit 9e5baaa

Please sign in to comment.