Skip to content

Commit

Permalink
Merge branch 'master' into feat-CommandLineTool
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Oct 4, 2024
2 parents 55a7cee + 652f220 commit 7e3fc75
Show file tree
Hide file tree
Showing 84 changed files with 4,813 additions and 1,506 deletions.
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export default [{
}],

'unicorn/prefer-code-point': 'warn',
'unicorn/prefer-global-this': 'off',
'unicorn/prefer-logical-operator-over-ternary': 'warn',
'unicorn/prefer-module': 'off',
'unicorn/prefer-node-protocol': 'off',
Expand Down
8 changes: 8 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ export type Config = {
authenticationSecret?: string[];
authToken?: string[];
};
uestc: {
bbsCookie?: string;
bbsAuthStr?: string;
};
weibo: {
app_key?: string;
app_secret?: string;
Expand Down Expand Up @@ -668,6 +672,10 @@ const calculateValue = () => {
authenticationSecret: envs.TWITTER_AUTHENTICATION_SECRET?.split(','),
authToken: envs.TWITTER_AUTH_TOKEN?.split(','),
},
uestc: {
bbsCookie: envs.UESTC_BBS_COOKIE,
bbsAuthStr: envs.UESTC_BBS_AUTH_STR,
},
weibo: {
app_key: envs.WEIBO_APP_KEY,
app_secret: envs.WEIBO_APP_SECRET,
Expand Down
8 changes: 0 additions & 8 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ router.get('/huya/live/:id', lazyloadRouteHandler('./routes/huya/live'));
// f-droid
// router.get('/fdroid/apprelease/:app', lazyloadRouteHandler('./routes/fdroid/apprelease'));

// konachan
router.get('/konachan/post/popular_recent', lazyloadRouteHandler('./routes/konachan/post-popular-recent'));
router.get('/konachan.com/post/popular_recent', lazyloadRouteHandler('./routes/konachan/post-popular-recent'));
router.get('/konachan.net/post/popular_recent', lazyloadRouteHandler('./routes/konachan/post-popular-recent'));
router.get('/konachan/post/popular_recent/:period', lazyloadRouteHandler('./routes/konachan/post-popular-recent'));
router.get('/konachan.com/post/popular_recent/:period', lazyloadRouteHandler('./routes/konachan/post-popular-recent'));
router.get('/konachan.net/post/popular_recent/:period', lazyloadRouteHandler('./routes/konachan/post-popular-recent'));

// PornHub
// router.get('/pornhub/category/:caty', lazyloadRouteHandler('./routes/pornhub/category'));
// router.get('/pornhub/search/:keyword', lazyloadRouteHandler('./routes/pornhub/search'));
Expand Down
67 changes: 0 additions & 67 deletions lib/routes-deprecated/konachan/post-popular-recent.js

This file was deleted.

45 changes: 0 additions & 45 deletions lib/routes/a9vg/a9vg.ts

This file was deleted.

214 changes: 214 additions & 0 deletions lib/routes/a9vg/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
import { Route } from '@/types';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);

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 path from 'node:path';

export const handler = async (ctx) => {
const { category = 'news/All' } = ctx.req.param();
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 15;

const rootUrl = 'http://www.a9vg.com';
const currentUrl = new URL(`list/${category}`, rootUrl).href;

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

const $ = load(response);

const language = $('html').prop('lang');

let items = $('a.a9-rich-card-list_item')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);

const image = item.find('img.a9-rich-card-list_image');
const title = item.find('div.a9-rich-card-list_label').text();

return {
title,
link: new URL(item.prop('href'), rootUrl).href,
description: art(path.join(__dirname, 'templates/description.art'), {
images: image
? [
{
src: image.prop('src'),
alt: title,
},
]
: undefined,
}),
pubDate: timezone(parseDate(item.find('div.a9-rich-card-list_infos').text()), +8),
language,
};
});

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

const $$ = load(detailResponse);

$$('ignore_js_op img, p img').each((_, el) => {
el = $$(el);

el.parent().replaceWith(
art(path.join(__dirname, 'templates/description.art'), {
images: el.prop('file')
? [
{
src: el.prop('file'),
alt: el.next().find('div.xs0 p').first().text(),
},
]
: undefined,
})
);
});

