Skip to content

Commit

Permalink
feat(route): add Quicker动作更新 (#9357)
Browse files Browse the repository at this point in the history
* feat(route): add Quicker动作更新

* fix typo

* delete outdated routes

* fix: add h2 header

* fix: invalid pubDate
  • Loading branch information
Ethan Shen authored Mar 31, 2022
1 parent ede7352 commit d68e5a8
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 118 deletions.
10 changes: 0 additions & 10 deletions docs/bbs.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,6 @@ pageClass: routes

<Route author="xyqfer" example="/nga/post/18449558" path="/nga/post/:tid" :paramsDesc="['帖子 id, 可在帖子 URL 找到']" radar="1" rssbud="1"/>

## Quicker

### 讨论区

<Route author="Cesaryuan" example="/quicker/qa" path="/quicker/qa"/>

### 用户动作更新

<Route author="Cesaryuan" example="/quicker/user/action/18359/Cesaryuan" path="/quicker/user/action/:uid/:person" :paramsDesc="['用户ID,可在用户主页链接里找到', '用户昵称,可在用户主页链接里找到']" />

## RF 技术社区

### 文章
Expand Down
2 changes: 1 addition & 1 deletion docs/program-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ pageClass: routes

### 版本更新

<Route author="Cesaryuan" example="/quicker/update" path="/quicker/update"/>
<Route author="Cesaryuan nczitzk" example="/quicker/versions" path="/quicker/versions"/>

## RescueTime

Expand Down
52 changes: 52 additions & 0 deletions docs/programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,58 @@ GitHub 官方也提供了一些 RSS:

<Route author="hellodword" example="/project-zero-issues" path="/project-zero-issues" />

## Quicker

### 动作分享

<Route author="nczitzk" example="/quicker/share/Recent" path="/quicker/share/:category?" :paramsDesc="['分类,见下表,默认为动作库最新更新']">

| 动作库最新更新 | 动作库最多赞 | 动作库新动作 | 动作库最近赞 |
| ------- | ----------- | ---------- | ----------- |
| Recent | Recommended | NewActions | RecentLiked |

| 子程序 | 扩展热键 | 文本指令 |
| ----------- | --------- | ------------ |
| SubPrograms | PowerKeys | TextCommands |

</Route>

### 讨论区

<Route author="Cesaryuan nczitzk" example="/quicker/qa" path="/quicker/qa/:category?/:state?" :paramsDesc="['分类,见下表,默认为全部', '状态,见下表,默认为全部']">

分类

| 使用问题 | 动作开发 | BUG 反馈 | 功能建议 |
| ---- | ---- | ------ | ---- |
| 1 | 9 | 3 | 4 |

| 动作需求 | 经验创意 | 动作推荐 | 信息发布 |
| ---- | ---- | ---- | ---- |
| 6 | 2 | 7 | 5 |

| 随便聊聊 | 异常报告 | 全部 |
| ---- | ---- | --- |
| 8 | 10 | all |

状态

| 全部 | 精华 | 已归档 |
| -- | ------ | ------- |
| | digest | achived |

</Route>

### 用户更新

<Route author="Cesaryuan nczitzk" example="/quicker/user/Actions/3-CL" path="/quicker/user/:category/:id" :paramsDesc="['分类,见下表', '用户 id,可在对应用户页 URL 中找到']">

| 动作 | 子程序 | 动作单 |
| ------- | ----------- | ----------- |
| Actions | SubPrograms | ActionLists |

</Route>

## react

### react-native
Expand Down
8 changes: 4 additions & 4 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const lazyloadRouteHandler = (routeHandlerPath) => (ctx) => {
router.get('/1draw', lazyloadRouteHandler('./routes/1draw/index'));

// quicker
router.get('/quicker/qa', lazyloadRouteHandler('./routes/quicker/qa.js'));
router.get('/quicker/update', lazyloadRouteHandler('./routes/quicker/update.js'));
router.get('/quicker/user/action/:uid/:person', lazyloadRouteHandler('./routes/quicker/person.js'));
router.get('/quicker/user/:uid/:person', lazyloadRouteHandler('./routes/quicker/person.js'));
// router.get('/quicker/qa', lazyloadRouteHandler('./routes/quicker/qa.js'));
// router.get('/quicker/update', lazyloadRouteHandler('./routes/quicker/update.js'));
// router.get('/quicker/user/action/:uid/:person', lazyloadRouteHandler('./routes/quicker/person.js'));
// router.get('/quicker/user/:uid/:person', lazyloadRouteHandler('./routes/quicker/person.js'));

// Benedict Evans
router.get('/benedictevans', lazyloadRouteHandler('./routes/benedictevans/recent.js'));
Expand Down
32 changes: 0 additions & 32 deletions lib/routes/quicker/person.js

This file was deleted.

41 changes: 0 additions & 41 deletions lib/routes/quicker/qa.js

This file was deleted.

30 changes: 0 additions & 30 deletions lib/routes/quicker/update.js

This file was deleted.

7 changes: 7 additions & 0 deletions lib/v2/quicker/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
'/qa/:category?/:state?': ['Cesaryuan', 'nczitzk'],
'/share/:category?': ['nczitzk'],
'/update': ['Cesaryuan', 'nczitzk'],
'/user/:category/:id': ['Cesaryuan', 'nczitzk'],
'/versions': ['Cesaryuan', 'nczitzk'],
};
65 changes: 65 additions & 0 deletions lib/v2/quicker/qa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate, parseRelativeDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const category = ctx.params.category ?? 'all';
const state = ctx.params.state ?? '';

const rootUrl = 'https://getquicker.net';
const currentUrl = `${rootUrl}/QA${category !== 'all' ? `?category=${category}` : ''}${state ? `?state=${state}` : ''}`;

const response = await got({
method: 'get',
url: currentUrl,
});

const $ = cheerio.load(response.data);

let items = $('a.question-title')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 25)
.toArray()
.map((item) => {
item = $(item);

return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
};
});

