From e749584ece96d46270f9c0ab32cb15942bcff04c Mon Sep 17 00:00:00 2001 From: miles Date: Sun, 8 Jan 2023 01:25:20 +0800 Subject: [PATCH] feat(route): add Shopping Design (#11575) --- docs/design.md | 6 ++++ lib/v2/shoppingdesign/maintainer.js | 3 ++ lib/v2/shoppingdesign/posts.js | 43 +++++++++++++++++++++++++++++ lib/v2/shoppingdesign/radar.js | 13 +++++++++ lib/v2/shoppingdesign/router.js | 3 ++ 5 files changed, 68 insertions(+) create mode 100644 lib/v2/shoppingdesign/maintainer.js create mode 100644 lib/v2/shoppingdesign/posts.js create mode 100644 lib/v2/shoppingdesign/radar.js create mode 100644 lib/v2/shoppingdesign/router.js diff --git a/docs/design.md b/docs/design.md index 61195acd61..6ea2f1508b 100644 --- a/docs/design.md +++ b/docs/design.md @@ -178,6 +178,12 @@ Behance 用户主页 URL 获取用户名,如 +## Shopping Design + +### 文章列表 + + + ## UI 中国 ### 推荐文章 diff --git a/lib/v2/shoppingdesign/maintainer.js b/lib/v2/shoppingdesign/maintainer.js new file mode 100644 index 0000000000..e22ac4e64e --- /dev/null +++ b/lib/v2/shoppingdesign/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/posts': ['miles170'], +}; diff --git a/lib/v2/shoppingdesign/posts.js b/lib/v2/shoppingdesign/posts.js new file mode 100644 index 0000000000..c1a691624a --- /dev/null +++ b/lib/v2/shoppingdesign/posts.js @@ -0,0 +1,43 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const asyncPool = require('tiny-async-pool'); + +module.exports = async (ctx) => { + // sn_f parameter is required to prevent redirection + const currentUrl = 'https://www.shoppingdesign.com.tw/post?sn_f=1'; + const response = await got(currentUrl); + const $ = cheerio.load(response.data); + const items = []; + // maximum parallel requests on the target website are limited to 11. + for await (const data of asyncPool(10, $('article-item'), (item) => { + item = $(item); + const link = item.attr('url'); + return ctx.cache.tryGet(link, async () => { + const response = await got(`${link}?sn_f=1`); + const $ = cheerio.load(response.data); + const article = $('.left article .htmlview'); + article.find('d-image').each(function () { + $(this).replaceWith(``); + }); + + return { + title: $('.left article .top_info h1').text(), + author: $('meta[name="my:author"]').attr('content'), + description: article.html(), + category: $('meta[name="my:category"]').attr('content'), + pubDate: parseDate($('meta[name="my:publish"]').attr('content')), + link, + }; + }); + })) { + items.push(data); + } + + ctx.state.data = { + title: $('meta[property="og:title"]').attr('content'), + link: currentUrl, + description: $('meta[property="og:description"]').attr('content'), + item: items, + }; +}; diff --git a/lib/v2/shoppingdesign/radar.js b/lib/v2/shoppingdesign/radar.js new file mode 100644 index 0000000000..e750f45820 --- /dev/null +++ b/lib/v2/shoppingdesign/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'shoppingdesign.com.tw': { + _name: 'Shopping Design', + www: [ + { + title: '文章列表', + docs: 'https://docs.rsshub.app/design.html#shopping-design', + source: '/post', + target: '/shoppingdesign/posts', + }, + ], + }, +}; diff --git a/lib/v2/shoppingdesign/router.js b/lib/v2/shoppingdesign/router.js new file mode 100644 index 0000000000..a6c12593a2 --- /dev/null +++ b/lib/v2/shoppingdesign/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/posts', require('./posts')); +};