item.title = $$('h1.ts, div.c-article-main_content-title').first().text();
item.description = art(path.join(__dirname, 'templates/description.art'), {
description: $$('td.t_f, div.c-article-main_contentraw').first().html(),
});
item.author =
$$('b a.blue').first().text() ||
$$(
$$('span.c-article-main_content-intro-item')
.toArray()
.findLast((i) => $$(i).text().startsWith('作者'))
)
.text()
.split(//)
.pop();
item.pubDate = timezone(
parseDate(
$$('div.authi em')
.first()
.text()
.trim()
.match(/发表于 (\d+-\d+-\d+ \d+:\d+)/)?.[1] ?? $$('span.c-article-main_content-intro-item').first().text(),
['YYYY-M-D HH:mm', 'YYYY-MM-DD HH:mm']
),
+8
);
item.language = language;

return item;
})
)
);

const title = $('title').text();
const image = new URL('images/logo.1cee7c0f.svg', rootUrl).href;

return {
title,
description: $('meta[name="description"]').prop('content'),
link: currentUrl,
item: items,
allowEmpty: true,
image,
author: title.split(/-/).pop(),
language,
};
};

export const route: Route = {
path: '/:category{.+}?',
name: '新闻',
url: 'a9vg.com',
maintainers: ['monnerHenster', 'nczitzk'],
handler,
example: '/a9vg/news',
parameters: { category: '分类,默认为 ,可在对应分类页 URL 中找到, Category, by default' },
description: `:::tip
若订阅 [PS4](http://www.a9vg.com/list/news/PS4),网址为 \`http://www.a9vg.com/list/news/PS4\`。截取 \`http://www.a9vg.com/list\` 到末尾的部分 \`news/PS4\` 作为参数填入,此时路由为 [\`/a9vg/news/PS4\`](https://rsshub.app/a9vg/news/PS4)。
:::
| 分类 | ID |
| -------------------------------------------------- | ------------------------------------------------------ |
| [All](https://www.a9vg.com/list/news/All) | [news/All](https://rsshub.app/a9vg/news/All) |
| [PS4](https://www.a9vg.com/list/news/PS4) | [news/PS4](https://rsshub.app/a9vg/news/PS4) |
| [PS5](https://www.a9vg.com/list/news/PS5) | [news/PS5](https://rsshub.app/a9vg/news/PS5) |
| [Switch](https://www.a9vg.com/list/news/Switch) | [news/Switch](https://rsshub.app/a9vg/news/Switch) |
| [Xbox One](https://www.a9vg.com/list/news/XboxOne) | [news/XboxOne](https://rsshub.app/a9vg/news/XboxOne) |
| [XSX](https://www.a9vg.com/list/news/XSX) | [news/XSX](https://rsshub.app/a9vg/news/XSX) |
| [PC](https://www.a9vg.com/list/news/PC) | [news/PC](https://rsshub.app/a9vg/news/PC) |
| [业界](https://www.a9vg.com/list/news/Industry) | [news/Industry](https://rsshub.app/a9vg/news/Industry) |
| [厂商](https://www.a9vg.com/list/news/Factory) | [news/Factory](https://rsshub.app/a9vg/news/Factory) |
`,
categories: ['game'],

features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['www.a9vg.com/list/:category'],
target: (params) => {
const category = params.category;

return category ? `/${category}` : '';
},
},
{
title: 'All',
source: ['www.a9vg.com/list/news/All'],
target: '/news/All',
},
{
title: 'PS4',
source: ['www.a9vg.com/list/news/PS4'],
target: '/news/PS4',
},
{
title: 'PS5',
source: ['www.a9vg.com/list/news/PS5'],
target: '/news/PS5',
},
{
title: 'Switch',
source: ['www.a9vg.com/list/news/Switch'],
target: '/news/Switch',
},
{
title: 'Xbox One',
source: ['www.a9vg.com/list/news/XboxOne'],
target: '/news/XboxOne',
},
{
title: 'XSX',
source: ['www.a9vg.com/list/news/XSX'],
target: '/news/XSX',
},
{
title: 'PC',
source: ['www.a9vg.com/list/news/PC'],
target: '/news/PC',
},
{
title: '业界',
source: ['www.a9vg.com/list/news/Industry'],
target: '/news/Industry',
},
{
title: '厂商',
source: ['www.a9vg.com/list/news/Factory'],
target: '/news/Factory',
},
],
};
1 change: 1 addition & 0 deletions lib/routes/a9vg/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'A9VG 电玩部落',
url: 'a9vg.com',
description: '',
};
17 changes: 17 additions & 0 deletions lib/routes/a9vg/templates/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{ if images }}
{{ each images image }}
{{ if image?.src }}
<figure>
<img
{{ if image.alt }}
alt="{{ image.alt }}"
{{ /if }}
src="{{ image.src }}">
</figure>
{{ /if }}
{{ /each }}
{{ /if }}

{{ if description }}
{{@ description }}
{{ /if }}
Loading

0 comments on commit 7e3fc75

Please sign in to comment.