diff --git a/docs/en/shopping.md b/docs/en/shopping.md index 7f992bc7e9..ff10fa365c 100644 --- a/docs/en/shopping.md +++ b/docs/en/shopping.md @@ -85,11 +85,11 @@ Parameter `time` only works when `mostwanted` is chosen as the category. ### UK - New Product Release - + ### UK - Offers - + ## LeBonCoin diff --git a/docs/shopping.md b/docs/shopping.md index 835dd403eb..11636b3168 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -95,6 +95,16 @@ pageClass: routes +## IKEA 宜家 + +### 英国 - 商品上新 + + + +### 英国 - 促销 + + + ## lativ ### 订阅价格 @@ -471,16 +481,6 @@ For instance, in -## 宜家 IKEA - -### 宜家 IKEA(英国)- 商品上新 - - - -### 宜家 IKEA(英国)- 促销 - - - ## 优衣库 ### Stylingbook diff --git a/lib/router.js b/lib/router.js index 224f12925e..48b57c8485 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2280,8 +2280,8 @@ router.get('/centbrowser/history', lazyloadRouteHandler('./routes/centbrowser/hi router.get('/755/user/:username', lazyloadRouteHandler('./routes/755/user')); // IKEA -router.get('/ikea/uk/new', lazyloadRouteHandler('./routes/ikea/uk/new')); -router.get('/ikea/uk/offer', lazyloadRouteHandler('./routes/ikea/uk/offer')); +// router.get('/ikea/uk/new', lazyloadRouteHandler('./routes/ikea/uk/new')); +// router.get('/ikea/uk/offer', lazyloadRouteHandler('./routes/ikea/uk/offer')); // Mastodon router.get('/mastodon/timeline/:site/:only_media?', lazyloadRouteHandler('./routes/mastodon/timeline_local')); diff --git a/lib/routes/ikea/uk/new.js b/lib/routes/ikea/uk/new.js deleted file mode 100644 index 4b34579d20..0000000000 --- a/lib/routes/ikea/uk/new.js +++ /dev/null @@ -1,20 +0,0 @@ -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const link = 'https://www.ikea.com/gb/en/news/product-news-gallery/'; - - const count = (await got.get('https://sik.search.blue.cdtapps.com/gb/en/product-list-page?category=products&f-toggles2=new_product')).data.productListPage.productCount; - - const products = (await got.get(`http://sik.search.blue.cdtapps.com/gb/en/product-list-page/more-products?category=products&start=1&end=${count}`)).data.moreProducts.productWindow; - - ctx.state.data = { - title: 'IKEA UK - New Products', - link, - description: 'New products released by IKEA UK.', - item: products.map((p) => ({ - title: `${p.name} ${p.typeName} ${p.itemMeasureReferenceText}`, - description: ``, - link: p.pipUrl, - })), - }; -}; diff --git a/lib/routes/ikea/uk/offer.js b/lib/routes/ikea/uk/offer.js deleted file mode 100644 index f8e38c67af..0000000000 --- a/lib/routes/ikea/uk/offer.js +++ /dev/null @@ -1,64 +0,0 @@ -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 = $('.range-revamp-product-compact').get(); - - if (products.length > 0) { - for (const p of products) { - const price = $(p).find('.range-revamp-compact-price-package__price-wrapper').text(); - - if (!price) { - continue; - } - - let title = $(p).find('.range-revamp-header-section__title--small').text() + ' '; - - title += $(p).find('.range-revamp-header-section__description-text').text().trim() + ' '; - - const previous = $(p).find('.range-revamp-compact-price-package__previous-price-text').next('span').text(); - - title += `[${previous} ▶️ ${price}]`; - - const link = $(p).find('.range-revamp-product-compact__bottom-wrapper > a').attr('href'); - - items.push({ - title, - description: ``, - 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, - }; -}; diff --git a/lib/v2/ikea/gb/new.js b/lib/v2/ikea/gb/new.js new file mode 100644 index 0000000000..90cb78b3e1 --- /dev/null +++ b/lib/v2/ikea/gb/new.js @@ -0,0 +1,54 @@ +const got = require('@/utils/got'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const link = 'https://www.ikea.com/gb/en/new/new-products/'; + + const { + data: { specialPage }, + } = await got('https://sik.search.blue.cdtapps.com/gb/en/special', { + searchParams: { + special: 'new_product', + // size: 24, + // 'subcategories-style': 'tree-navigation', + // c: 'lf', + // v: 20220826, + // sort: 'RELEVANCE', + }, + }); + + const { + data: { + moreProducts: { productWindow }, + }, + } = await got('https://sik.search.blue.cdtapps.com/gb/en/special/more-products', { + searchParams: { + special: 'new_product', + start: 24, + end: specialPage.productCount, + // 'subcategories-style': 'tree-navigation', + // c: 'lf', + // v: 20220826, + // sort: 'RELEVANCE', + }, + }); + + const products = [...specialPage.productWindow, ...productWindow]; + + const items = products.map((p) => ({ + title: `${p.name} ${p.typeName}, ${p.itemMeasureReferenceText}`, + description: art(path.join(__dirname, '../templates/new.art'), { + p, + }), + link: p.pipUrl, + category: p.categoryPath.map((c) => c.name), + })); + + ctx.state.data = { + title: 'New Products - Browse All New Furniture & Home Decor - IKEA', + link, + description: 'New products released by IKEA UK.', + item: items, + }; +}; diff --git a/lib/v2/ikea/gb/offer.js b/lib/v2/ikea/gb/offer.js new file mode 100644 index 0000000000..2d71ae9d82 --- /dev/null +++ b/lib/v2/ikea/gb/offer.js @@ -0,0 +1,69 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const link = 'https://www.ikea.com/gb/en/offers/'; + const response = await got(link); + + const $ = cheerio.load(response.data); + const carousel = $('.pub__carousel-slide') + .toArray() + .map((e) => { + e = $(e); + const title = e.find('h3'); + const img = e.find('.pub__image').each((_, e) => { + e.attribs.src = e.attribs.src.split('?')[0]; + delete e.attribs.srcset; + }); + const link = new URL(e.find('pub-hide-empty-link a').attr('href')); + const { searchParams } = link; + searchParams.delete('itm_content'); + searchParams.delete('itm_element'); + searchParams.delete('itm_campaign'); + return { + title: title.text(), + description: art(path.join(__dirname, '../templates/offer.art'), { + img: img.parent().html(), + desc: title.next().parent().html(), + }), + link: link.href, + guid: `${link.href}#${title.text()}`, + }; + }); + + const banner = $('div[data-pub-type="banner"]') + .toArray() + .map((e) => { + e = $(e); + const title = e.find('h2'); + const next = title.next(); + const img = e.find('.pub__image').each((_, e) => { + e.attribs.src = e.attribs.src.split('?')[0]; + delete e.attribs.srcset; + }); + + const link = new URL(next.find('a').attr('href')); + const { searchParams } = link; + searchParams.delete('itm_content'); + searchParams.delete('itm_element'); + searchParams.delete('itm_campaign'); + return { + title: title.text(), + description: art(path.join(__dirname, '../templates/offer.art'), { + img: img.parent().html(), + desc: title.parent().html(), + }), + link: link.href, + guid: `${link.href}#${title.text()}`, + }; + }); + + ctx.state.data = { + title: 'IKEA UK - Offers', + link, + description: 'Offers by IKEA UK.', + item: [...carousel, ...banner], + }; +}; diff --git a/lib/v2/ikea/maintainer.js b/lib/v2/ikea/maintainer.js new file mode 100644 index 0000000000..14b504aa31 --- /dev/null +++ b/lib/v2/ikea/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/gb/new': ['HenryQW'], + '/gb/offer': ['HenryQW'], +}; diff --git a/lib/v2/ikea/radar.js b/lib/v2/ikea/radar.js new file mode 100644 index 0000000000..bfeca152ec --- /dev/null +++ b/lib/v2/ikea/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'ikea.com': { + _name: 'IKEA 宜家', + '.': [ + { + title: '英国 - 商品上新', + docs: 'https://docs.rsshub.app/shopping.html#ikea-yi-jia', + source: ['/gb/en/new/new-products/', '/'], + target: '/ikea/gb/new', + }, + { + title: '英国 - 促销', + docs: 'https://docs.rsshub.app/shopping.html#ikea-yi-jia', + source: ['/gb/en/offers', '/'], + target: '/ikea/gb/offer', + }, + ], + }, +}; diff --git a/lib/v2/ikea/router.js b/lib/v2/ikea/router.js new file mode 100644 index 0000000000..13210c57f8 --- /dev/null +++ b/lib/v2/ikea/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/gb/new', require('./gb/new')); + router.get('/gb/offer', require('./gb/offer')); +}; diff --git a/lib/v2/ikea/templates/new.art b/lib/v2/ikea/templates/new.art new file mode 100644 index 0000000000..114f52d7cc --- /dev/null +++ b/lib/v2/ikea/templates/new.art @@ -0,0 +1,7 @@ +{{ p.mainImageAlt }} +
+{{ p.name }} +
+{{ p.typeName }}, {{ p.itemMeasureReferenceText }} +
+{{ p.salesPrice.current.prefix }} {{ p.salesPrice.current.wholeNumber }} diff --git a/lib/v2/ikea/templates/offer.art b/lib/v2/ikea/templates/offer.art new file mode 100644 index 0000000000..ce79ac73ad --- /dev/null +++ b/lib/v2/ikea/templates/offer.art @@ -0,0 +1,3 @@ +{{@ img }} +
+{{@ desc }}