-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add Quicker动作更新 (#9357)
* 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
Showing
14 changed files
with
326 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
Oops, something went wrong.