dsh-featured 0.0.0-stage → 0.1.0
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/README.md +79 -2
- package/cordis.patch.yml +8 -0
- package/icon.svg +4 -0
- package/lib/client.js +715 -0
- package/lib/index.js +256 -0
- package/locale/en.json +4 -0
- package/locale/zh.json +4 -0
- package/package.json +51 -4
package/README.md
CHANGED
|
@@ -1,3 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 精选插件
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**发现好插件,只需要一个入口。**
|
|
4
|
+
|
|
5
|
+
DSH 的好东西散落在各处——有的藏在 GitHub,有的只在群里传,有的名字平平无奇但用起来离不开。**精选插件**把社区里真正值得用的插件收进一个清单,打开插件页就能逛、能搜、能一键装上。
|
|
6
|
+
|
|
7
|
+
> 装上它之后,你大概就不会想卸载了。
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 你会得到什么
|
|
12
|
+
|
|
13
|
+
**一个标签页,逛完全部好货**
|
|
14
|
+
|
|
15
|
+
打开「插件」页面,点「精选插件」——卡片瀑布流铺开,每个插件都带图标、简介、版本号和截图预览。不用一个个去翻 GitHub README。
|
|
16
|
+
|
|
17
|
+
**搜得到,筛得准**
|
|
18
|
+
|
|
19
|
+
- 顶部搜索框:输名字、简介或者标签,边打边过滤
|
|
20
|
+
- 标签栏:想看「数据库」相关的?点一下就够了
|
|
21
|
+
- 已装过的插件,右上角直接标「✓ 已安装」,不会重复装
|
|
22
|
+
|
|
23
|
+
**点一下,就装好了**
|
|
24
|
+
|
|
25
|
+
不用填包名、不用复制命令、不用确认一堆弹窗。点「安装」,进度条就开始走。
|
|
26
|
+
|
|
27
|
+
**先看 README,再决定**
|
|
28
|
+
|
|
29
|
+
点插件标题,弹窗里直接显示它的完整说明文档——排版整齐,图片、表格、链接都正常。看完再装,不踩坑。
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 不用它的时候
|
|
34
|
+
|
|
35
|
+
不装它也完全没关系。
|
|
36
|
+
|
|
37
|
+
如果你用过某些内置了这个板块的插件,点开「精选插件」时会**自动帮你装好完整版**——你什么都不用做。
|
|
38
|
+
|
|
39
|
+
偶尔屏幕上多一个标签页?那是「精选插件」在正常工作。不喜欢的话,在插件列表里把它卸掉就好,下次也不会再自动装。
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 里面有什么
|
|
44
|
+
|
|
45
|
+
目前收录了社区里口碑最稳的一批:
|
|
46
|
+
|
|
47
|
+
| 插件 | 一句话 |
|
|
48
|
+
|---|---|
|
|
49
|
+
| **TokenBank 免费模型** | 白嫖各家大模型的免费额度 |
|
|
50
|
+
| **百万上下文** | 把超长对话压进模型窗口 |
|
|
51
|
+
| **远程控制** | 手机/浏览器远程操作桌面 |
|
|
52
|
+
| **技能市场** | 一键装其他开发者写的技能 |
|
|
53
|
+
| **数据源** | 让 AI 直连 MySQL / PostgreSQL |
|
|
54
|
+
| **代码版本管理** | 在对话里直接看 diff、提交代码 |
|
|
55
|
+
| **网页工具箱** | 侧边栏内置浏览器,点哪抓哪 |
|
|
56
|
+
| **终端栏** | 侧边栏常驻命令行 |
|
|
57
|
+
| **项目汇报** | 按 git 提交自动生成日报 |
|
|
58
|
+
|
|
59
|
+
清单一直在长。看到好用的插件,清单里没有?点右上角 **「申请收录」**,提个 PR 就行。
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 常见问题
|
|
64
|
+
|
|
65
|
+
**会收集我的数据吗?**
|
|
66
|
+
不会。清单是公开的,你装了什么只记录在本机,用来显示「已安装」标记。
|
|
67
|
+
|
|
68
|
+
**插件列表是写死的吗?**
|
|
69
|
+
不是。清单从公开仓库实时拉取,新插件进来你刷新页面就能看到,不用等更新。
|
|
70
|
+
|
|
71
|
+
**我可以只装某几个插件吗?**
|
|
72
|
+
当然。这里只是逛街的地方,装不装、装哪个,完全看你。
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## 关于
|
|
77
|
+
|
|
78
|
+
由 [skillpie](https://github.com/skillpie) 维护,精选清单一并维护在 [GitHub 仓库](https://github.com/skillpie/dsh-plugins)。
|
|
79
|
+
|
|
80
|
+
有问题、有建议、想把自己的插件放进来,都欢迎来仓库提 issue 或 PR。
|
package/cordis.patch.yml
ADDED
package/icon.svg
ADDED
package/lib/client.js
ADDED
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
// dsh-featured — 精选插件 client 半。
|
|
2
|
+
//
|
|
3
|
+
// 正式 DSH bundle:向官方插件页 plugins.tab 槽注册「精选插件」tab,
|
|
4
|
+
// 带搜索栏、标签筛选、申请收录入口与 README 详情弹窗。
|
|
5
|
+
//
|
|
6
|
+
// 与内联版(dsh-plugins-plugin)的关系:
|
|
7
|
+
// - 两者用同一个 slot id `dsh-plugins-plugin`,页面只显示一个 tab;
|
|
8
|
+
// - 本插件启动时若发现内联版已注册,先调它的 disposer 注销(GitHub 上挂
|
|
9
|
+
// window.__DSH_FEATURED_ENTRY__),再注册完整版 —— 干净替换,不靠 priority 遮蔽。
|
|
10
|
+
// - 内联版保持原样不动(已发布,有人下载);本插件装上后自动接管。
|
|
11
|
+
window.__ModuleLoader__.load({
|
|
12
|
+
id: 'dsh-featured',
|
|
13
|
+
factory(require) {
|
|
14
|
+
const React = require('react')
|
|
15
|
+
|
|
16
|
+
const h = React.createElement
|
|
17
|
+
|
|
18
|
+
const NS = 'dsh-featured'
|
|
19
|
+
const ROUTE = '/dsh-featured/featured'
|
|
20
|
+
// 数据统一由宿主半提供:host 拉远程集中目录(node fetch,无浏览器缓存/CORS)
|
|
21
|
+
// 并合并接入插件登记源,client 只读本地路由,永远新鲜。
|
|
22
|
+
|
|
23
|
+
function fetchJson(url, timeoutMs) {
|
|
24
|
+
const ctrl = typeof AbortController === 'function' ? new AbortController() : null
|
|
25
|
+
const timer = setTimeout(() => ctrl && ctrl.abort(), timeoutMs)
|
|
26
|
+
return fetch(url, { cache: 'no-store', headers: { accept: 'application/json' }, signal: ctrl ? ctrl.signal : undefined })
|
|
27
|
+
.then((res) => {
|
|
28
|
+
if (!res.ok) throw new Error('HTTP ' + res.status)
|
|
29
|
+
return res.json()
|
|
30
|
+
})
|
|
31
|
+
.finally(() => clearTimeout(timer))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function fetchText(url, timeoutMs) {
|
|
35
|
+
const ctrl = typeof AbortController === 'function' ? new AbortController() : null
|
|
36
|
+
const timer = setTimeout(() => ctrl && ctrl.abort(), timeoutMs)
|
|
37
|
+
return fetch(url, { cache: 'no-store', signal: ctrl ? ctrl.signal : undefined })
|
|
38
|
+
.then((res) => {
|
|
39
|
+
if (!res.ok) throw new Error('HTTP ' + res.status)
|
|
40
|
+
return res.text()
|
|
41
|
+
})
|
|
42
|
+
.finally(() => clearTimeout(timer))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 远程条目规范化(与 host 半 normalizeEntry 对齐的宽松版)。
|
|
46
|
+
// 富字段(author/stars/downloads/screenshots 等)由 scripts/enrich.mjs
|
|
47
|
+
// 在构建期从 awesome-dsh-plugin 官方目录 join 进来,这里原样放行。
|
|
48
|
+
function normalizeRemoteEntry(raw) {
|
|
49
|
+
if (!raw || typeof raw !== 'object') return null
|
|
50
|
+
const pkg = String(raw.package || raw.name || '').trim()
|
|
51
|
+
const title = String(raw.title || '').trim()
|
|
52
|
+
if (!pkg || !title) return null
|
|
53
|
+
const entry = { package: pkg, title, source: 'plugins.json' }
|
|
54
|
+
for (const key of ['description', 'version', 'icon', 'homepage', 'author', 'category']) {
|
|
55
|
+
const v = String(raw[key] || '').trim()
|
|
56
|
+
if (v) entry[key] = v
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(raw.screenshots)) {
|
|
59
|
+
const shots = raw.screenshots.map((x) => String(x).trim()).filter(Boolean).slice(0, 2)
|
|
60
|
+
if (shots.length) entry.screenshots = shots
|
|
61
|
+
}
|
|
62
|
+
if (typeof raw.stars === 'number' && raw.stars >= 0) entry.stars = raw.stars
|
|
63
|
+
if (typeof raw.downloads === 'number' && raw.downloads >= 0) entry.downloads = raw.downloads
|
|
64
|
+
if (Array.isArray(raw.tags)) {
|
|
65
|
+
const tags = raw.tags.map((x) => String(x).trim()).filter(Boolean).slice(0, 8)
|
|
66
|
+
if (tags.length) entry.tags = tags
|
|
67
|
+
}
|
|
68
|
+
return entry
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 数值缩写:586200 → 586.2k,1200000 → 1.2m。
|
|
72
|
+
function fmtCount(n) {
|
|
73
|
+
if (n >= 1e6) return (Math.round(n / 1e5) / 10) + 'm'
|
|
74
|
+
if (n >= 1e3) return (Math.round(n / 100) / 10) + 'k'
|
|
75
|
+
return String(n)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// raw.githubusercontent 在国内常不可达;转 jsdelivr gh 镜像再失败则放弃。
|
|
79
|
+
function shotCandidates(url) {
|
|
80
|
+
const match = String(url).match(/^https?:\/\/raw\.githubusercontent\.com\/([^/]+)\/([^/]+)\/(HEAD|[0-9a-fA-F]{6,}|[^/]+)\/(.+)$/)
|
|
81
|
+
if (!match) return [url]
|
|
82
|
+
const [, owner, repo, ref, file] = match
|
|
83
|
+
const branch = ref === 'HEAD' ? 'main' : ref
|
|
84
|
+
return [
|
|
85
|
+
`https://cdn.jsdelivr.net/gh/${owner}/${repo}@${branch}/${file}`,
|
|
86
|
+
url,
|
|
87
|
+
`https://cdn.jsdelivr.net/gh/${owner}/${repo}@master/${file}`,
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 合并已移到宿主半(host 侧远程目录 + 登记源,按包名去重)。
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
const zh = {
|
|
95
|
+
tabLabel: '精选插件',
|
|
96
|
+
install: '安装',
|
|
97
|
+
installed: '已安装',
|
|
98
|
+
installed_short: '✓ 已安装',
|
|
99
|
+
loading: '加载中…',
|
|
100
|
+
error: '加载失败',
|
|
101
|
+
retry: '重试',
|
|
102
|
+
empty: '暂无精选内容',
|
|
103
|
+
searchPlaceholder: '搜索插件名称、简介或标签…',
|
|
104
|
+
allTags: '全部',
|
|
105
|
+
apply: '申请收录',
|
|
106
|
+
count: (n) => `${n} 个插件`,
|
|
107
|
+
noMatch: '没有匹配的插件,换个关键词试试',
|
|
108
|
+
recommendedBy: '推荐',
|
|
109
|
+
close: '关闭',
|
|
110
|
+
readmeLoading: 'README 加载中…',
|
|
111
|
+
readmeError: 'README 读取失败',
|
|
112
|
+
applyTitle: '申请收录到精选插件',
|
|
113
|
+
applyDesc: '精选插件列表在 GitHub 仓库集中维护,提交一个 Pull Request 即可收录你的插件。',
|
|
114
|
+
applyStep1: 'Fork 仓库 skillpie/dsh-plugins',
|
|
115
|
+
applyStep2: '在 plugins.json 的 entries 里加一条',
|
|
116
|
+
applyStep3: '提交 Pull Request,等待合并后自动生效',
|
|
117
|
+
applyOpen: '打开仓库',
|
|
118
|
+
applyOk: '知道了',
|
|
119
|
+
exampleTitle: '示例条目',
|
|
120
|
+
}
|
|
121
|
+
const en = {
|
|
122
|
+
tabLabel: 'Featured',
|
|
123
|
+
install: 'Install',
|
|
124
|
+
installed: 'Installed',
|
|
125
|
+
installed_short: '✓ Installed',
|
|
126
|
+
loading: 'Loading…',
|
|
127
|
+
error: 'Failed to load',
|
|
128
|
+
retry: 'Retry',
|
|
129
|
+
empty: 'Nothing featured yet',
|
|
130
|
+
searchPlaceholder: 'Search by name, description or tag…',
|
|
131
|
+
allTags: 'All',
|
|
132
|
+
apply: 'Submit plugin',
|
|
133
|
+
count: (n) => `${n} plugin${n === 1 ? '' : 's'}`,
|
|
134
|
+
noMatch: 'No plugin matches your search',
|
|
135
|
+
recommendedBy: 'Recommended by',
|
|
136
|
+
close: 'Close',
|
|
137
|
+
readmeLoading: 'Loading README…',
|
|
138
|
+
readmeError: 'Failed to load README',
|
|
139
|
+
applyTitle: 'Submit your plugin',
|
|
140
|
+
applyDesc: 'The featured list is maintained in a GitHub repository. Open a Pull Request to add yours.',
|
|
141
|
+
applyStep1: 'Fork skillpie/dsh-plugins',
|
|
142
|
+
applyStep2: 'Add an entry to entries in plugins.json',
|
|
143
|
+
applyStep3: 'Open a Pull Request; it goes live once merged',
|
|
144
|
+
applyOpen: 'Open repository',
|
|
145
|
+
applyOk: 'Got it',
|
|
146
|
+
exampleTitle: 'Example entry',
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const S = {
|
|
150
|
+
wrap: { padding: '12px 0 24px', display: 'flex', flexDirection: 'column', gap: 12 },
|
|
151
|
+
// 官方 Discover 同款瀑布流:CSS 多列,卡片高度不一自然堆叠
|
|
152
|
+
grid: { listStyle: 'none', margin: 0, padding: 0, columns: '300px', columnGap: 12 },
|
|
153
|
+
card: {
|
|
154
|
+
breakInside: 'avoid', WebkitColumnBreakInside: 'avoid', marginBottom: 12,
|
|
155
|
+
display: 'flex', flexDirection: 'column', gap: 8, padding: 14,
|
|
156
|
+
border: '1px solid var(--dsw-alias-border-l1)',
|
|
157
|
+
borderRadius: 12, background: 'var(--dsw-alias-bg-layer-2)',
|
|
158
|
+
},
|
|
159
|
+
head: { display: 'flex', alignItems: 'center', gap: 8, minWidth: 0 },
|
|
160
|
+
// 插件名 + GitHub 图标紧贴成组,右侧留给 安装按钮/已安装徽标
|
|
161
|
+
nameWrap: { display: 'flex', alignItems: 'center', gap: 6, minWidth: 0, flex: '1 1 auto' },
|
|
162
|
+
title: {
|
|
163
|
+
fontSize: 15, fontWeight: 600, color: 'var(--dsw-alias-label-primary)', minWidth: 0,
|
|
164
|
+
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', cursor: 'pointer',
|
|
165
|
+
},
|
|
166
|
+
ghLink: { display: 'flex', flex: 'none', color: 'var(--dsw-alias-label-secondary)', textDecoration: 'none' },
|
|
167
|
+
ghIcon: { width: 15, height: 15, fill: 'currentColor' },
|
|
168
|
+
badge: { flex: 'none', fontSize: 12, color: 'var(--dsw-alias-state-success-primary)' },
|
|
169
|
+
iconS: { width: 20, height: 20, borderRadius: 6, objectFit: 'contain', flex: 'none', display: 'block' },
|
|
170
|
+
// 作者行 + 数据行合并为一行:左头像+作者,右 v·↓·★
|
|
171
|
+
authorRow: { display: 'flex', alignItems: 'center', gap: 6, minWidth: 0, marginTop: -4, cursor: 'pointer' },
|
|
172
|
+
avatar: { width: 14, height: 14, borderRadius: 999, flex: 'none', display: 'block' },
|
|
173
|
+
author: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
174
|
+
meta: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)', flex: 'none', marginLeft: 'auto' },
|
|
175
|
+
desc: {
|
|
176
|
+
margin: 0, fontSize: 13, lineHeight: 1.6, color: 'var(--dsw-alias-label-primary)', cursor: 'pointer',
|
|
177
|
+
display: '-webkit-box', WebkitLineClamp: 4, WebkitBoxOrient: 'vertical', overflow: 'hidden',
|
|
178
|
+
},
|
|
179
|
+
shots: { display: 'flex', gap: 8 },
|
|
180
|
+
shot: {
|
|
181
|
+
display: 'block', flex: 1, minWidth: 0, height: 104, objectFit: 'cover', objectPosition: 'top',
|
|
182
|
+
borderRadius: 8, border: '1px solid var(--dsw-alias-border-l1)', background: 'var(--dsw-alias-bg-layer-1)', cursor: 'pointer',
|
|
183
|
+
},
|
|
184
|
+
foot: { display: 'flex', alignItems: 'center', gap: 8, marginTop: 'auto', paddingTop: 4 },
|
|
185
|
+
chips: { display: 'flex', flexWrap: 'wrap', gap: 6, flex: '1 1 auto', minWidth: 0 },
|
|
186
|
+
chip: { fontSize: 12, padding: '3px 10px', borderRadius: 999, border: '1px solid var(--dsw-alias-border-l1)', color: 'var(--dsw-alias-label-primary)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', maxWidth: 180 },
|
|
187
|
+
src: { fontSize: 11, color: 'var(--dsw-alias-label-secondary)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
188
|
+
btn: {
|
|
189
|
+
flex: 'none', cursor: 'pointer', font: 'inherit', fontSize: 12,
|
|
190
|
+
padding: '4px 14px', borderRadius: 8, border: '1px solid var(--dsw-alias-border-l1)',
|
|
191
|
+
background: 'var(--dsw-alias-bg-layer-1)', color: 'var(--dsw-alias-label-primary)',
|
|
192
|
+
},
|
|
193
|
+
btnBusy: { opacity: 0.6, cursor: 'default' },
|
|
194
|
+
note: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-label-secondary)' },
|
|
195
|
+
retryBtn: {
|
|
196
|
+
alignSelf: 'flex-start', cursor: 'pointer', font: 'inherit', fontSize: 12,
|
|
197
|
+
padding: '4px 14px', borderRadius: 8, border: '1px solid var(--dsw-alias-border-l1)',
|
|
198
|
+
background: 'transparent', color: 'var(--dsw-alias-label-primary)',
|
|
199
|
+
},
|
|
200
|
+
// ── 自建详情弹窗(README 从 npm 包 jsdelivr 读取) ──
|
|
201
|
+
overlay: { position: 'fixed', inset: 0, zIndex: 1000, background: 'rgba(0,0,0,0.4)', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 24 },
|
|
202
|
+
panel: {
|
|
203
|
+
width: 'min(860px, 92vw)', maxHeight: '84vh', display: 'flex', flexDirection: 'column',
|
|
204
|
+
background: 'var(--dsw-alias-bg-layer-2)', border: '1px solid var(--dsw-alias-border-l1)',
|
|
205
|
+
borderRadius: 14, boxShadow: '0 12px 40px rgba(0,0,0,0.25)', overflow: 'hidden',
|
|
206
|
+
},
|
|
207
|
+
panelHead: { display: 'flex', alignItems: 'flex-start', gap: 12, padding: '16px 16px 12px' },
|
|
208
|
+
panelIcon: { width: 44, height: 44, borderRadius: 10, objectFit: 'contain', flex: 'none', background: 'var(--dsw-alias-bg-layer-1)' },
|
|
209
|
+
panelTitleCol: { display: 'flex', flexDirection: 'column', gap: 3, minWidth: 0, flex: '1 1 auto' },
|
|
210
|
+
panelTitle: { fontSize: 17, fontWeight: 600, color: 'var(--dsw-alias-label-primary)', margin: 0 },
|
|
211
|
+
panelPkg: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)', fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
212
|
+
panelClose: {
|
|
213
|
+
flex: 'none', cursor: 'pointer', font: 'inherit', fontSize: 12, border: 'none', background: 'transparent',
|
|
214
|
+
color: 'var(--dsw-alias-label-secondary)', padding: '4px 6px',
|
|
215
|
+
},
|
|
216
|
+
panelMeta: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap', padding: '0 16px 10px', fontSize: 12, color: 'var(--dsw-alias-label-secondary)' },
|
|
217
|
+
panelDesc: { margin: '0 16px 12px', fontSize: 13, lineHeight: 1.6, color: 'var(--dsw-alias-label-primary)' },
|
|
218
|
+
panelBody: { margin: '0 16px', borderTop: '1px solid var(--dsw-alias-border-l1)', padding: '14px 2px 18px', overflowY: 'auto', fontSize: 13, lineHeight: 1.7, color: 'var(--dsw-alias-label-primary)' },
|
|
219
|
+
mdNote: { margin: 0, fontSize: 12, color: 'var(--dsw-alias-label-secondary)' },
|
|
220
|
+
mdH: { fontSize: 15, fontWeight: 600, margin: '18px 0 8px' },
|
|
221
|
+
mdH2: { fontSize: 14, fontWeight: 600, margin: '16px 0 6px' },
|
|
222
|
+
mdP: { margin: '0 0 10px' },
|
|
223
|
+
mdList: { margin: '0 0 10px', paddingLeft: 20 },
|
|
224
|
+
mdLi: { margin: '0 0 4px' },
|
|
225
|
+
mdImg: { display: 'block', maxWidth: '100%', borderRadius: 8, border: '1px solid var(--dsw-alias-border-l1)', margin: '8px 0' },
|
|
226
|
+
mdCode: { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: 12, background: 'var(--dsw-alias-bg-layer-1)', borderRadius: 4, padding: '1px 5px' },
|
|
227
|
+
mdPre: { background: 'var(--dsw-alias-bg-layer-1)', border: '1px solid var(--dsw-alias-border-l1)', borderRadius: 8, padding: 12, overflowX: 'auto', margin: '0 0 10px' },
|
|
228
|
+
mdPreCode: { fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: 12, whiteSpace: 'pre-wrap', margin: 0 },
|
|
229
|
+
mdA: { color: 'var(--dsw-alias-link)' },
|
|
230
|
+
linkIcon: { width: 11, height: 11, marginRight: 3, verticalAlign: '-1px', color: 'var(--dsw-alias-link)' },
|
|
231
|
+
mdQuote: { borderLeft: '3px solid var(--dsw-alias-border-l1)', paddingLeft: 12, margin: '0 0 12px', color: 'var(--dsw-alias-label-secondary)' },
|
|
232
|
+
mdTable: { borderCollapse: 'collapse', width: '100%', margin: '0 0 12px', fontSize: 12.5 },
|
|
233
|
+
mdTd: { border: '1px solid var(--dsw-alias-border-l1)', padding: '6px 10px', textAlign: 'left', verticalAlign: 'top' },
|
|
234
|
+
// ── 完整版工具栏:搜索栏 + 标签筛选 + 申请收录入口 ──
|
|
235
|
+
toolbar: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' },
|
|
236
|
+
search: {
|
|
237
|
+
flex: '1 1 220px', minWidth: 160, font: 'inherit', fontSize: 13, padding: '6px 10px',
|
|
238
|
+
border: '1px solid var(--dsw-alias-border-l1)', borderRadius: 8,
|
|
239
|
+
background: 'var(--dsw-alias-bg-layer-1)', color: 'var(--dsw-alias-label-primary)', outline: 'none',
|
|
240
|
+
},
|
|
241
|
+
tabBar: { display: 'flex', gap: 6, flexWrap: 'wrap', alignItems: 'center' },
|
|
242
|
+
tabBtn: {
|
|
243
|
+
cursor: 'pointer', font: 'inherit', fontSize: 12, padding: '4px 12px', borderRadius: 999,
|
|
244
|
+
border: '1px solid var(--dsw-alias-border-l1)', background: 'transparent', color: 'var(--dsw-alias-label-primary)',
|
|
245
|
+
},
|
|
246
|
+
tabBtnActive: {
|
|
247
|
+
cursor: 'pointer', font: 'inherit', fontSize: 12, padding: '4px 12px', borderRadius: 999,
|
|
248
|
+
border: '1px solid var(--dsw-alias-border-l1)', background: 'var(--dsw-alias-bg-layer-1)', color: 'var(--dsw-alias-label-primary)', fontWeight: 600,
|
|
249
|
+
},
|
|
250
|
+
applyBtn: {
|
|
251
|
+
flex: 'none', cursor: 'pointer', font: 'inherit', fontSize: 12, padding: '5px 12px', borderRadius: 8,
|
|
252
|
+
border: '1px solid var(--dsw-alias-border-l1)', background: 'transparent', color: 'var(--dsw-alias-label-primary)',
|
|
253
|
+
},
|
|
254
|
+
count: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)', flex: 'none' },
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// GitHub mark(octicon mark-github 16x16 路径)
|
|
258
|
+
const GH_PATH = 'M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27s1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z'
|
|
259
|
+
|
|
260
|
+
// 包名行:npm 包名(左,等宽)+ 数据(右,同行);整行可点开详情弹窗。
|
|
261
|
+
// 不展示作者信息(不依赖 awesome-dsh-plugin 的 author 字段)。
|
|
262
|
+
function FeaturedAuthor(props) {
|
|
263
|
+
const pkg = props.pkg
|
|
264
|
+
const meta = props.meta
|
|
265
|
+
const onDetail = props.onDetail
|
|
266
|
+
if (!pkg && !meta) return null
|
|
267
|
+
return h('div', { style: S.authorRow, onClick: onDetail },
|
|
268
|
+
pkg ? h('span', { style: S.author }, pkg) : null,
|
|
269
|
+
meta ? h('span', { style: S.meta }, meta) : null)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// 截图:逐个候选地址回退(jsdelivr gh 镜像 → 原始 raw → master 分支),全失败则隐藏。
|
|
273
|
+
function FeaturedShot(props) {
|
|
274
|
+
const url = props.url
|
|
275
|
+
const pair = React.useState(0)
|
|
276
|
+
const idx = pair[0], setIdx = pair[1]
|
|
277
|
+
const candidates = React.useMemo(() => shotCandidates(url), [url])
|
|
278
|
+
if (idx >= candidates.length) return null
|
|
279
|
+
return h('img', {
|
|
280
|
+
src: candidates[idx], alt: '', style: S.shot, loading: 'lazy',
|
|
281
|
+
onError: () => setIdx(idx + 1),
|
|
282
|
+
onClick: () => window.open(candidates[idx], '_blank', 'noopener'),
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// 卡片布局对齐官方 Discover:
|
|
287
|
+
// 标题行(标题 + GitHub 链接) → 作者行(头像+作者) → 数据行(v·↓·★)
|
|
288
|
+
// → 简介(4 行截断) → 截图(≤2) → 脚行(标签 chips + 安装按钮)。
|
|
289
|
+
// 卡片首行插件图标:候选地址逐个回退(jsdelivr gh 镜像优先),无 icon 或全失败不展示。
|
|
290
|
+
function FeaturedHeadIcon(props) {
|
|
291
|
+
const entry = props.entry
|
|
292
|
+
const pair = React.useState(0)
|
|
293
|
+
const idx = pair[0], setIdx = pair[1]
|
|
294
|
+
const candidates = React.useMemo(() => (entry.icon ? shotCandidates(entry.icon) : []), [entry.icon])
|
|
295
|
+
if (!candidates.length || idx >= candidates.length) return null
|
|
296
|
+
return h('img', { src: candidates[idx], alt: '', style: props.large ? S.panelIcon : S.iconS, loading: 'lazy', onError: () => setIdx(idx + 1) })
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function FeaturedCard(props) {
|
|
300
|
+
const e = props.entry
|
|
301
|
+
const t = props.t
|
|
302
|
+
const install = props.install
|
|
303
|
+
const onDetail = props.onDetail // 打开自建详情弹窗
|
|
304
|
+
const installed = !!props.installed // 宿主侧 pluginManager.listBundles 判定
|
|
305
|
+
const pair = React.useState(false) // busy
|
|
306
|
+
const busy = pair[0], setBusy = pair[1]
|
|
307
|
+
const donePair = React.useState(false) // 本会话刚装过(仅避免重复点击)
|
|
308
|
+
const done = donePair[0], setDone = donePair[1]
|
|
309
|
+
|
|
310
|
+
const onClick = () => {
|
|
311
|
+
if (busy || done || typeof install !== 'function') return
|
|
312
|
+
setBusy(true)
|
|
313
|
+
try {
|
|
314
|
+
install({ spec: e.version ? `${e.package}@${e.version}` : e.package, title: e.title, version: e.version || '' })
|
|
315
|
+
setDone(true)
|
|
316
|
+
} finally {
|
|
317
|
+
setBusy(false)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const btnLabel = busy ? '…' : t('install')
|
|
322
|
+
const metaParts = []
|
|
323
|
+
if (e.version) metaParts.push(`v${e.version}`)
|
|
324
|
+
const metaText = metaParts.join(' · ')
|
|
325
|
+
|
|
326
|
+
const chips = (e.tags || []).slice(0, 2)
|
|
327
|
+
return h('li', { style: S.card },
|
|
328
|
+
h('div', { style: S.head },
|
|
329
|
+
h(FeaturedHeadIcon, { entry: e }),
|
|
330
|
+
h('div', { style: S.nameWrap },
|
|
331
|
+
h('span', { style: S.title, title: e.title, onClick: onDetail }, e.title),
|
|
332
|
+
e.homepage ? h('a', { style: S.ghLink, href: e.homepage, target: '_blank', rel: 'noreferrer noopener', title: e.package },
|
|
333
|
+
h('svg', { style: S.ghIcon, viewBox: '0 0 16 16', 'aria-hidden': 'true' }, h('path', { d: GH_PATH }))) : null),
|
|
334
|
+
// 右上角:已安装绿色徽标,否则安装按钮(参考 billion-context 卡片布局)
|
|
335
|
+
installed || done
|
|
336
|
+
? h('span', { style: S.badge }, `✓ ${t('installed')}`)
|
|
337
|
+
: h('button', {
|
|
338
|
+
type: 'button', style: Object.assign({}, S.btn, busy ? S.btnBusy : {}),
|
|
339
|
+
onClick, disabled: busy,
|
|
340
|
+
}, btnLabel)),
|
|
341
|
+
h(FeaturedAuthor, { pkg: e.package, meta: metaText, onDetail }),
|
|
342
|
+
e.description ? h('p', { style: S.desc, onClick: onDetail }, e.description) : null,
|
|
343
|
+
e.screenshots && e.screenshots.length
|
|
344
|
+
? h('div', { style: S.shots }, e.screenshots.map((url) => h(FeaturedShot, { key: url, url })))
|
|
345
|
+
: null,
|
|
346
|
+
h('div', { style: S.foot },
|
|
347
|
+
h('div', { style: S.chips },
|
|
348
|
+
chips.map((c) => h('span', { key: c, style: S.chip, title: c }, c)),
|
|
349
|
+
e.sourceTitle ? h('span', { style: S.src, title: `${t('recommendedBy')} ${e.sourceTitle}` }, `${t('recommendedBy')} ${e.sourceTitle}`) : null)))
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// ── 自建详情弹窗:README 从 npm 包(jsdelivr)读取,轻量 markdown 渲染 ──
|
|
353
|
+
// 相对路径的图片/链接重写到 jsdelivr 包根。
|
|
354
|
+
function mdAbsUrl(url, base) {
|
|
355
|
+
const u = String(url).trim()
|
|
356
|
+
if (/^https?:\/\//i.test(u)) return u
|
|
357
|
+
return base + u.replace(/^\.\//, '')
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// 占位符还原:把 s 里 \u0000<idx>\u0000 换回暂存的节点
|
|
361
|
+
function restoreInline(s, tokens) {
|
|
362
|
+
const parts = String(s).split(/\u0000(\d+)\u0000/g)
|
|
363
|
+
const out = []
|
|
364
|
+
for (let i = 0; i < parts.length; i++) {
|
|
365
|
+
if (i % 2 === 1) out.push(tokens[Number(parts[i])])
|
|
366
|
+
else if (parts[i]) out.push(parts[i])
|
|
367
|
+
}
|
|
368
|
+
return out
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// 行内解析(占位符两段式):
|
|
372
|
+
// 粗体 → 图片 → 链接 → 行内代码。图片先于链接,使 [](l) 外链图可用;
|
|
373
|
+
// 粗体内部递归解析,粗体套链接/链接套图片均正常。
|
|
374
|
+
function mdInline(text, base) {
|
|
375
|
+
const tokens = []
|
|
376
|
+
const stash = (node) => { tokens.push(node); return '\u0000' + (tokens.length - 1) + '\u0000' }
|
|
377
|
+
const stashText = (t) => { tokens.push(t); return '\u0000' + (tokens.length - 1) + '\u0000' }
|
|
378
|
+
// 链接统一形态:蓝色 + 前置地球图标(与官方 markdown 链接色一致)
|
|
379
|
+
const makeLink = (href, kids) => h('a', { style: S.mdA, href, target: '_blank', rel: 'noreferrer noopener' },
|
|
380
|
+
h('svg', { style: S.linkIcon, viewBox: '0 0 16 16', 'aria-hidden': 'true', fill: 'none', stroke: 'currentColor', 'stroke-width': '1.2' },
|
|
381
|
+
h('circle', { cx: 8, cy: 8, r: 6.3 }),
|
|
382
|
+
h('path', { d: 'M1.7 8h12.6M8 1.7c2.4 1.9 2.4 10.7 0 12.6M8 1.7c-2.4 1.9-2.4 10.7 0 12.6' })),
|
|
383
|
+
...kids)
|
|
384
|
+
let s = String(text)
|
|
385
|
+
s = s.replace(/\*\*([^*]+)\*\*/g, (m0, inner) => stash(h('strong', null, mdInline(inner, base))))
|
|
386
|
+
s = s.replace(/!\[([^\]]*)\]\(([^)\s]+)(?:\s+"[^"]*")?\)/g, (m0, alt, url) => stash(h('img', { style: S.mdImg, src: mdAbsUrl(url, base), alt: alt || '', loading: 'lazy' })))
|
|
387
|
+
s = s.replace(/\[([^\]]*)\]\(([^)\s]+)(?:\s+"[^"]*")?\)/g, (m0, label, url) => stash(makeLink(mdAbsUrl(url, base), restoreInline(label, tokens))))
|
|
388
|
+
s = s.replace(/`([^`]+)`/g, (m0, c) => stash(h('code', { style: S.mdCode }, c)))
|
|
389
|
+
// 裸自动链接:<https://…> 与 http(s)://…(URL 中间允许点/斜杠,仅结尾剔除标点)
|
|
390
|
+
const TRAIL_PUNCT = /([.,;:!?"'))\u3001\u3002\uff0c\uff1b\uff1a\uff01\uff1f\u201d\u2019]|[^\x20-\x7e])+$/
|
|
391
|
+
s = s.replace(/<(https?:\/\/[^>\s]+)>/g, (m0, url) => stash(makeLink(url, [url])))
|
|
392
|
+
s = s.replace(/(^|[\s(])(https?:\/\/[^\s<>()\u0000]+)/g, (m0, pre, rawUrl) => {
|
|
393
|
+
const trailMatch = TRAIL_PUNCT.exec(rawUrl)
|
|
394
|
+
const trail = trailMatch ? trailMatch[0] : ''
|
|
395
|
+
const url = trail ? rawUrl.slice(0, -trail.length) : rawUrl
|
|
396
|
+
return stashText(pre) + stash(makeLink(url, [url])) + (trail ? stashText(trail) : '')
|
|
397
|
+
})
|
|
398
|
+
return restoreInline(s, tokens)
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// 块级解析:围栏代码块 / 标题 / 列表 / 段落(不追求完整 markdown,够读 README 即可)
|
|
402
|
+
function renderReadme(text, base) {
|
|
403
|
+
const lines = String(text).split('\n')
|
|
404
|
+
const out = []
|
|
405
|
+
let key = 0, para = [], i = 0
|
|
406
|
+
const flushPara = () => {
|
|
407
|
+
if (para.length) {
|
|
408
|
+
out.push(h('p', { style: S.mdP, key: 'p' + (key++) }, mdInline(para.join(' '), base)))
|
|
409
|
+
para = []
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
while (i < lines.length) {
|
|
413
|
+
const line = lines[i]
|
|
414
|
+
if (/^```/.test(line)) {
|
|
415
|
+
flushPara()
|
|
416
|
+
const buf = []
|
|
417
|
+
i++
|
|
418
|
+
while (i < lines.length && !/^```/.test(lines[i])) { buf.push(lines[i]); i++ }
|
|
419
|
+
i++
|
|
420
|
+
out.push(h('pre', { style: S.mdPre, key: 'c' + (key++) }, h('code', { style: S.mdPreCode }, buf.join('\n'))))
|
|
421
|
+
continue
|
|
422
|
+
}
|
|
423
|
+
// 引用块(> 行,支持连续多行合并)
|
|
424
|
+
if (/^\s*>\s?/.test(line)) {
|
|
425
|
+
flushPara()
|
|
426
|
+
const buf = []
|
|
427
|
+
while (i < lines.length && /^\s*>\s?/.test(lines[i])) {
|
|
428
|
+
buf.push(lines[i].replace(/^\s*>\s?/, ''))
|
|
429
|
+
i++
|
|
430
|
+
}
|
|
431
|
+
out.push(h('div', { style: S.mdQuote, key: 'q' + (key++) },
|
|
432
|
+
h('p', { style: S.mdP }, mdInline(buf.join(' ').trim(), base))))
|
|
433
|
+
continue
|
|
434
|
+
}
|
|
435
|
+
// 表格(| 行,第二行为 |---| 分隔)
|
|
436
|
+
if (/^\s*\|/.test(line)) {
|
|
437
|
+
const block = []
|
|
438
|
+
while (i < lines.length && /^\s*\|/.test(lines[i])) { block.push(lines[i].trim()); i++ }
|
|
439
|
+
const cells = (row) => row.replace(/^\|/, '').replace(/\|$/, '').split('|').map((c) => c.trim())
|
|
440
|
+
const isSep = (row) => /^\|?[\s:|-]+\|?$/.test(row) && row.includes('-')
|
|
441
|
+
if (block.length >= 2 && isSep(block[1])) {
|
|
442
|
+
flushPara()
|
|
443
|
+
const head = cells(block[0])
|
|
444
|
+
const rows = block.slice(2).filter((r) => !isSep(r)).map(cells)
|
|
445
|
+
out.push(h('table', { style: S.mdTable, key: 't' + (key++) },
|
|
446
|
+
h('thead', null, h('tr', null, head.map((c) => h('th', { style: S.mdTd }, mdInline(c, base))))),
|
|
447
|
+
h('tbody', null, rows.map((r) => h('tr', null, head.map((_, ci) => h('td', { style: S.mdTd }, mdInline(r[ci] || '', base))))))))
|
|
448
|
+
continue
|
|
449
|
+
}
|
|
450
|
+
// 非法表格形态 → 按普通段落处理
|
|
451
|
+
for (const row of block) para.push(row)
|
|
452
|
+
continue
|
|
453
|
+
}
|
|
454
|
+
const hm = line.match(/^(#{1,4})\s+(.*)/)
|
|
455
|
+
if (hm) {
|
|
456
|
+
flushPara()
|
|
457
|
+
out.push(h(hm[1].length <= 2 ? 'h3' : 'h4', { style: hm[1].length <= 2 ? S.mdH : S.mdH2, key: 'h' + (key++) }, mdInline(hm[2], base)))
|
|
458
|
+
i++
|
|
459
|
+
continue
|
|
460
|
+
}
|
|
461
|
+
const lm = line.match(/^\s*(?:[-*+]|\d+[.)])\s+(.*)/)
|
|
462
|
+
if (lm) {
|
|
463
|
+
flushPara()
|
|
464
|
+
const items = []
|
|
465
|
+
while (i < lines.length) {
|
|
466
|
+
const m2 = lines[i].match(/^\s*(?:[-*+]|\d+[.)])\s+(.*)/)
|
|
467
|
+
if (!m2) break
|
|
468
|
+
items.push(h('li', { style: S.mdLi, key: 'li' + items.length }, mdInline(m2[1], base)))
|
|
469
|
+
i++
|
|
470
|
+
}
|
|
471
|
+
out.push(h('ul', { style: S.mdList, key: 'u' + (key++) }, items))
|
|
472
|
+
continue
|
|
473
|
+
}
|
|
474
|
+
if (!line.trim()) { flushPara(); i++; continue }
|
|
475
|
+
para.push(line.trim())
|
|
476
|
+
i++
|
|
477
|
+
}
|
|
478
|
+
flushPara()
|
|
479
|
+
return out
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function FeaturedModal(props) {
|
|
483
|
+
const e = props.entry
|
|
484
|
+
const t = props.t
|
|
485
|
+
const onClose = props.onClose
|
|
486
|
+
const pair = React.useState({ status: 'loading', kids: [] })
|
|
487
|
+
const state = pair[0], setState = pair[1]
|
|
488
|
+
|
|
489
|
+
React.useEffect(() => {
|
|
490
|
+
let alive = true
|
|
491
|
+
setState({ status: 'loading', kids: [] })
|
|
492
|
+
const base = `https://cdn.jsdelivr.net/npm/${e.package}/`
|
|
493
|
+
fetchText(base + 'README.md', 10000).then((txt) => {
|
|
494
|
+
if (!alive) return
|
|
495
|
+
setState({ status: 'ready', kids: renderReadme(txt, base) })
|
|
496
|
+
}).catch(() => {
|
|
497
|
+
if (!alive) return
|
|
498
|
+
// jsdelivr npm 主源失败 → GitHub 仓库兜底(README 大小写两种形态)
|
|
499
|
+
const ghCandidates = e.homepage && /^https?:\/\/github\.com\/([^/]+)\/([^/]+)/i.exec(e.homepage)
|
|
500
|
+
if (!ghCandidates) { setState({ status: 'error', kids: [] }); return }
|
|
501
|
+
const ghBase = `https://cdn.jsdelivr.net/gh/${ghCandidates[1]}/${ghCandidates[2]}@main/`
|
|
502
|
+
fetchText(ghBase + 'README.md', 10000).then((txt2) => {
|
|
503
|
+
if (!alive) return
|
|
504
|
+
setState({ status: 'ready', kids: renderReadme(txt2, ghBase) })
|
|
505
|
+
}).catch(() => { if (alive) setState({ status: 'error', kids: [] }) })
|
|
506
|
+
})
|
|
507
|
+
return () => { alive = false }
|
|
508
|
+
}, [e.package])
|
|
509
|
+
|
|
510
|
+
React.useEffect(() => {
|
|
511
|
+
const onKey = (ev) => { if (ev.key === 'Escape') onClose() }
|
|
512
|
+
window.addEventListener('keydown', onKey)
|
|
513
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
514
|
+
}, [onClose])
|
|
515
|
+
|
|
516
|
+
const metaParts = []
|
|
517
|
+
if (e.version) metaParts.push(`v${e.version}`)
|
|
518
|
+
return h('div', {
|
|
519
|
+
style: S.overlay,
|
|
520
|
+
onClick: (ev) => { if (ev.target === ev.currentTarget) onClose() },
|
|
521
|
+
},
|
|
522
|
+
h('div', { style: S.panel },
|
|
523
|
+
h('div', { style: S.panelHead },
|
|
524
|
+
h(FeaturedHeadIcon, { entry: e, large: true }),
|
|
525
|
+
h('div', { style: S.panelTitleCol },
|
|
526
|
+
h('p', { style: S.panelTitle }, e.title),
|
|
527
|
+
h('span', { style: S.panelPkg }, e.package)),
|
|
528
|
+
h('button', { type: 'button', style: S.panelClose, onClick: onClose }, '✕')),
|
|
529
|
+
metaParts.length ? h('div', { style: S.panelMeta }, metaParts.join(' · ')) : null,
|
|
530
|
+
e.description ? h('p', { style: S.panelDesc }, e.description) : null,
|
|
531
|
+
h('div', { style: S.panelBody },
|
|
532
|
+
state.status === 'loading' ? h('p', { style: S.mdNote }, t('readmeLoading')) : null,
|
|
533
|
+
state.status === 'error' ? h('p', { style: S.mdNote }, t('readmeError')) : null,
|
|
534
|
+
state.status === 'ready' ? state.kids : null),
|
|
535
|
+
h('div', { style: Object.assign({}, S.panelMeta, { justifyContent: 'flex-end', paddingTop: 10 }) },
|
|
536
|
+
h('button', { type: 'button', style: S.retryBtn, onClick: onClose }, t('close')))))
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
// ── 申请收录弹窗(GitHub PR 引导 + 可复制的 JSON 示例)──
|
|
541
|
+
function ApplyModal(props) {
|
|
542
|
+
const t = props.t
|
|
543
|
+
const onClose = props.onClose
|
|
544
|
+
React.useEffect(() => {
|
|
545
|
+
const onKey = (ev) => { if (ev.key === 'Escape') onClose() }
|
|
546
|
+
window.addEventListener('keydown', onKey)
|
|
547
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
548
|
+
}, [onClose])
|
|
549
|
+
const step = (n, text) => h('li', { key: 's' + n, style: S.mdLi }, text)
|
|
550
|
+
return h('div', {
|
|
551
|
+
style: S.overlay,
|
|
552
|
+
onClick: (ev) => { if (ev.target === ev.currentTarget) onClose() },
|
|
553
|
+
},
|
|
554
|
+
h('div', { style: S.panel },
|
|
555
|
+
h('div', { style: S.panelHead },
|
|
556
|
+
h('div', { style: S.panelTitleCol },
|
|
557
|
+
h('p', { style: S.panelTitle }, t('applyTitle')),
|
|
558
|
+
h('span', { style: S.panelPkg }, 'skillpie/dsh-plugins')),
|
|
559
|
+
h('button', { type: 'button', style: S.panelClose, onClick: onClose }, '✕')),
|
|
560
|
+
h('p', { style: S.panelDesc }, t('applyDesc')),
|
|
561
|
+
h('div', { style: S.panelBody },
|
|
562
|
+
h('ol', { style: S.mdList },
|
|
563
|
+
step(1, t('applyStep1')),
|
|
564
|
+
step(2, t('applyStep2')),
|
|
565
|
+
step(3, t('applyStep3'))),
|
|
566
|
+
h('p', { style: S.mdH2 }, t('exampleTitle')),
|
|
567
|
+
h('pre', { style: S.mdPre }, h('code', { style: S.mdPreCode }, {
|
|
568
|
+
"package": "dsh-my-plugin",
|
|
569
|
+
"title": "我的插件",
|
|
570
|
+
"description": "一句话说明它解决什么问题",
|
|
571
|
+
"version": "1.2.3",
|
|
572
|
+
"homepage": "https://github.com/me/dsh-my-plugin",
|
|
573
|
+
"tags": ["效率"]
|
|
574
|
+
}))),
|
|
575
|
+
h('div', { style: Object.assign({}, S.panelMeta, { justifyContent: 'flex-end', gap: 8, paddingTop: 10 }) },
|
|
576
|
+
h('a', {
|
|
577
|
+
style: Object.assign({}, S.retryBtn, { textDecoration: 'none', display: 'inline-block' }),
|
|
578
|
+
href: 'https://github.com/skillpie/dsh-plugins', target: '_blank', rel: 'noreferrer noopener',
|
|
579
|
+
}, t('applyOpen')),
|
|
580
|
+
h('button', { type: 'button', style: S.retryBtn, onClick: onClose }, t('applyOk')))))
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// ── tab 入口:搜索栏 + 标签筛选 + 申请收录 ──
|
|
584
|
+
function FeaturedSection(props) {
|
|
585
|
+
const install = props.install
|
|
586
|
+
void props.openPackage
|
|
587
|
+
const t = props.t
|
|
588
|
+
|
|
589
|
+
const pair = React.useState({ status: 'loading', entries: [], installed: {} })
|
|
590
|
+
const state = pair[0], setState = pair[1]
|
|
591
|
+
const noncePair = React.useState(0)
|
|
592
|
+
const nonce = noncePair[0], setNonce = noncePair[1]
|
|
593
|
+
const detailPair = React.useState(null)
|
|
594
|
+
const detail = detailPair[0], setDetail = detailPair[1]
|
|
595
|
+
const applyPair = React.useState(false)
|
|
596
|
+
const applyOpen = applyPair[0], setApplyOpen = applyPair[1]
|
|
597
|
+
const queryPair = React.useState('')
|
|
598
|
+
const query = queryPair[0], setQuery = queryPair[1]
|
|
599
|
+
const tagPair = React.useState('')
|
|
600
|
+
const activeTag = tagPair[0], setActiveTag = tagPair[1]
|
|
601
|
+
|
|
602
|
+
React.useEffect(() => {
|
|
603
|
+
let alive = true
|
|
604
|
+
setState({ status: 'loading', entries: [], installed: {} })
|
|
605
|
+
fetchJson(ROUTE, 8000).then((body) => {
|
|
606
|
+
if (!alive) return
|
|
607
|
+
const entries = body && body.ok && body.data && Array.isArray(body.data.entries)
|
|
608
|
+
? body.data.entries.map((raw) => {
|
|
609
|
+
const e = normalizeRemoteEntry(raw)
|
|
610
|
+
if (e && raw && raw.sourceTitle) e.sourceTitle = String(raw.sourceTitle)
|
|
611
|
+
return e
|
|
612
|
+
}).filter(Boolean)
|
|
613
|
+
: []
|
|
614
|
+
const installed = body && body.ok && body.data && body.data.installed && typeof body.data.installed === 'object'
|
|
615
|
+
? body.data.installed
|
|
616
|
+
: {}
|
|
617
|
+
setState({ status: entries.length ? 'ready' : 'empty', entries, installed })
|
|
618
|
+
}).catch(() => {
|
|
619
|
+
if (alive) setState({ status: 'error', entries: [], installed: {} })
|
|
620
|
+
})
|
|
621
|
+
return () => { alive = false }
|
|
622
|
+
}, [nonce])
|
|
623
|
+
|
|
624
|
+
// 标签集合:所有条目 tags 去重
|
|
625
|
+
const tags = React.useMemo(() => {
|
|
626
|
+
const set = []
|
|
627
|
+
for (const e of state.entries) {
|
|
628
|
+
for (const tg of (e.tags || [])) if (set.indexOf(tg) < 0) set.push(tg)
|
|
629
|
+
}
|
|
630
|
+
return set.slice(0, 12)
|
|
631
|
+
}, [state.entries])
|
|
632
|
+
|
|
633
|
+
// 过滤:搜索 + 标签
|
|
634
|
+
const visible = React.useMemo(() => {
|
|
635
|
+
const q = query.trim().toLowerCase()
|
|
636
|
+
return state.entries.filter((e) => {
|
|
637
|
+
if (activeTag && !(e.tags || []).includes(activeTag)) return false
|
|
638
|
+
if (!q) return true
|
|
639
|
+
const hay = [e.title, e.package, e.description, (e.tags || []).join(' ')].join(' ').toLowerCase()
|
|
640
|
+
return hay.includes(q)
|
|
641
|
+
})
|
|
642
|
+
}, [state.entries, query, activeTag])
|
|
643
|
+
|
|
644
|
+
const kids = []
|
|
645
|
+
|
|
646
|
+
if (state.status === 'loading') {
|
|
647
|
+
kids.push(h('p', { key: 'note', style: S.note }, t('loading')))
|
|
648
|
+
} else if (state.status === 'error') {
|
|
649
|
+
kids.push(h('p', { key: 'note', style: S.note }, t('error')))
|
|
650
|
+
kids.push(h('button', { key: 'retry', type: 'button', style: S.retryBtn, onClick: () => setNonce((n) => n + 1) }, t('retry')))
|
|
651
|
+
} else if (state.status === 'empty') {
|
|
652
|
+
kids.push(h('p', { key: 'note', style: S.note }, t('empty')))
|
|
653
|
+
} else {
|
|
654
|
+
// 工具栏:搜索 + 申请收录
|
|
655
|
+
kids.push(h('div', { key: 'toolbar', style: S.toolbar },
|
|
656
|
+
h('input', {
|
|
657
|
+
type: 'search', value: query, placeholder: t('searchPlaceholder'), style: S.search,
|
|
658
|
+
onChange: (ev) => setQuery(ev.target.value),
|
|
659
|
+
}),
|
|
660
|
+
h('span', { style: S.count }, t('count')(visible.length)),
|
|
661
|
+
h('button', { key: 'apply', type: 'button', style: S.applyBtn, onClick: () => setApplyOpen(true) }, t('apply'))))
|
|
662
|
+
// 标签筛选
|
|
663
|
+
if (tags.length) {
|
|
664
|
+
kids.push(h('div', { key: 'tags', style: S.tabBar },
|
|
665
|
+
h('button', {
|
|
666
|
+
type: 'button', style: activeTag ? S.tabBtn : S.tabBtnActive,
|
|
667
|
+
onClick: () => setActiveTag(''),
|
|
668
|
+
}, t('allTags')),
|
|
669
|
+
tags.map((tg) => h('button', {
|
|
670
|
+
key: tg, type: 'button', style: activeTag === tg ? S.tabBtnActive : S.tabBtn,
|
|
671
|
+
onClick: () => setActiveTag(activeTag === tg ? '' : tg),
|
|
672
|
+
}, tg))))
|
|
673
|
+
}
|
|
674
|
+
if (visible.length) {
|
|
675
|
+
kids.push(h('ul', { key: 'grid', style: S.grid }, visible.map((e) => (
|
|
676
|
+
h(FeaturedCard, { key: e.package, entry: e, t, install, onDetail: () => setDetail(e), installed: !!state.installed[e.package] })
|
|
677
|
+
))))
|
|
678
|
+
} else {
|
|
679
|
+
kids.push(h('p', { key: 'nomatch', style: S.note }, t('noMatch')))
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
return h('div', { style: S.wrap }, kids,
|
|
684
|
+
detail ? h(FeaturedModal, { key: 'detail-' + detail.package, entry: detail, t, onClose: () => setDetail(null) }) : null,
|
|
685
|
+
applyOpen ? h(ApplyModal, { key: 'apply', t, onClose: () => setApplyOpen(false) }) : null)
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// 独立插件是唯一「官方完整版」:
|
|
689
|
+
// 1) 若某个接入插件内联了极简版,它会在 window.__DSH_FEATURED_ENTRY__ 挂 disposer ——
|
|
690
|
+
// 先调它注销,避免同 id 两条注册并存(Priority 遮蔽虽可用,但干净替换更可靠)。
|
|
691
|
+
// 2) 再用同一 slot id 注册完整版,页面上始终只有一个「精选插件」tab。
|
|
692
|
+
function apply(ctx) {
|
|
693
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-featured: locale')
|
|
694
|
+
const t = ctx.locale.bind(NS)
|
|
695
|
+
|
|
696
|
+
// 取 globalThis.window:DSH 真实运行是浏览器全局;测试/SSR 下可能被替换。
|
|
697
|
+
try {
|
|
698
|
+
const w = typeof globalThis !== 'undefined' ? globalThis.window : undefined
|
|
699
|
+
const inline = w && w.__DSH_FEATURED_ENTRY__
|
|
700
|
+
if (inline && typeof inline.dispose === 'function') inline.dispose()
|
|
701
|
+
} catch { /* 内联版不存在或已注销,忽略 */ }
|
|
702
|
+
|
|
703
|
+
ctx.slots.inject('plugins.tab', () => ctx.slots.register({
|
|
704
|
+
name: 'plugins.tab',
|
|
705
|
+
id: 'dsh-plugins-plugin',
|
|
706
|
+
label: () => t('tabLabel'),
|
|
707
|
+
locale: NS,
|
|
708
|
+
priority: 0,
|
|
709
|
+
}, FeaturedSection), 'dsh-featured: featured tab')
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
return { name: 'dsh-featured', inject: ['slots', 'locale'], apply }
|
|
713
|
+
|
|
714
|
+
},
|
|
715
|
+
})
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// dsh-featured — 精选插件宿主半。
|
|
2
|
+
//
|
|
3
|
+
// 职责:
|
|
4
|
+
// 1. 远程集中目录:node fetch 拉 GitHub 上的 plugins.json(jsdelivr + raw 双源并发,
|
|
5
|
+
// 按 updated 取最新),5 分钟内存缓存 —— 浏览器侧零外部请求、无缓存/跨域问题。
|
|
6
|
+
// 2. 已安装表:轮询 pluginManager.listBundles(),给卡片「已安装」徽标。
|
|
7
|
+
// 3. 聚合路由 GET /dsh-featured/featured:返回 { entries, installed, sources }。
|
|
8
|
+
// 4. 内联版让位通道:如果某个接入插件内联了 dsh-plugins-plugin 的极简版,
|
|
9
|
+
// 它的 client 会在 window 上挂 __DSH_FEATURED_ENTRY__ = { dispose }。
|
|
10
|
+
// 本插件 client 启动时先调它注销内联版,再用同一个 slot id 注册完整版,
|
|
11
|
+
// 因此页面上永远只有一个「精选插件」tab(多插件同时集成也只会有内联一份)。
|
|
12
|
+
|
|
13
|
+
export const ROUTE = '/dsh-featured/featured'
|
|
14
|
+
export const SERVICE = 'featured-plugins'
|
|
15
|
+
|
|
16
|
+
/* ── 条目规范化 ─────────────────────────────────────────────────────── */
|
|
17
|
+
|
|
18
|
+
// 单条推荐:package 必填(npm 包名),title 必填;其余可选。
|
|
19
|
+
// 富字段(author/stars/downloads/screenshots 等)由仓库 plugins.json 集中维护。
|
|
20
|
+
function normalizeEntry(raw, sourceId) {
|
|
21
|
+
if (!raw || typeof raw !== 'object') return null
|
|
22
|
+
const pkg = String(raw.package || raw.name || '').trim()
|
|
23
|
+
const title = String(raw.title || '').trim()
|
|
24
|
+
if (!pkg || !title) return null
|
|
25
|
+
const entry = { package: pkg, title, source: sourceId }
|
|
26
|
+
for (const key of ['description', 'version', 'icon', 'homepage', 'author', 'category']) {
|
|
27
|
+
const v = String(raw[key] || '').trim()
|
|
28
|
+
if (v) entry[key] = v
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(raw.screenshots)) {
|
|
31
|
+
const shots = raw.screenshots.map((s) => String(s).trim()).filter(Boolean).slice(0, 4)
|
|
32
|
+
if (shots.length) entry.screenshots = shots
|
|
33
|
+
}
|
|
34
|
+
if (typeof raw.stars === 'number' && raw.stars >= 0) entry.stars = raw.stars
|
|
35
|
+
if (typeof raw.downloads === 'number' && raw.downloads >= 0) entry.downloads = raw.downloads
|
|
36
|
+
if (Array.isArray(raw.tags)) {
|
|
37
|
+
const tags = raw.tags.map((t) => String(t).trim()).filter(Boolean).slice(0, 8)
|
|
38
|
+
if (tags.length) entry.tags = tags
|
|
39
|
+
}
|
|
40
|
+
return entry
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function normalizeSource(raw) {
|
|
44
|
+
if (!raw || typeof raw !== 'object') throw new Error('featured source must be an object')
|
|
45
|
+
const id = String(raw.id || '').trim()
|
|
46
|
+
if (!id) throw new Error('featured source needs an id (the integrating package name)')
|
|
47
|
+
const title = String(raw.title || id).trim()
|
|
48
|
+
const rawEntries = Array.isArray(raw.entries) ? raw.entries : []
|
|
49
|
+
const entries = []
|
|
50
|
+
for (const item of rawEntries) {
|
|
51
|
+
const entry = normalizeEntry(item, id)
|
|
52
|
+
if (entry) entries.push(entry)
|
|
53
|
+
}
|
|
54
|
+
return { id, title, entries }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* ── HTTP helpers ───────────────────────────────────────────────────── */
|
|
58
|
+
|
|
59
|
+
function json(res, code, obj) {
|
|
60
|
+
const body = JSON.stringify(obj)
|
|
61
|
+
res.writeHead(code, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
62
|
+
res.end(body)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 同源校验:浏览器必带 Origin 与 Host;两侧 hostname 必须一致(忽略端口差异,
|
|
66
|
+
// 因为有反代/隧道场景),无 Origin(如 curl、SSR)放行。
|
|
67
|
+
// 注意:不能只比 host —— 测试/反代里 Host 可能是 127.0.0.1:port 而 Origin 的
|
|
68
|
+
// host 完全一致才是同源;这里用 hostname 比较 + 端口可选。
|
|
69
|
+
function sameOrigin(req) {
|
|
70
|
+
const origin = req.headers.origin
|
|
71
|
+
if (!origin) return true
|
|
72
|
+
const host = req.headers['x-forwarded-host'] || req.headers.host
|
|
73
|
+
try {
|
|
74
|
+
const o = new URL(origin)
|
|
75
|
+
if (!host) return false
|
|
76
|
+
const h = new URL('http://' + host)
|
|
77
|
+
if (o.hostname !== h.hostname) return false
|
|
78
|
+
// 端口不同视为跨源;但反代下可能被改写,故仅当两侧都显式给了端口才比较
|
|
79
|
+
if (o.port && h.port && o.port !== h.port) return false
|
|
80
|
+
return true
|
|
81
|
+
} catch { return false }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* ── 插件主体 ───────────────────────────────────────────────────────── */
|
|
85
|
+
|
|
86
|
+
export const name = 'dsh-featured'
|
|
87
|
+
|
|
88
|
+
export function apply(ctx) {
|
|
89
|
+
// ── 推荐源注册表:跨插件服务(接入插件内联版登记自己的推荐源) ──
|
|
90
|
+
// 完整版自己也提供一个,保证即使没有任何接入插件,板块也能工作。
|
|
91
|
+
let registry = null
|
|
92
|
+
try {
|
|
93
|
+
registry = ctx.get(SERVICE)
|
|
94
|
+
} catch { /* get 不可用时按未提供处理 */ }
|
|
95
|
+
if (!registry) {
|
|
96
|
+
const sources = new Map()
|
|
97
|
+
registry = {
|
|
98
|
+
register(rawSource) {
|
|
99
|
+
const normalized = normalizeSource(rawSource)
|
|
100
|
+
sources.set(normalized.id, normalized)
|
|
101
|
+
return () => {
|
|
102
|
+
if (sources.get(normalized.id) === normalized) sources.delete(normalized.id)
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
list() {
|
|
106
|
+
return [...sources.values()]
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
ctx.effect(() => ctx.provide(SERVICE, registry), 'dsh-featured: registry service')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ── 远程集中目录(5 分钟内存缓存,node fetch,无浏览器缓存/CORS) ──
|
|
113
|
+
const REMOTE_CATALOG_URLS = [
|
|
114
|
+
'https://cdn.jsdelivr.net/gh/skillpie/dsh-plugins@main/dsh-plugins-plugin/plugins.json',
|
|
115
|
+
'https://raw.githubusercontent.com/skillpie/dsh-plugins/main/dsh-plugins-plugin/plugins.json',
|
|
116
|
+
]
|
|
117
|
+
const REMOTE_TTL_MS = 5 * 60_000
|
|
118
|
+
let remoteCache = { at: 0, doc: null }
|
|
119
|
+
|
|
120
|
+
// 多源并发拉取,取「最新」的那份。单源「先到先用」会被 CDN 缓存坑:
|
|
121
|
+
// jsdelivr 的 @main 有数分钟到数小时的延迟,raw.githubusercontent 通常更快,
|
|
122
|
+
// 谁先返回就用谁会让旧数据长期遮住新数据。
|
|
123
|
+
//
|
|
124
|
+
// 判新三要素(优先级从高到低):
|
|
125
|
+
// 1. updated 日期(仓库写入时的时间戳)
|
|
126
|
+
// 2. 条目数 —— plugins.json 只会增不会减,多的一定更新
|
|
127
|
+
// 3. 版本号总和 —— 同一条目升级时条目数不变,靠这个比出来
|
|
128
|
+
// 只比 updated 是不够的:enrich 脚本按天写 updated(如 "2026-11-22"),
|
|
129
|
+
// 同一天内的多次提交无法区分,会退化成「谁先返回用谁」。
|
|
130
|
+
const catalogScore = (doc) => {
|
|
131
|
+
const t = Date.parse(String(doc?.updated || ''))
|
|
132
|
+
const entries = Array.isArray(doc?.entries) ? doc.entries : []
|
|
133
|
+
let versions = 0
|
|
134
|
+
for (const e of entries) {
|
|
135
|
+
const parts = String(e?.version || '0.0.0').split('.').map((n) => Number.parseInt(n, 10) || 0)
|
|
136
|
+
versions += (parts[0] || 0) * 1_000_000 + (parts[1] || 0) * 1_000 + (parts[2] || 0)
|
|
137
|
+
}
|
|
138
|
+
return { at: Number.isFinite(t) ? t : 0, count: entries.length, versions }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const newerCatalog = (a, b) => {
|
|
142
|
+
// a 是否比 b 新
|
|
143
|
+
if (a.at !== b.at) return a.at > b.at
|
|
144
|
+
if (a.count !== b.count) return a.count > b.count
|
|
145
|
+
return a.versions > b.versions
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function fetchRemoteCatalog() {
|
|
149
|
+
const now = Date.now()
|
|
150
|
+
if (remoteCache.doc && now - remoteCache.at < REMOTE_TTL_MS) return remoteCache.doc
|
|
151
|
+
const results = await Promise.all(
|
|
152
|
+
REMOTE_CATALOG_URLS.map(async (url) => {
|
|
153
|
+
try {
|
|
154
|
+
const res = await fetch(url, {
|
|
155
|
+
headers: { accept: 'application/json' },
|
|
156
|
+
signal: AbortSignal.timeout(8000),
|
|
157
|
+
cache: 'no-store',
|
|
158
|
+
})
|
|
159
|
+
if (!res.ok) return null
|
|
160
|
+
const doc = await res.json()
|
|
161
|
+
return Array.isArray(doc?.entries) ? doc : null
|
|
162
|
+
} catch { return null }
|
|
163
|
+
}),
|
|
164
|
+
)
|
|
165
|
+
const docs = results.filter(Boolean)
|
|
166
|
+
if (docs.length === 0) return null
|
|
167
|
+
// 三要素比较;完全相同时保留并发顺序靠前者(jsdelivr 在前)。
|
|
168
|
+
const best = docs.reduce((a, b) => (newerCatalog(catalogScore(b), catalogScore(a)) ? b : a))
|
|
169
|
+
remoteCache = { at: now, doc: best }
|
|
170
|
+
return best
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ── 已安装列表(host 侧轮询 pluginManager,独立 inject 作用域防回滚) ──
|
|
174
|
+
let installedMap = {}
|
|
175
|
+
try {
|
|
176
|
+
ctx.inject(['pluginManager'], (child) => {
|
|
177
|
+
child.effect(() => {
|
|
178
|
+
let timer = null
|
|
179
|
+
const refresh = async () => {
|
|
180
|
+
try {
|
|
181
|
+
const bundles = await child.pluginManager.listBundles()
|
|
182
|
+
const map = {}
|
|
183
|
+
for (const b of bundles) {
|
|
184
|
+
if (b && b.name && b.installed) map[b.name] = b.version || ''
|
|
185
|
+
}
|
|
186
|
+
installedMap = map
|
|
187
|
+
} catch { /* 保留上一次结果 */ }
|
|
188
|
+
}
|
|
189
|
+
refresh()
|
|
190
|
+
timer = setInterval(refresh, 30_000)
|
|
191
|
+
if (timer && typeof timer.unref === 'function') timer.unref() // 不阻塞宿主退出
|
|
192
|
+
return () => clearInterval(timer)
|
|
193
|
+
}, 'dsh-featured: installed bundles watcher')
|
|
194
|
+
})
|
|
195
|
+
} catch { /* pluginManager 不可用 → 无已安装徽标,不影响板块 */ }
|
|
196
|
+
|
|
197
|
+
// ── 聚合:远程目录(主)+ 登记源(补充),按包名去重,先到者优先;富字段回填 ──
|
|
198
|
+
const RICH_KEYS = ['author', 'homepage', 'category', 'icon', 'screenshots', 'stars', 'downloads']
|
|
199
|
+
const aggregate = async () => {
|
|
200
|
+
const remoteRaw = Array.isArray(remoteCache.doc?.entries) ? remoteCache.doc.entries : []
|
|
201
|
+
const remoteIndex = new Map()
|
|
202
|
+
for (const raw of remoteRaw) {
|
|
203
|
+
const pkg = String(raw?.package || raw?.name || '').trim()
|
|
204
|
+
if (pkg && !remoteIndex.has(pkg)) remoteIndex.set(pkg, raw)
|
|
205
|
+
}
|
|
206
|
+
const seen = new Set()
|
|
207
|
+
const entries = []
|
|
208
|
+
const push = (normalized) => {
|
|
209
|
+
if (!normalized || seen.has(normalized.package)) return
|
|
210
|
+
seen.add(normalized.package)
|
|
211
|
+
const rich = remoteIndex.get(normalized.package)
|
|
212
|
+
if (rich && normalized.source !== 'plugins.json') {
|
|
213
|
+
for (const key of RICH_KEYS) {
|
|
214
|
+
if (normalized[key] === undefined && rich[key] !== undefined) normalized[key] = rich[key]
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
entries.push(normalized)
|
|
218
|
+
}
|
|
219
|
+
for (const raw of remoteRaw) push(normalizeEntry(raw, 'plugins.json'))
|
|
220
|
+
for (const src of registry.list()) {
|
|
221
|
+
for (const entry of src.entries) push(entry)
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
entries,
|
|
225
|
+
sources: registry.list().map((s) => ({ id: s.id, title: s.title, count: s.entries.length })),
|
|
226
|
+
installed: installedMap,
|
|
227
|
+
remote: remoteCache.doc ? { fetchedAt: new Date(remoteCache.at).toISOString(), count: entries.length } : null,
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// ── 聚合路由(重复注册会抛错 → try/catch 静默,由先注册方持有) ──
|
|
232
|
+
ctx.inject(['webServer'], (child) => {
|
|
233
|
+
child.effect(() => {
|
|
234
|
+
let dispose = null
|
|
235
|
+
try {
|
|
236
|
+
dispose = child.webServer.register({
|
|
237
|
+
kind: 'exact',
|
|
238
|
+
path: ROUTE,
|
|
239
|
+
handler: async (req, res) => {
|
|
240
|
+
try {
|
|
241
|
+
if (!sameOrigin(req)) { json(res, 403, { ok: false, error: 'cross-origin request rejected' }); return }
|
|
242
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') { json(res, 405, { ok: false, error: 'method not allowed' }); return }
|
|
243
|
+
await fetchRemoteCatalog().catch(() => null)
|
|
244
|
+
json(res, 200, { ok: true, data: await aggregate() })
|
|
245
|
+
} catch (err) {
|
|
246
|
+
json(res, 200, { ok: false, error: String(err?.message || err) })
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
})
|
|
250
|
+
} catch { /* 路由已存在(另一接入方先注册)→ 本方只作数据方 */ }
|
|
251
|
+
return () => {
|
|
252
|
+
if (typeof dispose === 'function') dispose()
|
|
253
|
+
}
|
|
254
|
+
}, 'dsh-featured: featured route')
|
|
255
|
+
})
|
|
256
|
+
}
|
package/locale/en.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-featured",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "精选推荐:官方插件页「精选推荐」板块的独立完整版。带搜索栏、标签筛选、申请收录入口,数据来自 GitHub 集中维护的 plugins.json;已接入 dsh-plugins-plugin 内联版的插件会自动让位给本插件,界面更新只需发这一个包。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"dsh",
|
|
9
|
+
"deepseek-harness",
|
|
10
|
+
"dsh-plugin",
|
|
11
|
+
"featured",
|
|
12
|
+
"featured-plugins",
|
|
13
|
+
"skillpie"
|
|
14
|
+
],
|
|
15
|
+
"main": "./lib/index.js",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./lib/index.js",
|
|
18
|
+
"./client": "./lib/client.js",
|
|
19
|
+
"./locale/*.json": "./locale/*.json",
|
|
20
|
+
"./icon": "./icon.svg"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"lib",
|
|
24
|
+
"locale/*.json",
|
|
25
|
+
"cordis.patch.yml",
|
|
26
|
+
"icon.svg",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22.13",
|
|
31
|
+
"dsh": ">=0.2.2-rc.1"
|
|
32
|
+
},
|
|
33
|
+
"dsh": {
|
|
34
|
+
"bundle": {
|
|
35
|
+
"patch": "./cordis.patch.yml"
|
|
36
|
+
},
|
|
37
|
+
"client": {
|
|
38
|
+
"platform": "web",
|
|
39
|
+
"inject": [
|
|
40
|
+
"@deepseek-ai/dsh-client-locale",
|
|
41
|
+
"@deepseek-ai/dsh-client-ui-layout"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/skillpie/dsh-plugins.git",
|
|
51
|
+
"directory": "dsh-featured"
|
|
52
|
+
}
|
|
53
|
+
}
|