请熟悉项目的小伙伴,增加u3c3的支持(内附实现代码) #10052
-
我实在是不知道为啥会一直pull request失败(#10051 #10050 ),我不想再改了,我本地测试好之后的代码贴在这里,希望熟悉项目的小伙伴能pull request 一下吧
module.exports = function (router) {
router.get('/:type?/:keyword?', require('./index'));
};
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const type = ctx.params.type;
// should be:
// undefined
// U3C3
// Videos
// Photo
// Book
// Game
// Software
// Other
const rootURL = 'https://www.u3c3.com';
let currentURL = rootURL;
let title = 'u3c3';
if (typeof type === 'undefined') {
currentURL = rootURL;
title = 'home - u3c3';
} else if (type === 'search') {
const keyword = typeof ctx.params.keyword === 'undefined' ? '' : ctx.params.keyword;
currentURL = `${rootURL}/?search=${keyword}`;
title = `search ${keyword} - u3c3`;
} else {
currentURL = `${rootURL}/?type=${type}&p=1`;
title = `${type} - u3c3`;
}
const response = await got({
method: 'get',
url: currentURL,
});
const $ = cheerio.load(response.data);
const items = $('body > div.container > div.table-responsive > table > tbody > tr')
.toArray()
.map((item) => {
item = $(item);
const title = item.find('td:nth-of-type(2) > a ').attr('title');
const guid = rootURL + item.find('td:nth-of-type(2) > a').attr('href');
const link = guid;
const pubDate = item.find('td:nth-of-type(5)').text();
const enclosure_url = item.find('td:nth-of-type(3) > a:nth-of-type(2)').attr('href');
return {
title,
guid,
link,
pubDate,
enclosure_url,
enclosure_type: 'application/x-bittorrent',
};
});
ctx.state.data = {
title,
description: title,
link: currentURL,
item: items,
};
};
## u3c3
### 关键词搜索
<Route author="noname1897" example="/u3c3/search/新片速递" path="/u3c3/search/:keyword?" :paramsDesc="['搜索关键字']" supportBT="1" />
### 分类
<Route author="noname1897" example="/u3c3/U3C3" path="/u3c3/:type?" :paramsDesc="['类别名称,注意大小写,需要严格对应!可选的 `type` 有 `U3C3`/`Video`/`Photo`/`Book`/`Game`/`Software`/`Other`,如果不设置 type,则展示首页']" supportBT="1" />
## u3c3
### search keyword
<RouteEn author="noname1897" example="/u3c3/search/les" path="/u3c3/search/:keyword?" :paramsDesc="['search keyword']" supportBT="1" />
### 分类
<RouteEn author="noname1897" example="/u3c3/U3C3" path="/u3c3/:type?" :paramsDesc="['type, pay attention to case, it should be exactly same as the choices: `U3C3`/`Video`/`Photo`/`Book`/`Game`/`Software`/`Other`, if no type is provided, show the home index']" supportBT="1" /> |
Beta Was this translation helpful? Give feedback.
Answered by
noname1776
Jun 29, 2022
Replies: 2 comments
Answer selected by
TonyRL
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我又重新提了一个 #10062 。 @TonyRL 看看是否可以 merge