feat(route): add 东立出版 (#7516)
Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
parent
472b2939ad
commit
9e5baaa7d4
|
|
@ -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="['分类, 可以在“話題新聞”链接中找到']"/>
|
||||
|
||||
## 飞地
|
||||
|
||||
### 分类
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue