From 1dd850cb1c04696a097185722ff0719802201b0f Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 16:03:23 +0800 Subject: [PATCH] feat(route): add Literotica Category (#8415) --- docs/en/reading.md | 6 ++++ docs/reading.md | 6 ++++ lib/v2/literotica/category.js | 55 +++++++++++++++++++++++++++++++++ lib/v2/literotica/maintainer.js | 3 ++ lib/v2/literotica/radar.js | 13 ++++++++ lib/v2/literotica/router.js | 3 ++ 6 files changed, 86 insertions(+) create mode 100644 lib/v2/literotica/category.js create mode 100644 lib/v2/literotica/maintainer.js create mode 100644 lib/v2/literotica/radar.js create mode 100644 lib/v2/literotica/router.js diff --git a/docs/en/reading.md b/docs/en/reading.md index 930f3a235..785018410 100644 --- a/docs/en/reading.md +++ b/docs/en/reading.md @@ -9,3 +9,9 @@ pageClass: routes ### Poems + +## Literotica + +### Category + + diff --git a/docs/reading.md b/docs/reading.md index 663b32ec3..eff178701 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -22,6 +22,12 @@ pageClass: routes +## Literotica + +### New Stories + + + ## Mobilism ### eBook Releases diff --git a/lib/v2/literotica/category.js b/lib/v2/literotica/category.js new file mode 100644 index 000000000..839ffaa62 --- /dev/null +++ b/lib/v2/literotica/category.js @@ -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, + }; +}; diff --git a/lib/v2/literotica/maintainer.js b/lib/v2/literotica/maintainer.js new file mode 100644 index 000000000..fc7773855 --- /dev/null +++ b/lib/v2/literotica/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/category/:category': ['nczitzk'], +}; diff --git a/lib/v2/literotica/radar.js b/lib/v2/literotica/radar.js new file mode 100644 index 000000000..597075ffa --- /dev/null +++ b/lib/v2/literotica/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/literotica/router.js b/lib/v2/literotica/router.js new file mode 100644 index 000000000..babffa269 --- /dev/null +++ b/lib/v2/literotica/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/category/:category', require('./category')); +};