From 232ae144596b98d5fb0dc93ea5d4dce84eb59787 Mon Sep 17 00:00:00 2001
From: MisteryMonster <40703811+MisteryMonster@users.noreply.github.com>
Date: Tue, 28 Apr 2020 15:45:31 +0800
Subject: [PATCH] feat: Add method studios (#4570)
---
docs/design.md | 12 ++++++
docs/en/design.md | 12 ++++++
lib/router.js | 3 ++
lib/routes/method-studios/index.js | 60 ++++++++++++++++++++++++++++++
4 files changed, 87 insertions(+)
create mode 100755 lib/routes/method-studios/index.js
diff --git a/docs/design.md b/docs/design.md
index 99894fd54e..dbec28af1c 100755
--- a/docs/design.md
+++ b/docs/design.md
@@ -43,6 +43,18 @@ pageClass: routes
+## Method Studios
+
+### 菜单
+
+
+
+不支持`news`和`main`。
+
+默认为 'https://www.methodstudios.com/en/features' 下的栏目。
+
+
+
## UI 中国
### 推荐文章
diff --git a/docs/en/design.md b/docs/en/design.md
index 9ad5863176..1db94ff7b3 100755
--- a/docs/en/design.md
+++ b/docs/en/design.md
@@ -43,6 +43,18 @@ Some tags are rarely used: `Script`, `direction`, `production`, `design-concep
+## Method Studios
+
+### Menus
+
+
+
+Not support `main`, `news`.
+
+Default is under 'https://www.methodstudios.com/en/features'.
+
+
+
## Unit Image
### Films
diff --git a/lib/router.js b/lib/router.js
index f36683bbbb..d871eaff99 100755
--- a/lib/router.js
+++ b/lib/router.js
@@ -2574,6 +2574,9 @@ router.get('/zhuixinfan/list', require('./routes/zhuixinfan/list'));
// scoresaber
router.get('/scoresaber/user/:id', require('./routes/scoresaber/user'));
+// method-studios
+router.get('/method-studios/:menu?', require('./routes/method-studios/index'));
+
// blow-studio
router.get('/blow-studio', require('./routes/blow-studio/work'));
diff --git a/lib/routes/method-studios/index.js b/lib/routes/method-studios/index.js
new file mode 100755
index 0000000000..33d2e86b34
--- /dev/null
+++ b/lib/routes/method-studios/index.js
@@ -0,0 +1,60 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+
+module.exports = async (ctx) => {
+ const menu = ctx.params.menu || 'features';
+ const response = await got({
+ method: 'get',
+ url: `https://www.methodstudios.com/en/${menu}`,
+ });
+ const data = response.data;
+ const $ = cheerio.load(data); // 使用 cheerio 加载返回的 HTML
+ const list = $('div.grid>div.grid-item>div a').get().slice(0, 6);
+ const articledata = await Promise.all(
+ list.map(async (item) => {
+ const link = `https:${$(item)
+ .attr('href')
+ .replace(/https:/, '')}`;
+
+ const cache = await ctx.cache.get(link);
+ if (cache) {
+ return Promise.resolve(JSON.parse(cache));
+ }
+
+ const response2 = await got({
+ method: 'get',
+ url: link,
+ });
+
+ const articleHtml = response2.data;
+ const $2 = cheerio.load(articleHtml);
+
+ $2('div.carousel-text').remove();
+ $2('div.carousel-nav').remove();
+ $2('i').remove();
+ const content = $2('.content-placeholder')
+ .html()
+ .replace(/