diff --git a/docs/anime.md b/docs/anime.md index b8cdbfac19..1e694e07de 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -288,7 +288,7 @@ pageClass: routes ### 文章 - + ## 终点分享 diff --git a/lib/router.js b/lib/router.js index b75640c915..1b356b02e9 100644 --- a/lib/router.js +++ b/lib/router.js @@ -530,8 +530,9 @@ router.get('/weatheralarm', require('./routes/weatheralarm')); router.get('/gitlab/explore/:type', require('./routes/gitlab/explore')); // 忧郁的loli -router.get('/mygalgame', require('./routes/galgame/mmgal')); // 废弃 -router.get('/mmgal', require('./routes/galgame/mmgal')); +router.get('/mygalgame', require('./routes/galgame/hhgal')); // 废弃 +router.get('/mmgal', require('./routes/galgame/hhgal')); // 废弃 +router.get('/hhgal', require('./routes/galgame/hhgal')); // say花火 router.get('/sayhuahuo', require('./routes/galgame/sayhuahuo')); diff --git a/lib/routes/galgame/hhgal.js b/lib/routes/galgame/hhgal.js new file mode 100644 index 0000000000..ac8e0abd92 --- /dev/null +++ b/lib/routes/galgame/hhgal.js @@ -0,0 +1,37 @@ +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const browser = await require('@/utils/puppeteer')(); + const page = await browser.newPage(); + await page.goto('https://www.hhgal.com/'); + const htmlHandle = await page.$('html'); + const html = await page.evaluate((html) => html.innerHTML, htmlHandle); + browser.close(); + + const $ = cheerio.load(html); + const list = $('#article-list').find('.article'); + + ctx.state.data = { + title: $('title').text(), + link: 'https://www.hhgal.com/', + description: '忧郁的loli - Galgame资源发布站', + item: + list && + list + .slice(1) + .map((index, item) => { + item = $(item); + const time = `${item.find('.tag-article .label.label-zan').text()}`; + const math = /\d{4}-\d{2}-\d{2}/.exec(time); + const pubdate = new Date(math[0]); + + return { + title: item.find('h1').text(), + description: `${item.find('.info p').text()}`, + pubDate: pubdate, + link: item.find('h1 a').attr('href'), + }; + }) + .get(), + }; +}; diff --git a/lib/routes/galgame/mmgal.js b/lib/routes/galgame/mmgal.js deleted file mode 100644 index 1ea96d3981..0000000000 --- a/lib/routes/galgame/mmgal.js +++ /dev/null @@ -1,42 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const res = await got({ - method: 'get', - url: 'https://www.mmgal.com/', - header: { - Referer: 'https://www.mmgal.com/', - }, - }); - - const data = res.data; - - const $ = cheerio.load(data); - const list = $('#article-list').find('.article'); - - ctx.state.data = { - title: $('title').text(), - link: 'https://www.mmgal.com/', - description: '忧郁的loli - Galgame资源发布站', - item: - list && - list - .slice(1) - .map((index, item) => { - item = $(item); - const time = `${item.find('.month').text()}${item.find('.day').text()}日`; - const date = new Date(); - const math = /(\d+)月(\d+)日/.exec(time); - const pubdate = new Date(date.getFullYear(), parseInt(math[1]) - 1, math[2]); - - return { - title: item.find('h1').text(), - description: `${item.find('.info p').text()}`, - pubDate: pubdate > date ? new Date(date.getFullYear() - 1, parseInt(math[1]) - 1, math[2]).toUTCString() : pubdate.toUTCString(), - link: item.find('h1 a').attr('href'), - }; - }) - .get(), - }; -};