feat(route): add Literotica News Stories (#8410)

Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
Ethan Shen 2021-11-27 16:05:31 +08:00 committed by GitHub
parent 1dd850cb1c
commit efe64eb952
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 0 deletions

View File

@ -12,6 +12,10 @@ pageClass: routes
## Literotica
### New Stories
<RouteEn author="nczitzk" example="/literotica/new" path="/literotica/new"/>
### Category
<RouteEn author="nczitzk" example="/literotica/category/anal-sex-stories" path="/literotica/category/:category?" :paramsDesc="['Categor, can be found in URL']"/>

View File

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

View File

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

59
lib/v2/literotica/new.js Normal file
View File

@ -0,0 +1,59 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'https://www.literotica.com';
const currentUrl = `${rootUrl}/stories/new_submissions.php`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.b-46t')
.map((_, item) => {
item = $(item);
const a = item.find('.p-48y');
return {
title: a.text(),
link: a.attr('href'),
category: item.nextAll().eq(3).text().replace(/\(|\)/g, '').trim(),
pubDate: parseDate(item.nextAll().eq(4).text().trim(), 'MM/DD/YY'),
author: item
.nextAll()
.eq(2)
.text()
.replace(/Submitted by/, '')
.trim(),
};
})
.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

@ -2,6 +2,12 @@ module.exports = {
'literotica.com': {
_name: 'Literotica',
'.': [
{
title: 'New Stories',
docs: 'https://docs.rsshub.app/reading.html#literotica-new-stories',
source: ['/'],
target: '/literotica/new',
},
{
title: 'Category',
docs: 'https://docs.rsshub.app/reading.html#literotica-category',

View File

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