diff --git a/docs/reading.md b/docs/reading.md index e6d649c6b..663b32ec3 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -182,6 +182,12 @@ count 的取值范围为 1-12,为防止请求次数过多,推荐设置为 5 +## 东立出版 + +### NEWS 资讯 + + + ## 飞地 ### 分类 diff --git a/lib/router.js b/lib/router.js index dee0cf35a..6f11e24cd 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/tongli/news.js b/lib/routes/tongli/news.js new file mode 100644 index 000000000..a3d8ad2f8 --- /dev/null +++ b/lib/routes/tongli/news.js @@ -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, + }; +};