Skip to content

Commit

Permalink
Merge pull request #2479 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 Apr 19, 2024
2 parents e4ca8c0 + 6a80296 commit 27fab57
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 44 deletions.
128 changes: 128 additions & 0 deletions lib/routes/dehenglaw/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
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 { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import path from 'node:path';

export const handler = async (ctx) => {
const { language = 'CN', category = 'paper' } = ctx.req.param();
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 6;

const rootUrl = 'https://www.dehenglaw.com';
const currentUrl = new URL(`${language}/${category}/0008/000901.aspx`, rootUrl).href;

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

const $ = load(response);

let items = $('div.news_box ul li')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);

const title = item.find('h2').text();
const description = art(path.join(__dirname, 'templates/description.art'), {
intro: item.find('div.deheng_newscontent p').text(),
});

return {
title,
description,
pubDate: parseDate(item.find('span').text(), 'YYYY/M/D'),
link: item.find('a').first().prop('href'),
};
});

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

const $$ = load(detailResponse);

const description =
item.description +
art(path.join(__dirname, 'templates/description.art'), {
description: $$('div.news_content').html(),
});
const image = $$('div.news_content img').prop('src');

item.description = description;
item.author = $$('div.name h4 a').text();
item.content = {
html: description,
text: $$('div.news_content').text(),
};
item.image = image;
item.banner = image;

return item;
})
)
);

const image = $('div.logo_content a img').prop('src');

return {
title: $('title')
.text()
.replace(/\|.*?$/, `| ${$('li.onthis').text()}`),
description: $('meta[name="Description"]').prop('content'),
link: currentUrl,
item: items,
allowEmpty: true,
image,
author: $('meta[name="Description"]').prop('content'),
};
};

export const route: Route = {
path: '/:language?/:category?',
name: '德恒探索',
url: 'dehenglaw.com',
maintainers: ['nczitzk'],
handler,
example: '/dehenglaw/CN/paper',
parameters: { language: '语言,默认为中文,即 CN,可在对应分类页 URL 中找到,可选 CN 和 EN', category: '分类,默认为专业文章,即 paper,可在对应分类页 URL 中找到' },
description: `:::tip
若订阅 [专业文章](https://dehenglaw.com/),网址为 \`https://www.dehenglaw.com/CN/paper/0008/000902.aspx\`。截取 \`https://dehenglaw.com/\` 到末尾 \`/0008/000902.aspx\` 的部分 \`CN/paper\` 作为参数填入,此时路由为 [\`/dehenglaw/CN/paper\`](https://rsshub.app/dehenglaw/CN/paper)。
| 专业文章 | 出版物 | 德恒论坛 |
| -------- | ------- | -------- |
| paper | publish | luntan |
:::`,
categories: ['new-media'],

features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
title: '专业文章',
source: ['dehenglaw.com/:language/paper/0008/000902.aspx'],
target: '/:language/paper',
},
{
title: '出版物',
source: ['dehenglaw.com/:language/publish/0008/000903.aspx'],
target: '/:language/publish',
},
{
title: '德恒论坛',
source: ['dehenglaw.com/:language/luntan/0008/000901.aspx'],
target: '/:language/luntan',
},
],
};
8 changes: 8 additions & 0 deletions lib/routes/dehenglaw/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: 'dehenglaw.com',
categories: ['new-media'],
description: '',
};
7 changes: 7 additions & 0 deletions lib/routes/dehenglaw/templates/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ if intro }}
<blockquote>{{ intro }}</blockquote>
{{ /if }}

{{ if description }}
{{@ description }}
{{ /if }}
4 changes: 2 additions & 2 deletions lib/routes/reuters/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ export const route: Route = {
};

async function handler(ctx) {
const MUST_FETCH_BY_TOPICS = new Set(['authors']);
const MUST_FETCH_BY_TOPICS = new Set(['authors', 'tags']);
const CAN_USE_SOPHI = ['world'];

const category = ctx.req.param('category');
const topic = ctx.req.param('topic') ?? (category === 'authors' ? 'reuters' : '');
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20;
const useSophi = ctx.req.query('sophi') === 'true' && 'topic' !== '' && CAN_USE_SOPHI.includes(category);
const useSophi = ctx.req.query('sophi') === 'true' && topic !== '' && CAN_USE_SOPHI.includes(category);

const section_id = `/${category}/${topic ? `${topic}/` : ''}`;
const { title, description, rootUrl, response } = await (async () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/wechat-mp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ExtractMetadata {
$,
(script) => {
const scriptText = $(script).text();
const metadataExtracted = <Record<string, string>>this.doExtract(this.commonMetadataToBeExtracted, scriptText);
const metadataExtracted = <Record<string, string>> this.doExtract(this.commonMetadataToBeExtracted, scriptText);
const showType = showTypeMapReverse[metadataExtracted.showType];
const realShowType = showTypeMapReverse[metadataExtracted.realShowType];
metadataExtracted.sourceUrl = metadataExtracted.sourceUrl && fixUrl(metadataExtracted.sourceUrl);
Expand Down Expand Up @@ -191,7 +191,7 @@ class ExtractMetadata {
$,
(script) => {
const scriptText = $(script).text();
const metadataExtracted = <Record<string, string>>this.doExtract(this.audioMetadataToBeExtracted, scriptText);
const metadataExtracted = <Record<string, string>> this.doExtract(this.audioMetadataToBeExtracted, scriptText);
throw new LoopReturn(metadataExtracted);
},
{},
Expand All @@ -207,7 +207,7 @@ class ExtractMetadata {
$,
(script) => {
const scriptText = $(script).text();
const metadataExtracted = <Record<string, string[]>>this.doExtract(this.imgMetadataToBeExtracted, scriptText);
const metadataExtracted = <Record<string, string[]>> this.doExtract(this.imgMetadataToBeExtracted, scriptText);
if (Array.isArray(metadataExtracted.imgUrls)) {
metadataExtracted.imgUrls = metadataExtracted.imgUrls.map((url) => fixUrl(url));
}
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"build:docs": "tsx scripts/workflow/build-docs.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,tsx,js,yml}\" && prettier \"**/*.{ts,tsx,js,json}\" --write",
"format:check": "eslint --cache \"**/*.{ts,tsx,js,yml}\" && prettier \"**/*.{ts,tsx,js,json}\" --check",
"format": "prettier \"**/*.{ts,tsx,js,json}\" --write && eslint --cache --fix \"**/*.{ts,tsx,js,yml}\"",
"format:check": "prettier \"**/*.{ts,tsx,js,json}\" --check && eslint --cache \"**/*.{ts,tsx,js,yml}\"",
"format:staged": "lint-staged",
"lint": "eslint --cache .",
"prepare": "husky || true",
Expand Down Expand Up @@ -55,7 +55,7 @@
"@hono/zod-openapi": "0.11.0",
"@notionhq/client": "2.2.15",
"@postlight/parser": "2.2.3",
"@sentry/node": "7.110.1",
"@sentry/node": "7.111.0",
"@tonyrl/rand-user-agent": "2.0.59",
"aes-js": "3.1.2",
"art-template": "4.13.2",
Expand All @@ -75,7 +75,7 @@
"fanfou-sdk": "5.0.0",
"form-data": "4.0.0",
"googleapis": "134.0.0",
"hono": "4.2.4",
"hono": "4.2.5",
"html-to-text": "9.0.5",
"https-proxy-agent": "7.0.4",
"iconv-lite": "0.6.3",
Expand Down
70 changes: 35 additions & 35 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 27fab57

Please sign in to comment.