@jackwener/opencli 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLI-CREATOR.md +594 -0
- package/README.md +116 -38
- package/README.zh-CN.md +143 -0
- package/SKILL.md +154 -102
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +35 -1
- package/dist/cascade.d.ts +45 -0
- package/dist/cascade.js +180 -0
- package/dist/clis/bilibili/hot.yaml +38 -0
- package/dist/clis/github/trending.yaml +58 -0
- package/dist/clis/hackernews/top.yaml +36 -0
- package/dist/clis/index.d.ts +2 -1
- package/dist/clis/index.js +3 -1
- package/dist/clis/reddit/hot.yaml +46 -0
- package/dist/clis/twitter/trending.yaml +40 -0
- package/dist/clis/v2ex/hot.yaml +25 -0
- package/dist/clis/v2ex/latest.yaml +25 -0
- package/dist/clis/v2ex/topic.yaml +27 -0
- package/dist/clis/xiaohongshu/feed.yaml +32 -0
- package/dist/clis/xiaohongshu/notifications.yaml +38 -0
- package/dist/clis/xiaohongshu/search.d.ts +5 -0
- package/dist/clis/xiaohongshu/search.js +68 -0
- package/dist/clis/zhihu/hot.yaml +42 -0
- package/dist/clis/zhihu/question.js +39 -0
- package/dist/clis/zhihu/search.yaml +55 -0
- package/dist/explore.d.ts +23 -13
- package/dist/explore.js +293 -422
- package/dist/main.js +17 -0
- package/dist/pipeline.js +238 -2
- package/dist/synthesize.d.ts +11 -8
- package/dist/synthesize.js +142 -118
- package/package.json +4 -2
- package/src/browser.ts +33 -1
- package/src/cascade.ts +217 -0
- package/src/clis/index.ts +4 -1
- package/src/clis/reddit/hot.yaml +46 -0
- package/src/clis/v2ex/hot.yaml +5 -9
- package/src/clis/v2ex/latest.yaml +5 -8
- package/src/clis/v2ex/topic.yaml +27 -0
- package/src/clis/xiaohongshu/feed.yaml +32 -0
- package/src/clis/xiaohongshu/notifications.yaml +38 -0
- package/src/clis/xiaohongshu/search.ts +71 -0
- package/src/clis/zhihu/hot.yaml +22 -8
- package/src/clis/zhihu/question.ts +45 -0
- package/src/clis/zhihu/search.yaml +55 -0
- package/src/explore.ts +303 -465
- package/src/main.ts +14 -0
- package/src/pipeline.ts +239 -2
- package/src/synthesize.ts +142 -137
- package/dist/clis/zhihu/search.js +0 -58
- package/src/clis/zhihu/search.ts +0 -65
- /package/dist/clis/zhihu/{search.d.ts → question.d.ts} +0 -0
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { cli, Strategy } from '../../registry.js';
|
|
2
|
-
import { fetchJson } from '../../bilibili.js';
|
|
3
|
-
cli({
|
|
4
|
-
site: 'zhihu',
|
|
5
|
-
name: 'search',
|
|
6
|
-
description: '搜索知乎问题和回答',
|
|
7
|
-
domain: 'www.zhihu.com',
|
|
8
|
-
strategy: Strategy.COOKIE,
|
|
9
|
-
args: [
|
|
10
|
-
{ name: 'keyword', required: true, help: 'Search keyword' },
|
|
11
|
-
{ name: 'type', default: 'general', help: 'general, article, video' },
|
|
12
|
-
{ name: 'limit', type: 'int', default: 20, help: 'Number of results' },
|
|
13
|
-
],
|
|
14
|
-
columns: ['rank', 'title', 'author', 'type', 'url'],
|
|
15
|
-
func: async (page, kwargs) => {
|
|
16
|
-
const { keyword, type = 'general', limit = 20 } = kwargs;
|
|
17
|
-
// Navigate to zhihu to ensure cookie context
|
|
18
|
-
await page.goto('https://www.zhihu.com');
|
|
19
|
-
const qs = new URLSearchParams({ q: keyword, type, limit: String(limit) });
|
|
20
|
-
const payload = await fetchJson(page, `https://www.zhihu.com/api/v4/search_v3?${qs}`);
|
|
21
|
-
const data = payload?.data ?? [];
|
|
22
|
-
const rows = [];
|
|
23
|
-
for (let i = 0; i < Math.min(data.length, Number(limit)); i++) {
|
|
24
|
-
const item = data[i];
|
|
25
|
-
const obj = item.object ?? item;
|
|
26
|
-
const itemType = item.type ?? obj.type ?? 'unknown';
|
|
27
|
-
let title = '';
|
|
28
|
-
let author = '';
|
|
29
|
-
let url = '';
|
|
30
|
-
if (itemType === 'search_result') {
|
|
31
|
-
const highlight = obj.highlight ?? {};
|
|
32
|
-
title = (highlight.title ?? obj.title ?? '').replace(/<[^>]+>/g, '');
|
|
33
|
-
author = obj.author?.name ?? '';
|
|
34
|
-
url = obj.url ?? '';
|
|
35
|
-
}
|
|
36
|
-
else if (obj.question) {
|
|
37
|
-
title = (obj.question.title ?? obj.title ?? '').replace(/<[^>]+>/g, '');
|
|
38
|
-
author = obj.author?.name ?? '';
|
|
39
|
-
url = obj.question.url ? `https://www.zhihu.com/question/${obj.question.id}` : '';
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
title = (obj.title ?? obj.name ?? '').replace(/<[^>]+>/g, '');
|
|
43
|
-
author = obj.author?.name ?? '';
|
|
44
|
-
url = obj.url ?? '';
|
|
45
|
-
}
|
|
46
|
-
if (!title)
|
|
47
|
-
continue;
|
|
48
|
-
rows.push({
|
|
49
|
-
rank: rows.length + 1,
|
|
50
|
-
title: title.slice(0, 60),
|
|
51
|
-
author,
|
|
52
|
-
type: itemType.replace('search_result', 'result'),
|
|
53
|
-
url,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return rows;
|
|
57
|
-
},
|
|
58
|
-
});
|
package/src/clis/zhihu/search.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { cli, Strategy } from '../../registry.js';
|
|
2
|
-
import { fetchJson } from '../../bilibili.js';
|
|
3
|
-
|
|
4
|
-
cli({
|
|
5
|
-
site: 'zhihu',
|
|
6
|
-
name: 'search',
|
|
7
|
-
description: '搜索知乎问题和回答',
|
|
8
|
-
domain: 'www.zhihu.com',
|
|
9
|
-
strategy: Strategy.COOKIE,
|
|
10
|
-
args: [
|
|
11
|
-
{ name: 'keyword', required: true, help: 'Search keyword' },
|
|
12
|
-
{ name: 'type', default: 'general', help: 'general, article, video' },
|
|
13
|
-
{ name: 'limit', type: 'int', default: 20, help: 'Number of results' },
|
|
14
|
-
],
|
|
15
|
-
columns: ['rank', 'title', 'author', 'type', 'url'],
|
|
16
|
-
func: async (page, kwargs) => {
|
|
17
|
-
const { keyword, type = 'general', limit = 20 } = kwargs;
|
|
18
|
-
|
|
19
|
-
// Navigate to zhihu to ensure cookie context
|
|
20
|
-
await page.goto('https://www.zhihu.com');
|
|
21
|
-
|
|
22
|
-
const qs = new URLSearchParams({ q: keyword, type, limit: String(limit) });
|
|
23
|
-
const payload = await fetchJson(page, `https://www.zhihu.com/api/v4/search_v3?${qs}`);
|
|
24
|
-
|
|
25
|
-
const data: any[] = payload?.data ?? [];
|
|
26
|
-
const rows: any[] = [];
|
|
27
|
-
|
|
28
|
-
for (let i = 0; i < Math.min(data.length, Number(limit)); i++) {
|
|
29
|
-
const item = data[i];
|
|
30
|
-
const obj = item.object ?? item;
|
|
31
|
-
const itemType = item.type ?? obj.type ?? 'unknown';
|
|
32
|
-
|
|
33
|
-
let title = '';
|
|
34
|
-
let author = '';
|
|
35
|
-
let url = '';
|
|
36
|
-
|
|
37
|
-
if (itemType === 'search_result') {
|
|
38
|
-
const highlight = obj.highlight ?? {};
|
|
39
|
-
title = (highlight.title ?? obj.title ?? '').replace(/<[^>]+>/g, '');
|
|
40
|
-
author = obj.author?.name ?? '';
|
|
41
|
-
url = obj.url ?? '';
|
|
42
|
-
} else if (obj.question) {
|
|
43
|
-
title = (obj.question.title ?? obj.title ?? '').replace(/<[^>]+>/g, '');
|
|
44
|
-
author = obj.author?.name ?? '';
|
|
45
|
-
url = obj.question.url ? `https://www.zhihu.com/question/${obj.question.id}` : '';
|
|
46
|
-
} else {
|
|
47
|
-
title = (obj.title ?? obj.name ?? '').replace(/<[^>]+>/g, '');
|
|
48
|
-
author = obj.author?.name ?? '';
|
|
49
|
-
url = obj.url ?? '';
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (!title) continue;
|
|
53
|
-
|
|
54
|
-
rows.push({
|
|
55
|
-
rank: rows.length + 1,
|
|
56
|
-
title: title.slice(0, 60),
|
|
57
|
-
author,
|
|
58
|
-
type: itemType.replace('search_result', 'result'),
|
|
59
|
-
url,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return rows;
|
|
64
|
-
},
|
|
65
|
-
});
|
|
File without changes
|