Skip to content

Commit

Permalink
Merge pull request #1331 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Mar 28, 2024
2 parents 08d9eed + 0526c2c commit 4e44c32
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 34 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=true
5 changes: 5 additions & 0 deletions lib/routes/18comic/templates/description.art
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{{ if cover }}
<img src="{{ cover }}">
{{ /if }}
<p>
{{each category}}
<code>{{ $value }}</code>
{{/each}}
</p>
<p>{{ introduction }}</p>
{{ each images image }}
<img src="{{ image }}">
Expand Down
1 change: 1 addition & 0 deletions lib/routes/18comic/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const ProcessItems = async (ctx, currentUrl, rootUrl) => {
.toArray()
.map((image) => content(image).attr('data-original')),
cover: content('.thumb-overlay img').first().attr('src'),
category: item.category,
});

return item;
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/aeon/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const getData = async (ctx, list) => {

const article = data.props.pageProps.article;
const capture = load(article.body);
const banner = article.thumbnail?.urls?.header;
const banner = article.image?.url;
capture('p.pullquote').remove();

const authorsBio = article.authors.map((author) => '<p>' + author.name + author.authorBio.replaceAll(/^<p>/g, ' ')).join('');
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/docschina/weekly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const route: Route = {
maintainers: ['daijinru', 'hestudy'],
handler,
description: `| javascript | node | react |
| ---------- | ---- | ----- |
| js | node | react |`,
| ---------- | ---- | ----- |
| js | node | react |`,
radar: [
{
source: ['docschina.org/news/weekly/js/*', 'docschina.org/news/weekly/js', 'docschina.org/'],
Expand Down
11 changes: 9 additions & 2 deletions lib/routes/github/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ import queryString from 'query-string';

export const route: Route = {
path: '/file/:user/:repo/:branch/:filepath{.+}',
example: '/github/file/DIYgod/RSSHub/master/README.md',
parameters: {
user: 'GitHub user or org name',
repo: 'repository name',
branch: 'branch name',
filepath: 'path of target file',
},
radar: [
{
source: ['github.com/:user/:repo/blob/:branch/*filepath'],
target: '/file/:user/:repo/:branch/:filepath',
},
],
name: 'Unknown',
maintainers: [],
name: 'File Commits',
maintainers: ['zengxs'],
handler,
};

Expand Down
98 changes: 98 additions & 0 deletions lib/routes/junhe/legal-updates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { Route } from '@/types';

import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';

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

const rootUrl = 'https://junhe.com';
const currentUrl = new URL('legal-updates', rootUrl).href;

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

const $ = load(response);

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

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

return {
title: item.find('h1.news.detail').text(),
pubDate: parseDate(item.find('p.date').text(), 'YYYY.MM.DD'),
link: new URL(item.prop('href'), rootUrl).href,
};
});

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

const $$ = load(detailResponse);

const title = $$('h1.d-title').text();
const description = $$('div.d-content').html();
const infos = $$('p.d-pub-date').text().split(/\s/);

item.title = title;
item.description = description;
item.pubDate = parseDate(infos[0], 'YYYY.MM.DD');
item.author = infos.slice(1).join('/');
item.content = {
html: description,
text: $$('div.d-content').text(),
};
item.language = language;

return item;
})
)
);

const image = new URL($('a.site-logo img').prop('src'), rootUrl).href;

return {
title: $('title').text(),
description: $('meta[name="description"]').prop('content'),
link: currentUrl,
item: items,
allowEmpty: true,
image,
author: '君合律师事务所',
language,
};
};

export const route: Route = {
path: '/legal-updates',
name: '君合法评',
url: 'junhe.com',
maintainers: ['nczitzk'],
handler,
example: '/junhe/legal-updates',
description: '',
categories: ['new-media'],

features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['/legal-updates'],
target: '/legal-updates',
},
],
};
8 changes: 8 additions & 0 deletions lib/routes/junhe/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '君合律师事务所',
url: 'junhe.com',
categories: ['new-media'],
description: '',
};
69 changes: 69 additions & 0 deletions lib/routes/miui/community/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Route, Data } from '@/types';
import got from '@/utils/got';

export const route: Route = {
path: '/community/user/:uid',
categories: ['bbs'],
example: '/miui/community/user/1200057564',
parameters: {
uid: '小米用户 UID,可于网页版用户主页链接中 `uid` 项获取',
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['web.vip.miui.com/page/info/mio/mio/homePage'],
target: (_, url) => `/miui/community/user/${new URL(url).searchParams.get('uid')}`,
},
],
name: '小米社区用户发帖',
maintainers: ['abc1763613206'],
handler,
};

const userRoot = 'https://web.vip.miui.com/page/info/mio/mio/homePage';
const apiRoot = 'https://api.vip.miui.com/api/community/user/announce/list';
const pageRoot = 'https://web.vip.miui.com/page/info/mio/mio/detail';

async function handler(ctx): Promise<Data> {
const uid = ctx.req.param('uid');
const apiLink = `${apiRoot}?uid=${uid}&limit=10`;
const userLink = `${userRoot}?uid=${uid}`;
const { data } = await got({
method: 'get',
url: apiLink,
headers: {
Referer: userLink,
},
});
if (data.code === 200) {
let authorName = '';
const records = data.entity.records;
const items = records.map((item) => {
authorName = item.author.name;
return {
title: item.title || `${authorName} 的动态`,
description: item.textContent,
pubDate: new Date(item.createTime).toUTCString(),
author: item.author.name,
link: `${pageRoot}?postId=${item.id}`,
image: item.pic || item.cover || '',
};
});
return {
title: `小米社区 - ${authorName} 的发帖`,
link: userLink,
description: `${authorName} 的发帖`,
item: items,
language: 'zh-cn',
};
} else {
throw new Error(data.message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import got from '@/utils/got';
import queryString from 'query-string';

export const route: Route = {
path: '/:device/:type?/:region?',
path: '/firmware/:device/:type?/:region?',
categories: ['program-update'],
example: '/miui/aries',
example: '/miui/firmware/aries',
parameters: { device: 'the device `codename` eg. `aries` for Mi 2S', type: 'type', region: 'Region, default to `cn`' },
name: 'New firmware',
maintainers: ['Indexyz'],
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/pts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function handler(ctx) {

const $ = load(response.data);

let items = $('h2 a')
let items = $('h1 a,h2 a')
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 30)
.toArray()
.map((item) => {
Expand Down
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
"scripts": {
"build": "tsx scripts/workflow/build-routes.ts",
"build:docs": "tsx scripts/workflow/build-docs.ts",
"dev": "NODE_ENV=dev tsx watch --no-cache lib/index.ts",
"dev:cache": "NODE_ENV=production tsx watch lib/index.ts",
"dev": "cross-env NODE_ENV=dev tsx watch --no-cache lib/index.ts",
"dev:cache": "cross-env NODE_ENV=production tsx watch lib/index.ts",
"format": "eslint --cache --fix \"**/*.{ts,js,yml}\" && prettier \"**/*.{ts,js,json}\" --write",
"format:check": "eslint --cache \"**/*.{ts,js,yml}\" && prettier \"**/*.{ts,js,json}\" --check",
"format:staged": "lint-staged",
"vitest": "NODE_ENV=test vitest",
"vitest:fullroutes": "NODE_ENV=test FULL_ROUTES_TEST=true vitest --reporter=json --reporter=default --outputFile=\"./assets/build/test-full-routes.json\" routes",
"vitest:coverage": "NODE_ENV=test vitest --coverage.enabled --reporter=junit",
"vitest:watch": "NODE_ENV=test vitest --watch",
"vitest": "cross-env NODE_ENV=test vitest",
"vitest:fullroutes": "cross-env NODE_ENV=test FULL_ROUTES_TEST=true vitest --reporter=json --reporter=default --outputFile=\"./assets/build/test-full-routes.json\" routes",
"vitest:coverage": "cross-env NODE_ENV=test vitest --coverage.enabled --reporter=junit",
"vitest:watch": "cross-env NODE_ENV=test vitest --watch",
"lint": "eslint --cache .",
"prepare": "husky || true",
"profiling": "NODE_ENV=production tsx --prof lib/index.ts",
"start": "NODE_ENV=production tsx lib/index.ts",
"profiling": "cross-env NODE_ENV=production tsx --prof lib/index.ts",
"start": "cross-env NODE_ENV=production tsx lib/index.ts",
"test": "npm run format:check && npm run vitest:coverage"
},
"lint-staged": {
Expand Down Expand Up @@ -63,14 +63,16 @@
"cheerio": "1.0.0-rc.12",
"chrono-node": "2.7.5",
"city-timezones": "1.2.1",
"cross-env": "7.0.3",
"crypto-js": "4.2.0",
"currency-symbol-map": "5.1.0",
"dayjs": "1.11.8",
"directory-import": "3.2.1",
"directory-import": "3.3.1",
"dotenv": "16.4.5",
"entities": "4.5.0",
"etag": "1.8.1",
"fanfou-sdk": "5.0.0",
"form-data": "4.0.0",
"git-rev-sync": "3.0.2",
"googleapis": "134.0.0",
"got": "14.2.1",
Expand Down Expand Up @@ -111,7 +113,7 @@
"telegram": "2.20.2",
"tiny-async-pool": "2.1.0",
"title": "3.5.3",
"tldts": "6.1.14",
"tldts": "6.1.15",
"tough-cookie": "4.1.3",
"tsx": "4.7.1",
"twitter-api-v2": "1.16.1",
Expand Down
Loading

0 comments on commit 4e44c32

Please sign in to comment.