feat(route): Magazinelib latest magazine (#12072)
* feat(route): magazinelib latest magazine * feat: add subTitle * fix: wrong docs position * fix: wrong router * fix: wrong radar rules * chore: use arrow function * chore: remove extra blank lines * chore: remove extra blank lines * fix: magazineLib name * feat: use wordpress api * feat: use _embed to get image url
This commit is contained in:
parent
4b84b0dbd7
commit
f4997c45ad
|
|
@ -56,6 +56,16 @@ Eg:<https://kakuyomu.jp/works/1177354054883783581>
|
|||
|
||||
<RouteEn author="nczitzk" example="/literotica/category/anal-sex-stories" path="/literotica/category/:category?" :paramsDesc="['Category, can be found in URL']"/>
|
||||
|
||||
## MagazineLib
|
||||
|
||||
### Latest Magazine
|
||||
|
||||
<RouteEn author="NavePnow" example="/magazinelib/latest-magazine/new+yorker" path="/magazinelib/latest-magazine/:query?" :paramsDesc="['query, search page querystring']"/>
|
||||
|
||||
For instance, when doing search at <https://magazinelib.com/> and you get url <https://magazinelib.com/?s=new+yorker>, the query is `new+yorker`
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## Mobilism
|
||||
|
||||
### eBook Releases
|
||||
|
|
|
|||
|
|
@ -67,6 +67,16 @@ pageClass: routes
|
|||
|
||||
<Route author="nczitzk" example="/literotica/category/anal-sex-stories" path="/literotica/category/:category?" :paramsDesc="['分类,可在对应分类页地址栏中找到']"/>
|
||||
|
||||
## MagazineLib
|
||||
|
||||
### Latest Magazine
|
||||
|
||||
<Route author="NavePnow" example="/magazinelib/latest-magazine/new+yorker" path="/magazinelib/latest-magazine/:query?" :paramsDesc="['query,search page querystring']"/>
|
||||
|
||||
For instance, when doing search at <https://magazinelib.com/> and you get url <https://magazinelib.com/?s=new+yorker>, the query is `new+yorker`
|
||||
|
||||
</Route>
|
||||
|
||||
## Mobilism
|
||||
|
||||
### 电子书
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
const host = 'https://magazinelib.com';
|
||||
module.exports = async (ctx) => {
|
||||
const query = ctx.params.query;
|
||||
const url = `${host}/wp-json/wp/v2/posts/`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url,
|
||||
searchParams: {
|
||||
search: query,
|
||||
per_page: 30,
|
||||
_embed: 1,
|
||||
},
|
||||
});
|
||||
let subTitle = query;
|
||||
if (subTitle !== undefined) {
|
||||
subTitle = subTitle.replace(/[^a-zA-Z0-9]+/g, ' ').toUpperCase();
|
||||
subTitle = ` - ${subTitle}`;
|
||||
} else {
|
||||
subTitle = '';
|
||||
}
|
||||
|
||||
const items = response.data.map((obj) => {
|
||||
const data = {};
|
||||
data.date = obj.date_gmt;
|
||||
data.link = obj.link;
|
||||
data.featuredMediaLink = obj._links['wp:featuredmedia'][0].href;
|
||||
data.title = obj.title.rendered;
|
||||
const $ = cheerio.load(obj.content.rendered);
|
||||
const content = $('.vk-att');
|
||||
content.find('img[src="https://magazinelib.com/wp-includes/images/media/default.png"]').remove();
|
||||
data.content = content.html();
|
||||
const imgUrl = obj._embedded['wp:featuredmedia'][0].source_url;
|
||||
data.description = data.content + art(path.join(__dirname, 'templates/magazine-description.art'), { imgUrl });
|
||||
data.categories = obj._embedded['wp:term'][0].map((item) => item.name);
|
||||
return data;
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: `MagazineLib - Latest Magazines${subTitle}`,
|
||||
link: `{host}/?s=${query}`,
|
||||
description: `MagazineLib - Latest Magazines${subTitle}`,
|
||||
item: items.map((item) => ({
|
||||
title: item.title,
|
||||
link: item.link,
|
||||
category: item.categories,
|
||||
pubDate: new Date(item.pubDate).toUTCString(),
|
||||
description: item.description,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/latest-magazine/:query?': ['NavePnow'],
|
||||
};
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
module.exports = {
|
||||
'magazinelib.com': {
|
||||
_name: 'magazineLib',
|
||||
'.': [
|
||||
{
|
||||
title: 'Latest Magazine',
|
||||
docs: 'https://docs.rsshub.app/reading.html#magazinelib',
|
||||
source: ['/'],
|
||||
target: (_, url) => {
|
||||
const query = new URL(url).searchParams.get('s');
|
||||
if (query === null) {
|
||||
return '/magazinelib/latest-magazine';
|
||||
}
|
||||
return `/magazinelib/latest-magazine/${query}`;
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/latest-magazine/:query?', require('./latest-magazine'));
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<div>
|
||||
<img src={{imgUrl}}>
|
||||
</div>
|
||||
Loading…
Reference in New Issue