feat: add 1X photos (#5616)

This commit is contained in:
Ethan Shen
2020-09-07 11:15:39 +01:00
committed by GitHub
parent c0dbd8063a
commit abbf0166f7
4 changed files with 103 additions and 0 deletions
+32
View File
@@ -4,6 +4,38 @@ pageClass: routes
# Picture
## 1X
### Photos
<RouteEn author="nczitzk" example="/1x/latest/all" path="/1x/:type?/:caty?" :paramsDesc="['sort type, `latest` by default, or `popular` or `curators-choice`', 'picture category, `all` by default, see below']">
| Picture Category | Code |
| -------------- | ------------- |
| All categories | all |
| Abstract | abstract |
| Action | action |
| Animals | animals |
| Architecture | architecture |
| Conceptual | conceptual |
| Creative edit | creative-edit |
| Documentary | documentary |
| Everyday | everyday |
| Fine Art Nude | fine-art-nude |
| Humour | humour |
| Landscape | landscape |
| Macro | macro |
| Mood | mood |
| Night | night |
| Performance | performance |
| Portrait | portrait |
| Still life | still-life |
| Street | street |
| Underwater | underwater |
| Wildlife | wildlife |
</RouteEn>
## Awesome Pigtails
### New
+32
View File
@@ -4,6 +4,38 @@ pageClass: routes
# 图片
## 1X
### Photos
<Route author="nczitzk" example="/1x/latest/all" path="/1x/:type?/:caty?" :paramsDesc="['排序类型,默认为 `latest`,亦可选 `popular` 或 `curators-choice`', '图片类别,默认为 `all`,见下表']">
| 图片类别 | 代码 |
| -------------- | ------------- |
| All categories | all |
| Abstract | abstract |
| Action | action |
| Animals | animals |
| Architecture | architecture |
| Conceptual | conceptual |
| Creative edit | creative-edit |
| Documentary | documentary |
| Everyday | everyday |
| Fine Art Nude | fine-art-nude |
| Humour | humour |
| Landscape | landscape |
| Macro | macro |
| Mood | mood |
| Night | night |
| Performance | performance |
| Portrait | portrait |
| Still life | still-life |
| Street | street |
| Underwater | underwater |
| Wildlife | wildlife |
</Route>
## Awesome Pigtails
### 最新图片
+3
View File
@@ -3188,4 +3188,7 @@ router.get('/chuhaibiji', require('./routes/chuhaibiji/index'));
// 建宁闲谈
router.get('/blogs/jianning', require('./routes/blogs/jianning'));
// 1X
router.get('/1x/:type?/:caty?', require('./routes/1x/index'));
module.exports = router;
+36
View File
@@ -0,0 +1,36 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
ctx.params.type = ctx.params.type || 'latest';
ctx.params.caty = ctx.params.caty || 'all';
const rootUrl = `https://1x.com`;
const currentUrl = `${rootUrl}/photos/${ctx.params.type}/${ctx.params.caty}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('#photos_target')
.find('td a img')
.slice(0, 30)
.map((_, item) => {
item = $(item);
return {
title: item.attr('title'),
link: `${rootUrl}/${item.parent().attr('href')}`,
description: `<img src="${item.attr('src')}">`,
author: item.attr('title'),
};
})
.get();
ctx.state.data = {
title: `${$('title').text()} - ${ctx.params.caty}`,
link: currentUrl,
item: list,
};
};