feat: add IKEA UK routes (#3578)

This commit is contained in:
Henry Wang
2019-12-12 11:46:45 +08:00
committed by DIYgod
parent ce5601c30c
commit 384eb9e2c6
6 changed files with 163 additions and 3 deletions
+2 -2
View File
@@ -71,13 +71,13 @@ EZTV provides an official RSS feed of all torrents: https://eztv.ag/ezrss.xml
### Remote.work Job Information
<Route author="luyuhuang" example="/remote-work/all" path="/remote-work/:caty?" :paramsDesc="['Job category, default to all']" radar="1">
<RouteEn author="luyuhuang" example="/remote-work/all" path="/remote-work/:caty?" :paramsDesc="['Job category, default to all']" radar="1">
| All Jobs | Development | Design | Operation | Product | Other | Marketing | Sales |
| :------: | :---------: | :----: | :-------: | :-----: | :---: | :-------: | :---: |
| all | development | design | operation | product | other | marketing | sales |
</Route>
</RouteEn>
## TransferWise
+11 -1
View File
@@ -8,7 +8,17 @@ pageClass: routes
### News
<Route author="luyuhuang" example="/alter-cn/news" path="/alter-cn/news"/>
<RouteEn author="luyuhuang" example="/alter-cn/news" path="/alter-cn/news"/>
## IKEA
### UK - New Product Release
<RouteEn author="HenryQW" example="/ikea/uk/new" path="/ikea/uk/new"/>
### UK - Offers
<RouteEn author="HenryQW" example="/ikea/uk/offer" path="/ikea/uk/offer"/>
## LeBonCoin
+10
View File
@@ -191,6 +191,16 @@ pageClass: routes
<Route author="xyqfer" example="/mi/youpin/new" path="/mi/youpin/new"/>
## 宜家 IKEA
### 宜家 IKEA(英国)- 商品上新
<RouteEn author="HenryQW" example="/ikea/uk/new" path="/ikea/uk/new"/>
### 宜家 IKEA(英国)- 促销
<RouteEn author="HenryQW" example="/ikea/uk/offer" path="/ikea/uk/offer"/>
## 有赞
### 商品上新
+4
View File
@@ -2027,6 +2027,10 @@ router.get('/centbrowser/history', require('./routes/centbrowser/history'));
// 755
router.get('/755/user/:username', require('./routes/755/user'));
// IKEA
router.get('/ikea/uk/new', require('./routes/ikea/uk/new'));
router.get('/ikea/uk/offer', require('./routes/ikea/uk/offer'));
// Mastodon
router.get('/mastodon/timeline/:site/:only_media?', require('./routes/mastodon/timeline'));
+65
View File
@@ -0,0 +1,65 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const link = 'https://www.ikea.com/gb/en/news/product-news-gallery/';
const response = await got.get(link);
const $ = cheerio.load(response.data);
const list = $('.card__link')
.get()
.map((e) => $(e).attr('href'));
const items = [];
await Promise.all(
list.map(async (sectionUrl) => {
const response = await got.get(sectionUrl);
const $ = cheerio.load(response.data);
const products = $('.product-compact').get();
if (products.length > 0) {
for (const p of products) {
let title =
$(p)
.find('.product-compact__name')
.text() + ' ';
title +=
$(p)
.find('.product-compact__type')
.text()
.trim() + ' ';
title += `[${$(p)
.find('.product-compact__price')
.text()
.trim()}]`;
const link = $(p)
.find('.product-compact__spacer > a')
.attr('href');
items.push({
title,
description: `<img src='${$(p)
.find('.range-image-claim-height > img')
.attr('src')}'>`,
link,
});
}
}
return Promise.resolve();
})
);
ctx.state.data = {
title: 'IKEA UK - New Products',
link,
description: 'New products released by IKEA UK.',
item: items,
};
};
+71
View File
@@ -0,0 +1,71 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const link = 'https://www.ikea.com/gb/en/ikea-family/discounts/';
const items = [];
const loadProductsOnPage = (data) => {
const $ = cheerio.load(data);
const products = $('.product-compact').get();
if (products.length > 0) {
for (const p of products) {
let title =
$(p)
.find('.product-compact__name')
.text() + ' ';
title +=
$(p)
.find('.product-compact__type')
.text()
.trim() + ' ';
title += `[${$(p)
.find('.product-compact__comparable-price-element')
.text()} ▶️ ${$(p)
.find('.product-compact__price.product-compact__price--family')
.text()}]`;
const link = $(p)
.find('.product-compact__spacer > a')
.attr('href');
items.push({
title,
description: `<img src='${$(p)
.find('.range-image-claim-height > img')
.attr('src')}'>`,
link,
});
}
}
};
const response = await got.get(link);
loadProductsOnPage(response.data);
const $ = cheerio.load(response.data);
const list = $('.text.component a')
.get()
.map((e) => $(e).attr('href'));
if (list.length > 0) {
await Promise.all(
list.map(async (url) => {
const response = await got.get(url);
loadProductsOnPage(response.data);
})
);
}
ctx.state.data = {
title: 'IKEA UK - Offers',
link,
description: 'Offers by IKEA UK.',
item: items,
};
};