From 9124dcc018a66158e52dc5a452fe29474f6e6276 Mon Sep 17 00:00:00 2001 From: jackwener Date: Sun, 15 Mar 2026 07:30:35 +0800 Subject: [PATCH] chore: clean up duplicate adapters - Remove xiaohongshu/search.yaml (keep .ts with XHR interception) - Remove zhihu/search.ts (keep .yaml, self-contained) - Clean ~/.opencli/clis/ generated candidates (5 dirs) 24 commands across 8 sites, no duplicates --- src/clis/xiaohongshu/search.yaml | 36 ------------------ src/clis/zhihu/search.ts | 65 -------------------------------- 2 files changed, 101 deletions(-) delete mode 100644 src/clis/xiaohongshu/search.yaml delete mode 100644 src/clis/zhihu/search.ts diff --git a/src/clis/xiaohongshu/search.yaml b/src/clis/xiaohongshu/search.yaml deleted file mode 100644 index cccee67..0000000 --- a/src/clis/xiaohongshu/search.yaml +++ /dev/null @@ -1,36 +0,0 @@ -site: xiaohongshu -name: search -description: "小红书搜索 (via Pinia Store Action)" -domain: www.xiaohongshu.com -strategy: intercept -browser: true - -args: - keyword: - type: str - required: true - description: Search keyword - limit: - type: int - default: 20 - description: Number of items to return - -columns: [title, author, likes, type, url] - -pipeline: - - navigate: https://www.xiaohongshu.com/search_result?keyword=${{ args.keyword }}&source=web_search_result_notes - - wait: 3 - - tap: - store: search - action: fetchResult - capture: search/notes - select: data.items - timeout: 8 - - map: - id: ${{ item.id }} - title: ${{ item.note_card.display_title }} - type: ${{ item.note_card.type }} - author: ${{ item.note_card.user.nickname }} - likes: ${{ item.note_card.interact_info.liked_count }} - url: https://www.xiaohongshu.com/explore/${{ item.id }} - - limit: ${{ args.limit | default(20) }} diff --git a/src/clis/zhihu/search.ts b/src/clis/zhihu/search.ts deleted file mode 100644 index e16e73b..0000000 --- a/src/clis/zhihu/search.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { cli, Strategy } from '../../registry.js'; -import { fetchJson } from '../../bilibili.js'; - -cli({ - site: 'zhihu', - name: 'search', - description: '搜索知乎问题和回答', - domain: 'www.zhihu.com', - strategy: Strategy.COOKIE, - args: [ - { name: 'keyword', required: true, help: 'Search keyword' }, - { name: 'type', default: 'general', help: 'general, article, video' }, - { name: 'limit', type: 'int', default: 20, help: 'Number of results' }, - ], - columns: ['rank', 'title', 'author', 'type', 'url'], - func: async (page, kwargs) => { - const { keyword, type = 'general', limit = 20 } = kwargs; - - // Navigate to zhihu to ensure cookie context - await page.goto('https://www.zhihu.com'); - - const qs = new URLSearchParams({ q: keyword, type, limit: String(limit) }); - const payload = await fetchJson(page, `https://www.zhihu.com/api/v4/search_v3?${qs}`); - - const data: any[] = payload?.data ?? []; - const rows: any[] = []; - - for (let i = 0; i < Math.min(data.length, Number(limit)); i++) { - const item = data[i]; - const obj = item.object ?? item; - const itemType = item.type ?? obj.type ?? 'unknown'; - - let title = ''; - let author = ''; - let url = ''; - - if (itemType === 'search_result') { - const highlight = obj.highlight ?? {}; - title = (highlight.title ?? obj.title ?? '').replace(/<[^>]+>/g, ''); - author = obj.author?.name ?? ''; - url = obj.url ?? ''; - } else if (obj.question) { - title = (obj.question.title ?? obj.title ?? '').replace(/<[^>]+>/g, ''); - author = obj.author?.name ?? ''; - url = obj.question.url ? `https://www.zhihu.com/question/${obj.question.id}` : ''; - } else { - title = (obj.title ?? obj.name ?? '').replace(/<[^>]+>/g, ''); - author = obj.author?.name ?? ''; - url = obj.url ?? ''; - } - - if (!title) continue; - - rows.push({ - rank: rows.length + 1, - title: title.slice(0, 60), - author, - type: itemType.replace('search_result', 'result'), - url, - }); - } - - return rows; - }, -});