From 1649aee4b21b7932597ef244acaaf75f23acc2e7 Mon Sep 17 00:00:00 2001
From: Fatpandac <1779196284@qq.com>
Date: Sat, 21 May 2022 22:48:23 +0800
Subject: [PATCH] feat(route): add Gumroad (#9795)
* feat(route): add Gumroad
* Update lib/v2/gumroad/maintainer.js
---
docs/en/shopping.md | 10 ++++++++
docs/shopping.md | 10 ++++++++
lib/v2/gumroad/index.js | 35 +++++++++++++++++++++++++++
lib/v2/gumroad/maintainer.js | 3 +++
lib/v2/gumroad/radar.js | 17 +++++++++++++
lib/v2/gumroad/router.js | 3 +++
lib/v2/gumroad/templates/products.art | 7 ++++++
7 files changed, 85 insertions(+)
create mode 100644 lib/v2/gumroad/index.js
create mode 100644 lib/v2/gumroad/maintainer.js
create mode 100644 lib/v2/gumroad/radar.js
create mode 100644 lib/v2/gumroad/router.js
create mode 100644 lib/v2/gumroad/templates/products.art
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}}
+