items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});

const content = cheerio.load(detailResponse.data);

content('div[data-note="最后更新人信息"]').remove();

const pubDate = content('.info-text')
.first()
.text()
.replace(/ /, '')
.trim();

item.description = content('.topic-body').html();
item.author = content('.user-link').first().text();
item.pubDate = timezone(/-/.test(pubDate) ? parseDate(pubDate) : parseRelativeDate(pubDate), +8);

return item;
})
)
);

ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
allowEmpty: true,
};
};
31 changes: 31 additions & 0 deletions lib/v2/quicker/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
'getquicker.net': {
_name: 'Quicker',
'.': [
{
title: '动作分享',
docs: 'https://docs.rsshub.app/programming.html#quicker-dong-zuo-fen-xiang',
source: ['/Share/:category', '/'],
target: '/quicker/share/:category?',
},
{
title: '讨论区',
docs: 'https://docs.rsshub.app/programming.html#quicker-tao-lun-qu',
source: ['/QA', '/'],
target: (params, url) => `/quicker/qa/${new URL(url).searchParams.get('category') ?? ''}/${new URL(url).searchParams.get('state') ?? ''}`,
},
{
title: '用户动作更新',
docs: 'https://docs.rsshub.app/programming.html#quicker-yong-hu-dong-zuo-geng-xin',
source: ['/QA', '/'],
target: (params, url) => `/quicker/qa/${new URL(url).searchParams.get('category') ?? ''}/${new URL(url).searchParams.get('state') ?? ''}`,
},
{
title: '版本更新',
docs: 'https://docs.rsshub.app/programming.html#quicker-ban-ben-geng-xin',
source: ['/Help/Versions', '/'],
target: '/quicker/versions',
},
],
},
};
7 changes: 7 additions & 0 deletions lib/v2/quicker/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function (router) {
router.get('/qa/:category?/:state?', require('./qa'));
router.get('/share/:category?', require('./share'));
router.get('/update', require('./versions'));
router.get('/user/:category/:id', require('./user'));
router.get('/versions', require('./versions'));
};
61 changes: 61 additions & 0 deletions lib/v2/quicker/share.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate, parseRelativeDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const category = ctx.params.category ?? 'Recent';

const rootUrl = 'https://getquicker.net';
const currentUrl = `${rootUrl}/Share/${category}`;

const response = await got({
method: 'get',
url: currentUrl,
});

const $ = cheerio.load(response.data);

let items = $('table tbody tr')
.slice(1, ctx.query.limit ? parseInt(ctx.query.limit) : 25)
.toArray()
.map((item) => {
item = $(item).find('td a').first();

return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
};
});

items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});

const content = cheerio.load(detailResponse.data);

content('section').last().remove();
content('#app').children().slice(0, 2).remove();

const pubDate = content('.text-secondary a').not('.text-secondary').first().text()?.trim().replace(/\s*/g, '') || content('div.note-text').find('span').eq(3).text();

item.author = content('.user-link').first().text();
item.description = content('div[data-info="动作信息"]').html() ?? content('#app').html() ?? content('.row').eq(1).html();
item.pubDate = timezone(/-/.test(pubDate) ? parseDate(pubDate) : parseRelativeDate(pubDate), +8);

return item;
})
)
);

ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
allowEmpty: true,
};
};
Loading

0 comments on commit d68e5a8

Please sign in to comment.