feat: Add 绝对领域 (#4338)

This commit is contained in:
Kherrisan
2020-04-02 21:11:53 +08:00
committed by GitHub
parent 483d6596a8
commit 345547b642
3 changed files with 62 additions and 0 deletions

View File

@@ -179,6 +179,14 @@ pageClass: routes
| ------ | ---------- |
| ooxx | top-ooxx |
## 绝对领域
<Route author="Kherrisan" example="/jdlingyu/tuji" path="/jdlingyu/:type" :paramsDesc="['分区名']"/>
| 图集 | 文章 |
| ---- | ---- |
| tuji | as |
## 妹子图
### 首页(最新)

View File

@@ -2496,6 +2496,9 @@ router.get('/checkra1n/releases', require('./routes/checkra1n/releases'));
// 四川省科学技术厅
router.get('/sckjt/news/:type?', require('./routes/sckjt/news'));
// 绝对领域
router.get('/jdlingyu/:type', require('./routes/jdlingyu/index'));
// Hi, DIYgod
router.get('/blogs/diygod/animal-crossing', require('./routes/blogs/diygod/animal-crossing'));
router.get('/blogs/diygod/gk', require('./routes/blogs/diygod/gk'));

View File

@@ -0,0 +1,51 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const baseUrl = 'https://www.jdlingyu.mobi/';
const viewProps = {
tuji: '图集',
as: '文章',
};
module.exports = async (ctx) => {
const type = ctx.params.type || 'tuji';
const url = baseUrl + type;
const response = await got({
method: 'get',
url: url,
});
const $ = cheerio.load(response.data);
const items = await Promise.all(
$('#main > div.grid-bor > div')
.get()
.map(async (div) => {
const a = $(div).find('.entry-title > a');
const link = a.attr('href');
const description = await ctx.cache.tryGet(link, async () => {
const response = await got.get(link);
const $ = cheerio.load(response.data);
return $('#content-innerText > p').html();
});
return Promise.resolve({
title: a.text(),
description: description,
author: $(div)
.find('.post-header .users')
.text(),
link: link,
pubDate: new Date(
$(div)
.find('.post-header time')
.attr('datetime')
).toUTCString(),
});
})
);
ctx.state.data = {
title: `${viewProps[type]} - 绝对领域`,
link: url,
description: `${viewProps[type]} - 绝对领域`,
item: items,
};
};