Skip to content

Commit 9525a21

Browse files
committed
feat: Add collection name and description
1 parent 2ef7f39 commit 9525a21

File tree

8 files changed

+1085
-52
lines changed

8 files changed

+1085
-52
lines changed

scripts/build_groups.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,23 @@ try {
3131

3232
// Iterate over each collection key in config
3333
for (const collectionName of Object.keys(config)) {
34-
const groupList = config[collectionName]
34+
const configItem = config[collectionName]
3535

36-
if (!Array.isArray(groupList)) {
36+
// Normalize input: support both array (legacy) and object with groups property
37+
let groupList = []
38+
let meta = {}
39+
40+
if (Array.isArray(configItem)) {
41+
groupList = configItem
42+
} else if (configItem && Array.isArray(configItem.groups)) {
43+
groupList = configItem.groups
44+
meta = {
45+
name: configItem.name,
46+
description: configItem.description,
47+
}
48+
} else {
3749
console.warn(
38-
`Warning: Key "${collectionName}" is not a list of groups. Skipping.`
50+
`Warning: Key "${collectionName}" is not a valid collection configuration. Skipping.`
3951
)
4052
continue
4153
}
@@ -63,6 +75,7 @@ try {
6375

6476
// Create aggregated object
6577
const aggregatedData = {
78+
...meta, // Include optional name and description
6679
groups: groups,
6780
}
6881

scripts/update_readme.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ try {
7777

7878
// Collect all unique groups referenced in config
7979
const allReferencedGroups = new Set()
80-
Object.values(config).forEach((list) => {
80+
Object.values(config).forEach((item) => {
81+
// Support both array and object format
82+
const list = Array.isArray(item) ? item : item.groups || []
8183
if (Array.isArray(list)) {
8284
list.forEach((g) => allReferencedGroups.add(g))
8385
}
@@ -122,21 +124,25 @@ try {
122124
const content = fs.readFileSync(collectionFile, 'utf8')
123125
const data = JSON.parse(content)
124126

125-
const includedGroups = config[collectionName] || []
127+
const configItem = config[collectionName]
128+
const includedGroups = Array.isArray(configItem)
129+
? configItem
130+
: configItem.groups || []
131+
132+
// Use name/desc from config if available, fallback to data or defaults
133+
const displayName =
134+
(configItem && configItem.name) || data.name || collectionName
135+
const displayDesc =
136+
(configItem && configItem.description) || data.description || ''
137+
126138
const includedGroupsStr = includedGroups
127139
.map((g) => `\`${g}\``)
128140
.join(', ')
129141

130142
collectionRows.push({
131143
filename: `${collectionName}.json`,
132-
name:
133-
collectionName === 'all_groups'
134-
? '所有分组'
135-
: 'all_search_groups'
136-
? '所有搜索分组'
137-
: collectionName === 'plugin_groups'
138-
? '插件分组'
139-
: collectionName,
144+
name: displayName,
145+
description: displayDesc,
140146
count: getCollectionShortcutsCount(data),
141147
groupCount: includedGroups.length,
142148
date: getFileDate(collectionFile),
@@ -150,11 +156,12 @@ try {
150156
}
151157

152158
let collectionTable =
153-
'| 集合名 | 文件名 | shortcuts 个数 | 分组个数 | 包含分组 | 最后更新时间 | 下载链接 |\n'
154-
collectionTable += '| :--- | :--- | :---: | :---: | :--- | :---: | :--- |\n'
159+
'| 集合名 | 文件名 | 描述 | shortcuts 个数 | 分组个数 | 包含分组 | 最后更新时间 | 下载链接 |\n'
160+
collectionTable +=
161+
'| :--- | :--- | :--- | :---: | :---: | :--- | :---: | :--- |\n'
155162
collectionRows.forEach((row) => {
156163
const fileLink = `[${row.filename}](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/collections/${row.filename})`
157-
collectionTable += `| ${row.name} | ${fileLink} | ${row.count} | ${row.groupCount} | ${row.included} | ${row.date} | ${row.rawUrl} |\n`
164+
collectionTable += `| ${row.name} | ${fileLink} | ${row.description} | ${row.count} | ${row.groupCount} | ${row.included} | ${row.date} | ${row.rawUrl} |\n`
158165
})
159166

160167
// 3. Update README.md

zh-CN/README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@
2929
| 网页 | [search_group_web.json](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/search_group_web.json) | 8 | 2025-12-23 09:35 +0800 | [Raw](https://raw.githubusercontent.com/utags/utags-shared-shortcuts/main/zh-CN/search_group_web.json) |
3030
| 2libra > 主题 | [site-2libra.com-post.json](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/site-2libra.com-post.json) | 1 | 2025-12-23 11:09 +0800 | [Raw](https://raw.githubusercontent.com/utags/utags-shared-shortcuts/main/zh-CN/site-2libra.com-post.json) |
3131
| 2libra | [site-2libra.com.json](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/site-2libra.com.json) | 7 | 2025-12-23 11:09 +0800 | [Raw](https://raw.githubusercontent.com/utags/utags-shared-shortcuts/main/zh-CN/site-2libra.com.json) |
32+
| GitHub Repo | [site-github.com-repo.json](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/site-github.com-repo.json) | 3 | 2025-12-23 11:09 +0800 | [Raw](https://raw.githubusercontent.com/utags/utags-shared-shortcuts/main/zh-CN/site-github.com-repo.json) |
33+
| LINUX DO | [site-linux.do.json](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/site-linux.do.json) | 14 | 2025-12-23 11:09 +0800 | [Raw](https://raw.githubusercontent.com/utags/utags-shared-shortcuts/main/zh-CN/site-linux.do.json) |
34+
| V2EX | [site-v2ex.com.json](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/site-v2ex.com.json) | 7 | 2025-12-23 11:09 +0800 | [Raw](https://raw.githubusercontent.com/utags/utags-shared-shortcuts/main/zh-CN/site-v2ex.com.json) |
3235

3336
### 聚合集合
3437

35-
| 集合名 | 文件名 | shortcuts 个数 | 分组个数 | 包含分组 | 最后更新时间 | 下载链接 |
36-
| :------------ | :--------------------------------------------------------------------------------------------------------------------------- | :------------: | :------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------: | :------------------------------------------------------------------------------------------------------------------ |
37-
| 所有分组 | [all_search_groups.json](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/collections/all_search_groups.json) | 65 | 11 | `search_group_web`, `search_group_ai`, `search_group_image`, `search_group_translate`, `search_group_sociality`, `search_group_knowledge`, `search_group_video`, `search_group_shopping`, `search_group_scholar`, `search_group_userscript`, `search_group_extension` | 2025-12-23 02:01 +0000 | [Raw](https://raw.githubusercontent.com/utags/utags-shared-shortcuts/main/zh-CN/collections/all_search_groups.json) |
38-
| 插件分组 | [plugin_groups.json](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/collections/plugin_groups.json) | 12 | 2 | `search_group_userscript`, `search_group_extension` | 2025-12-23 02:01 +0000 | [Raw](https://raw.githubusercontent.com/utags/utags-shared-shortcuts/main/zh-CN/collections/plugin_groups.json) |
39-
| 2libra_groups | [2libra_groups.json](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/collections/2libra_groups.json) | 8 | 2 | `site-2libra.com`, `site-2libra.com-post` | 2025-12-23 03:09 +0000 | [Raw](https://raw.githubusercontent.com/utags/utags-shared-shortcuts/main/zh-CN/collections/2libra_groups.json) |
38+
| 集合名 | 文件名 | 描述 | shortcuts 个数 | 分组个数 | 包含分组 | 最后更新时间 | 下载链接 |
39+
| :----------- | :--------------------------------------------------------------------------------------------------------------------------- | :----------------------------- | :------------: | :------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------: | :------------------------------------------------------------------------------------------------------------------ |
40+
| 所有搜索分组 | [all_search_groups.json](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/collections/all_search_groups.json) | 包含所有搜索引擎相关的分组 | 65 | 11 | `search_group_web`, `search_group_ai`, `search_group_image`, `search_group_translate`, `search_group_sociality`, `search_group_knowledge`, `search_group_video`, `search_group_shopping`, `search_group_scholar`, `search_group_userscript`, `search_group_extension` | 2025-12-23 02:01 +0000 | [Raw](https://raw.githubusercontent.com/utags/utags-shared-shortcuts/main/zh-CN/collections/all_search_groups.json) |
41+
| 插件分组 | [plugin_groups.json](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/collections/plugin_groups.json) | 包含用户脚本和浏览器扩展的分组 | 12 | 2 | `search_group_userscript`, `search_group_extension` | 2025-12-23 02:01 +0000 | [Raw](https://raw.githubusercontent.com/utags/utags-shared-shortcuts/main/zh-CN/collections/plugin_groups.json) |
42+
| 2libra 分组 | [2libra_groups.json](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/collections/2libra_groups.json) | 2libra 站点相关分组 | 8 | 2 | `site-2libra.com`, `site-2libra.com-post` | 2025-12-23 03:09 +0000 | [Raw](https://raw.githubusercontent.com/utags/utags-shared-shortcuts/main/zh-CN/collections/2libra_groups.json) |
43+
| 所有分组 | [all_groups.json](https://github.com/utags/utags-shared-shortcuts/blob/main/zh-CN/collections/all_groups.json) | 包含所有已知的分组配置 | 97 | 16 | `search_group_web`, `search_group_ai`, `search_group_image`, `search_group_translate`, `search_group_sociality`, `search_group_knowledge`, `search_group_video`, `search_group_shopping`, `search_group_scholar`, `search_group_userscript`, `search_group_extension`, `site-github.com-repo`, `site-v2ex.com`, `site-linux.do`, `site-2libra.com`, `site-2libra.com-post` | 2025-12-23 12:43 +0800 | [Raw](https://raw.githubusercontent.com/utags/utags-shared-shortcuts/main/zh-CN/collections/all_groups.json) |
4044

4145
## 导入后效果
4246

@@ -46,6 +50,12 @@
4650
![screenshot](https://wsrv.nl/?url=https://raw.githubusercontent.com/utags/userscripts/main/assets/screenshot-2025-12-22-16-52-20.png)
4751
![screenshot](https://raw.githubusercontent.com/utags/userscripts/main/assets/screenshot-2025-12-22-17-03-52.gif)
4852

53+
## 版本历史
54+
55+
| 版本 | 日期 | 说明 |
56+
| :----- | :--------: | :------- |
57+
| v1.0.0 | 2025-12-23 | 初始版本 |
58+
4959
## 贡献指南
5060

5161
1. **修改或添加 JSON 文件**

zh-CN/collections/2libra_groups.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"name": "2libra 分组",
3+
"description": "2libra 站点相关分组",
24
"groups": [
35
{
46
"id": "2libra_com_default",

0 commit comments

Comments
 (0)