diff --git a/docs/bbs.md b/docs/bbs.md index 48a4ba692..64dffdbc0 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -729,3 +729,19 @@ pageClass: routes ### 滚动新闻 + +## 中国灵异网 + +### 分类 + + + +| 编辑推荐 | 奇闻异事 | 鬼话连篇 | +| -------- | ---------- | -------------- | +| tuijian | qiwenyishi | guihualianpian | + +| 灵异事件 | 灵异图片 | 民间奇谈 | +| ------------- | ------------ | ------------ | +| lingyishijain | lingyitupian | minjianqitan | + + diff --git a/lib/router.js b/lib/router.js index acc1379c3..a65a75524 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4027,9 +4027,13 @@ router.get('/gf-cn/news/:category?', require('./routes/gf-cn/news')); // Eagle router.get('/eagle/changelog/:language?', require('./routes/eagle/changelog')); +// 灵异网 +router.get('/lingyi/:category', require('./routes/lingyi/index')); + // 歪脑读 router.get('/wainao-reads/all-articles', require('./routes/wainao/index')); // react router.get('/react/react-native-weekly', require('./routes/react/react-native-weekly')); + module.exports = router; diff --git a/lib/routes/lingyi/index.js b/lib/routes/lingyi/index.js new file mode 100644 index 000000000..4b820e059 --- /dev/null +++ b/lib/routes/lingyi/index.js @@ -0,0 +1,64 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const categories = { + tuijian: '编辑推荐', + lingyishijian: '灵异事件', + guihualianpian: '鬼话连篇', + minjianqitan: '民间奇谈', + qiwenyishi: '奇闻异事', + lingyitupian: '灵异图片', + }; + const url = `http://www.lingyi.org/topics/${ctx.params.category}`; + const res = await got({ + method: 'get', + url, + }); + const $ = cheerio.load(res.data); + const resultItem = $('.post-list-item') + .map((index, li) => { + const elem = $(li); + return { + title: elem.find('h2').text(), + description: elem.find('.post-excerpt').text(), + link: elem.find('h2 a').attr('href'), + image: elem.find('.mobile-show > div > a > picture > img').attr('href'), + pubDate: elem.find('time').attr('datetime'), + author: elem.find('.post-list-meta-user>a>span').text(), + }; + }) + .get(); + + const out = await Promise.all( + resultItem.map(async (link) => { + const pageUrl = link.link; + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const response = await got({ + method: 'get', + url: pageUrl, + headers: { + Referer: url, + }, + }); + const $1 = cheerio.load(response.data); + const single = { + pubDate: link.pubDate, + link: link.link, + title: link.title, + description: $1('.entry-content').html(), + }; + ctx.cache.set(link.link, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `${categories[ctx.params.category]} - 中国灵异网`, + link: url, + item: out, + }; +};