Skip to content

Commit

Permalink
feat(route): add Literotica Category (#8415)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Shen authored Nov 27, 2021
1 parent 3715f2b commit 1dd850c
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/en/reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']"/>
6 changes: 6 additions & 0 deletions docs/reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions lib/v2/literotica/category.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
3 changes: 3 additions & 0 deletions lib/v2/literotica/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/category/:category': ['nczitzk'],
};
13 changes: 13 additions & 0 deletions lib/v2/literotica/radar.js
Original file line number Diff line number Diff line change
@@ -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',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/literotica/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/category/:category', require('./category'));
};

1 comment on commit 1dd850c

@vercel
Copy link

@vercel vercel bot commented on 1dd850c Nov 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.