From abbf0166f7c4f972a88ac3ebafe384622952e4c2 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Mon, 7 Sep 2020 18:15:39 +0800 Subject: [PATCH] feat: add 1X photos (#5616) --- docs/en/picture.md | 32 ++++++++++++++++++++++++++++++++ docs/picture.md | 32 ++++++++++++++++++++++++++++++++ lib/router.js | 3 +++ lib/routes/1x/index.js | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 lib/routes/1x/index.js diff --git a/docs/en/picture.md b/docs/en/picture.md index 89ab7cd6b..bca8033c0 100644 --- a/docs/en/picture.md +++ b/docs/en/picture.md @@ -4,6 +4,38 @@ pageClass: routes # Picture +## 1X + +### Photos + + + +| 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 | + + + ## Awesome Pigtails ### New diff --git a/docs/picture.md b/docs/picture.md index c474be23f..b0bf36851 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -4,6 +4,38 @@ pageClass: routes # 图片 +## 1X + +### Photos + + + +| 图片类别 | 代码 | +| -------------- | ------------- | +| 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 | + + + ## Awesome Pigtails ### 最新图片 diff --git a/lib/router.js b/lib/router.js index 292653419..6028e96b2 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/1x/index.js b/lib/routes/1x/index.js new file mode 100644 index 000000000..5e4fc0c2b --- /dev/null +++ b/lib/routes/1x/index.js @@ -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: ``, + author: item.attr('title'), + }; + }) + .get(); + + ctx.state.data = { + title: `${$('title').text()} - ${ctx.params.caty}`, + link: currentUrl, + item: list, + }; +};