fix: mmgal move to hhgal (#4312)

This commit is contained in:
kotoyuuko
2020-04-02 20:40:29 +08:00
committed by GitHub
parent 0c01cba1c9
commit 4580275abf
4 changed files with 41 additions and 45 deletions

View File

@@ -288,7 +288,7 @@ pageClass: routes
### 文章
<Route author="DIYgod" example="/mmgal" path="/mmgal"/>
<Route author="DIYgod kotoyuuko" example="/hhgal" path="/hhgal"/>
## 终点分享

View File

@@ -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'));

View File

@@ -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(),
};
};

View File

@@ -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(),
};
};