-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
5 changed files
with
146 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |