Skip to content

Commit

Permalink
fix(route): 追新番最近更新 (#14751)
Browse files Browse the repository at this point in the history
* fix(route): 追新番最近更新

* update lib/routes/fanxinzhui/index.ts

Co-authored-by: Tony <[email protected]>

* update lib/routes/fanxinzhui/index.ts

Co-authored-by: Tony <[email protected]>

---------
  • Loading branch information
nczitzk authored Mar 17, 2024
1 parent 4314e90 commit 7d6bde4
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 54 deletions.
4 changes: 2 additions & 2 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1121,8 +1121,8 @@ router.get('/etoland/:bo_table', lazyloadRouteHandler('./routes/etoland/board'))
router.get('/lntu/jwnews', lazyloadRouteHandler('./routes/universities/lntu/jwnews'));

// 追新番
router.get('/fanxinzhui', lazyloadRouteHandler('./routes/fanxinzhui/latest'));
router.get('/zhuixinfan/list', lazyloadRouteHandler('./routes/fanxinzhui/latest'));
// router.get('/fanxinzhui', lazyloadRouteHandler('./routes/fanxinzhui/latest'));
// router.get('/zhuixinfan/list', lazyloadRouteHandler('./routes/fanxinzhui/latest'));

// blur-studio
router.get('/blur-studio', lazyloadRouteHandler('./routes/blur-studio/index'));
Expand Down
52 changes: 0 additions & 52 deletions lib/routes-deprecated/fanxinzhui/latest.js

This file was deleted.

125 changes: 125 additions & 0 deletions lib/routes/fanxinzhui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import timezone from '@/utils/timezone';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import * as path from 'node:path';

export const route: Route = {
path: '/',
name: '最近更新',
url: 'fanxinzhui.com/lastest',
maintainers: ['nczitzk'],
handler,
example: '/fanxinzhui',
categories: ['multimedia'],

radar: [{
source: ['fanxinzhui.com/lastest'],
target: '/',
}],
};

async function handler(ctx) {
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 30;

const rootUrl = 'https://www.fanxinzhui.com';
const currentUrl = new URL('lastest', rootUrl).href;

const { data: response } = await got(currentUrl);

const $ = load(response);

let items = $('a.la')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);

const season = item.find('span.season').text();
const name = item.find('span.name').text();
const link = new URL(item.prop('href'), rootUrl).href;

return {
title: `${season} ${name}`,
link,
guid: `${link}#${season}`,
pubDate: timezone(parseDate(item.find('span.time').text()), +8),
};
});

items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);

const content = load(detailResponse);

item.author = undefined;
item.category = [];

content('div.info ul li').each((_, el) => {
el = content(el);

const key = el.find('span').text().split(/:/)[0];
const value = el.contents().last().text().trim();

if (key === '类型') {
item.category = [...item.category, ...value.split(/\//)];
} else if (key === '首播日期') {
return;
} else {
item.author = `${item.author ? `${item.author}/` : ''}${value}`;
item.category = [...item.category, ...value.split(/\//)].filter((c) => c !== '等');
}
});

content('div.image').each((_, el) => {
el = content(el);

const image = el.find('img').prop('src');

el.replaceWith(
art(path.join(__dirname, 'templates/description.art'), {
images: image
? [
{
src: image.replace(/@\d+,\d+\.\w+$/, ''),
alt: content('div.resource_title h2').text(),
},
]
: undefined,
})
);
});

content('a.password').each((_, el) => {
el = content(el);

el.replaceWith(el.text());
});

item.description = content('div.middle_box').html();
item.enclosure_url = content('p.way span a').prop('href');

return item;
})
)
);

const title = $('title').text();
const image = new URL($('img.logo').prop('src'), rootUrl).href;

return {
item: items,
title,
link: currentUrl,
description: $('meta[name="description"]').prop('content'),
language: 'zh',
image,
author: title.split(/_/).pop(),
allowEmpty: true,
};
}
6 changes: 6 additions & 0 deletions lib/routes/fanxinzhui/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '追新番',
url: 'fanxinzhui.com',
};
13 changes: 13 additions & 0 deletions lib/routes/fanxinzhui/templates/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{ if images }}
{{ each images image }}
{{ if image?.src }}
<figure>
<img
{{ if image.alt }}
alt="{{ image.alt }}"
{{ /if }}
src="{{ image.src }}">
</figure>
{{ /if }}
{{ /each }}
{{ /if }}

0 comments on commit 7d6bde4

Please sign in to comment.