feat(route): add TV Tropes Featured (#14574)
* feat(route): add TV Tropes Featured * fix typo ---------
This commit is contained in:
parent
3676871a7d
commit
b735b645d8
|
|
@ -0,0 +1,73 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
const categories = {
|
||||
today: 'left',
|
||||
newest: 'right',
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { category = 'today' } = ctx.params;
|
||||
|
||||
const rootUrl = 'https://tvtropes.org';
|
||||
|
||||
const { data: response } = await got(rootUrl);
|
||||
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
const item = $(`div#featured-tropes div.${categories[category]}`);
|
||||
|
||||
const link = new URL(item.find('h2.entry-title a').prop('href'), rootUrl).href;
|
||||
|
||||
const { data: detailResponse } = await got(link);
|
||||
|
||||
const content = cheerio.load(detailResponse);
|
||||
|
||||
content('div.folderlabel').remove();
|
||||
|
||||
content('div.lazy_load_img_box').each((_, el) => {
|
||||
el = content(el);
|
||||
|
||||
const image = el.find('img');
|
||||
|
||||
el.replaceWith(
|
||||
art(path.join(__dirname, 'templates/description.art'), {
|
||||
images: [
|
||||
{
|
||||
src: image.prop('src'),
|
||||
alt: image.prop('alt'),
|
||||
width: image.prop('width'),
|
||||
height: image.prop('height'),
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
const items = [
|
||||
{
|
||||
title: item.find('h2.entry-title').text(),
|
||||
link,
|
||||
description: content('div#main-article').html(),
|
||||
},
|
||||
];
|
||||
|
||||
const image = new URL($('img.logo-big').prop('src'), rootUrl).href;
|
||||
const icon = $('link[rel="shortcut icon"]').prop('href');
|
||||
|
||||
ctx.state.data = {
|
||||
item: items,
|
||||
title: `${$('title').text()} - ${item.find('span.box-title').text()}`,
|
||||
link: rootUrl,
|
||||
description: $('meta[name="description"]').prop('content'),
|
||||
language: $('html').prop('lang'),
|
||||
image,
|
||||
icon,
|
||||
logo: icon,
|
||||
subtitle: $('meta[property="og:title"]').prop('content'),
|
||||
author: $('meta[property="og:site_name"]').prop('content'),
|
||||
allowEmpty: true,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/featured/:category?': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
module.exports = {
|
||||
'tvtropes.org': {
|
||||
_name: 'TV Tropes',
|
||||
'.': [
|
||||
{
|
||||
title: "Featured - Today's Featured Trope",
|
||||
docs: 'https://docs.rsshub.app/routes/other#tvtropes-featured',
|
||||
source: ['/'],
|
||||
target: '/tvtropes/featured/today',
|
||||
},
|
||||
{
|
||||
title: 'Featured - Newest Trope',
|
||||
docs: 'https://docs.rsshub.app/routes/other#tvtropes-featured',
|
||||
source: ['/'],
|
||||
target: '/tvtropes/featured/newest',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/featured/:category?', require('./featured'));
|
||||
};
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
{{ if images }}
|
||||
{{ each images image }}
|
||||
{{ if image?.src }}
|
||||
<figure>
|
||||
<img
|
||||
{{ if image.alt }}
|
||||
alt="{{ image.alt }}"
|
||||
{{ /if }}
|
||||
{{ if image.width }}
|
||||
width="{{ image.width }}"
|
||||
{{ /if }}
|
||||
{{ if image.height }}
|
||||
height="{{ image.height }}"
|
||||
{{ /if }}
|
||||
src="{{ image.src }}">
|
||||
</figure>
|
||||
{{ /if }}
|
||||
{{ /each }}
|
||||
{{ /if }}
|
||||
|
||||
{{ if description }}
|
||||
{{@ description }}
|
||||
{{ /if }}
|
||||
|
|
@ -528,6 +528,16 @@ Specify options (in the format of query string) in parameter `routeParams` param
|
|||
| `routeParams` | `title=Example` |
|
||||
</Route>
|
||||
|
||||
## TV Tropes {#tv-tropes}
|
||||
|
||||
### Featured {#tv-tropes-featured}
|
||||
|
||||
<Route author="nczitzk" example="/tvtropes/featured/today" path="/tvtropes/featured/:category?" paramsDesc={['Category, see below, Today\'s Featured Trope by default']} radar="1">
|
||||
| Today's Featured Trope | Newest Trope |
|
||||
| ---------------------- | ------------ |
|
||||
| today | newest |
|
||||
</Route>
|
||||
|
||||
## Urban Dictionary {#urban-dictionary}
|
||||
|
||||
### Random words {#urban-dictionary-random-words}
|
||||
|
|
|
|||
Loading…
Reference in New Issue