diff --git a/docs/en/shopping.md b/docs/en/shopping.md index 653d1f457..390ce0e59 100644 --- a/docs/en/shopping.md +++ b/docs/en/shopping.md @@ -62,6 +62,16 @@ Parameter `time` only works when `mostwanted` is chosen as the category. +## Gumroad + +### Products + + + +`https://afkmaster.gumroad.com/l/Eve10` -> `/gumroad/afkmaster/Eve10` + + + ## hotukdeals ### thread diff --git a/docs/shopping.md b/docs/shopping.md index 52887e7a4..4e4a20b70 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -75,6 +75,16 @@ pageClass: routes +## Gumroad + +### 商品 + + + +如:`https://afkmaster.gumroad.com/l/Eve10` 则为 `/gumroad/afkmaster/Eve10` + + + ## hotukdeals ### thread diff --git a/lib/v2/gumroad/index.js b/lib/v2/gumroad/index.js new file mode 100644 index 000000000..b2d03c24c --- /dev/null +++ b/lib/v2/gumroad/index.js @@ -0,0 +1,35 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const username = ctx.params.username; + const products = ctx.params.products; + const url = `https://${username}.gumroad.com/l/${products}`; + + const response = await got(url); + const $ = cheerio.load(response.data); + const title = $('section.product-content.product-content__row > header > h1').text(); + const userFullName = $('section.product-content.product-content__row > section.details > a').text(); + + const item = [ + { + title, + link: url, + description: art(path.join(__dirname, 'templates/products.art'), { + img: response.data.match(/data-preview-url="(.*?)"/)[1], + productsName: title, + price: $('div.price').text(), + desc: $('section.product-content.product-content__row > section:nth-child(3) > div').html(), + stack: $('div.product-info').find('ul.stack').html(), + }), + }, + ]; + + ctx.state.data = { + link: url, + title: `Gumroad - ${userFullName}/${title}`, + item, + }; +}; diff --git a/lib/v2/gumroad/maintainer.js b/lib/v2/gumroad/maintainer.js new file mode 100644 index 000000000..12dc5e9b4 --- /dev/null +++ b/lib/v2/gumroad/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:username/:products': ['Fatpandac'], +}; diff --git a/lib/v2/gumroad/radar.js b/lib/v2/gumroad/radar.js new file mode 100644 index 000000000..d2672a01f --- /dev/null +++ b/lib/v2/gumroad/radar.js @@ -0,0 +1,17 @@ +module.exports = { + 'gumroad.com': { + _name: 'Gumroad', + '.': [ + { + title: '产品', + docs: 'https://docs.rsshub.app/shopping.html#gumroad', + source: ['/l/:products'], + target: (params, url) => { + const username = new URL(url).host.split('.')[0]; + + return `/gumroad/${username}/${params.products}`; + }, + }, + ], + }, +}; diff --git a/lib/v2/gumroad/router.js b/lib/v2/gumroad/router.js new file mode 100644 index 000000000..680746caa --- /dev/null +++ b/lib/v2/gumroad/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:username/:products', require('./index')); +}; diff --git a/lib/v2/gumroad/templates/products.art b/lib/v2/gumroad/templates/products.art new file mode 100644 index 000000000..cece45638 --- /dev/null +++ b/lib/v2/gumroad/templates/products.art @@ -0,0 +1,7 @@ + +

{{productsName}}

+

{{price}}

+{{@ desc}} +
+{{@ stack}} +