feat(route): add Literotica Category (#8415)

This commit is contained in:
Ethan Shen 2021-11-27 16:03:23 +08:00 committed by GitHub
parent 3715f2b35e
commit 1dd850cb1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 86 additions and 0 deletions

View File

@ -9,3 +9,9 @@ pageClass: routes
### Poems
<RouteEn author="HenryQW" example="/allpoetry/newest" path="/allpoetry/:order?" :paramsDesc="['排序方式, `best``newest`, 缺省 `best`']"/>
## Literotica
### Category
<RouteEn author="nczitzk" example="/literotica/category/anal-sex-stories" path="/literotica/category/:category?" :paramsDesc="['Categor, can be found in URL']"/>

View File

@ -22,6 +22,12 @@ pageClass: routes
</Route>
## Literotica
### New Stories
<Route author="nczitzk" example="/literotica/category/anal-sex-stories" path="/literotica/category/:category?" :paramsDesc="['分类,可在对应分类页地址栏中找到']"/>
## Mobilism
### eBook Releases

View File

@ -0,0 +1,55 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const category = ctx.params.category;
const rootUrl = 'https://www.literotica.com';
const currentUrl = `${rootUrl}/c/${category}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.b-slb-item')
.map((_, item) => {
item = $(item);
const a = item.find('h3 a');
return {
title: a.text(),
link: a.attr('href'),
author: item.find('.b-user-info-name').text(),
pubDate: parseDate(item.find('.b-slib-date').text(), 'MM/DD/YY'),
};
})
.get();
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('.aa_ht').html();
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/category/:category': ['nczitzk'],
};

View File

@ -0,0 +1,13 @@
module.exports = {
'literotica.com': {
_name: 'Literotica',
'.': [
{
title: 'Category',
docs: 'https://docs.rsshub.app/reading.html#literotica-category',
source: ['/c/:category', '/'],
target: '/literotica/category/:category',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/category/:category', require('./category'));
};