From 6e09d50dfe5047fbcfbf6ecabe0adc607f651de8 Mon Sep 17 00:00:00 2001 From: Wenmoux Date: Sun, 14 Mar 2021 14:13:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E7=81=B5=E5=BC=82=E7=BD=91=20(#7083)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update multimedia.md * Update router.js * fix(route):修改原网页地址 * Update index.js * style: auto format * Create index.js * Update router.js * Update bbs.md * Update index.js * Update index.js * style: auto format * Update index.js * Update router.js * Update bbs.md * Update router.js Co-authored-by: GitHub Action Co-authored-by: NeverBehave --- docs/bbs.md | 16 ++++++++++ lib/router.js | 4 +++ lib/routes/lingyi/index.js | 64 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 lib/routes/lingyi/index.js 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, + }; +};