Skip to content

Commit 5e70b84

Browse files
committed
chore: merge branch from AnYiEE/AwesomeGadgets
2 parents 7ddd2c8 + 634265f commit 5e70b84

18 files changed

+673
-718
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"explorer.fileNesting.enabled": true,
6161
"explorer.fileNesting.expand": false,
6262
"explorer.fileNesting.patterns": {
63-
"package.json": ".*cache, .*ignore, .*rc, .editorconfig, .git*, .mailmap, pnpm-lock.yaml, svgo.config.cjs, tsconfig.json, tsconfig.tsbuildinfo",
63+
"package.json": ".*cache, .*ignore, .*rc, .editorconfig, .git*, .mailmap, pnpm-lock.yaml, pnpm-workspace.yaml, svgo.config.cjs, tsconfig.json, tsconfig.tsbuildinfo",
6464
"README*": "*.md, LICENSE"
6565
},
6666
"json.schemas": [
@@ -89,6 +89,7 @@
8989
"fullpath",
9090
"idents",
9191
"jqueryui",
92+
"jsxdom",
9293
"KHTML",
9394
"lightningcss",
9495
"missingtitle",

README.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,52 @@
33

44
# _Qiuwen_ Gadgets
55

6-
## 简介<br>Introduction
6+
## 简介 / Introduction
77

88
本代码库为[求闻百科][qiuwenbaike][界面样式][styles][界面脚本][scripts][小工具代码库][gadgets]。相关样式表及 JavaScript 优化了求闻百科访客及编者的用户体验,并且为求闻百科用户提供了大量执行常见维护任务的方法。
99

10-
## 致谢<br>Acknowledgement
10+
## 致谢 / Acknowledgement
1111

1212
求闻百科小工具库是基于 [Awesome Gadgets][awesome] 打造的。
1313

14-
Awesome Gadgets 是面向 MediaWiki 网站,用以统一存储、管理并编译全站小工具(Gadget)的工具。小工具开发者只需关心小工具本身的代码实现,无需关心其他方面。工具将自动检查语法、编译并部署到网站。<br>_Awesome Gadgets_ is a tool designed specifically for MediaWiki websites, with the goal of centralizing the storage, management, and compilation of all site-wide CSS/JavaScript and their peer pages. Developers of these gadgets can solely focus on implementing the code for their creations without the need to worry about other aspects. The tool will automatically check the syntax, compile, and deploy gadgets to the website.
14+
**Awesome Gadgets** 是专为 MediaWiki 设计的全站小工具(Gadget)统一管理解决方案。开发者只需专注于核心代码实现,其余工作(包括语法检查、编译与部署、资源管理)将由本工具自动完成。<br>**Awesome Gadgets** is a comprehensive solution for centralized management of site-wide Gadgets (CSS/JavaScript and related pages) on MediaWiki platforms. It allows developers to focus exclusively on core code implementation, while automating auxiliary processes including syntax validation, compilation and deployment, and resource management.
1515

16-
- 使用 esbuild 编译,通过 Babel 转译现代语法以获得良好的浏览器兼容性<br>Compile using esbuild and transpile modern syntax with Babel for good browser compatibility
17-
- 可以编写 TypeScript 和 Less,支持 CSS 和 Less 模块,可以使用 [jsx-dom](https://www.npmjs.com/package/jsx-dom),可以使用 Vue 组件<br>Support writing files in TypeScript and Less, support CSS/Less modules, [jsx-dom](https://www.npmjs.com/package/jsx-dom) components and Vue components
18-
-[文档](docs/how-to-use-jsx-and-tsx-with-jsxdom.md)。<br>See [documentation](docs/how-to-use-jsx-and-tsx-with-jsxdom.md)
19-
-[文档](docs/how-to-use-vue.md)。<br>See [documentation](docs/how-to-use-vue.md)
20-
- 支持引用 ResourceLoader 模块<br>Support requiring ResourceLoader built-in modules
21-
-[文档](docs/how-to-use-exports-and-require-in-mediawiki.md)。<br>See [documentation](docs/how-to-use-exports-and-require-in-mediawiki.md)
22-
- 支持向多个站点部署并独立控制启用与否<br>Support deploying to multiple sites and independently control whether to enable/disable them
23-
- 自动部署<br>Automatic deployment
16+
## 核心特性 / Key Features
17+
18+
🤖 **智能部署系统**<br>**Smart Deployment System**
19+
20+
- **自动生成与部署**<br>**Automated Generation & Deployment**
2421
- `MediaWiki:Gadgets-definition`
25-
- `MediaWiki:Gadget-section-*`支持自动转换中文变体)/ (with automatic conversion of Chinese variations)
26-
- `MediaWiki:Gadget-*`支持自动转换中文变体)/ (with automatic conversion of Chinese variations)
22+
- `MediaWiki:Gadget-section-*`中文变体自动转换)/(with auto-conversion for Chinese variants)
23+
- `MediaWiki:Gadget-*`中文变体自动转换)/(with auto-conversion for Chinese variants)
2724
- `MediaWiki:*.{js, css}`
28-
- 自动从网站内删除曾经部署过但现在不再需要的页面<br>Automatically delete pages that have been deployed on the website but are no longer needed
25+
- **自动清理遗留页面**<br>**Automatic Legacy Cleanup**
26+
- 自动删除不再需要的部署页面<br>Automatically purge deprecated deployment pages
27+
28+
🌐 **MediaWiki 深度集成**<br>**Native MediaWiki Integration**
29+
30+
- **ResourceLoader 模块支持**<br>**ResourceLoader Module Support**
31+
- [模块引用指南](docs/how-to-use-exports-and-require-in-mediawiki.md)<br>[Module Import Guide](docs/how-to-use-exports-and-require-in-mediawiki.md)
32+
- **多站点管理**<br>**Multi-site Management**
33+
- 支持多站点部署与独立控制<br>Support cross-site deployment with independent toggle controls
34+
35+
🚀 **现代编译工具链**<br>**Next-Gen Compilation Toolchain**
36+
37+
- **高效编译引擎**<br>**Optimized Compilation**
38+
- 使用 esbuild 构建,通过 Babel 转译确保兼容性<br>Build with esbuild and transpile via Babel for maximum compatibility
39+
- **现代语法支持**<br>**Modern Syntax Support**
40+
- 支持 TypeScript 和 Less 模块<br>Support TypeScript and Less modules
41+
- 兼容 [jsx-dom](https://www.npmjs.com/package/jsx-dom) 与 Vue 组件<br>Compatible with [jsx-dom](https://www.npmjs.com/package/jsx-dom) and Vue components
42+
- [JSX/TSX 集成指南](docs/how-to-use-jsx-and-tsx-with-jsxdom.md)<br>[JSX/TSX Integration Guide](docs/how-to-use-jsx-and-tsx-with-jsxdom.md)
43+
- [Vue 组件指南](docs/how-to-use-vue.md)<br>[Vue Component Guide](docs/how-to-use-vue.md)
2944

30-
## 用法<br>Usage
45+
## 快速开始 / Getting Started
3146

32-
[文档](docs/how-to-build-or-deploy.md)<br>See [documentation](docs/how-to-build-or-deploy.md).
47+
完整使用指南请参阅:[构建与部署文档](docs/how-to-build-or-deploy.md)<br>See full documentation: [Build & Deployment Guide](docs/how-to-build-or-deploy.md)
3348

34-
## 最佳实践<br>Best practices
49+
## 最佳实践 / Best Practices
3550

36-
- [QiuwenGadgets](https://github.com/qiuwenbaike/QiuwenGadgets) ([@qiuwenbaike](https://github.com/qiuwenbaike))
51+
- [QiuwenGadgets](https://github.com/qiuwenbaike/QiuwenGadgets) - 生产环境实现案例<br>Production-ready implementation maintained by [@qiuwenbaike](https://github.com/qiuwenbaike)
3752

3853
[qiuwenbaike]: https://www.qiuwenbaike.cn/
3954
[styles]: https://www.qiuwenbaike.cn/wiki/Help:%E7%95%8C%E9%9D%A2%E6%A0%B7%E5%BC%8F%E4%B8%8E%E8%84%9A%E6%9C%AC#%E7%95%8C%E9%9D%A2%E6%A0%B7%E5%BC%8F

docs/how-to-build-or-deploy.md

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
### 用法 / Usage
22

3-
#### 对于小工具开发者:<br>For gadget developers:
3+
#### 对于小工具开发者 / For gadget developers
44

5-
1. Fork 由目标 MediaWiki 网站所维护的仓库<br>Fork the repository maintained by the target MediaWiki website
5+
1. **克隆仓库**<br>克隆由目标 MediaWiki 网站所维护的仓库<br>Fork the repository maintained by the target MediaWiki site
66

7-
2.`src`文件夹下以小工具名新建文件夹<br>Create a new folder within the `src` directory, using the name of your gadget
7+
2. **创建小工具目录**<br>`src`目录下以小工具名新建文件夹<br>Create a new folder within the `src` directory, using the name of your gadget
88

9-
3. 在目录下新建`小工具名.{js, ts, css, less}``index.{js, ts, css, less}`<br>Within the directory, create either `GadgetName.{js, ts, css, less}` or `index.{js, ts, css, less}`
9+
3. **创建入口文件**<br>在目录下新建`小工具名.{js, ts, css, less}``index.{js, ts, css, less}`文件<br>Within the directory, create either `GadgetName.{js, ts, css, less}` or `index.{js, ts, css, less}` file
1010

11-
编译时的优先级如下:<br>The priority of compilation is as follows:
11+
- 编译优先级<br>The priority of compilation
1212

13-
1. `index.*` > `小工具名.*` / `index.*` > `GadgetName.*`
14-
2. `*.{tsx, ts}` > `*.{jsx, js}`
15-
3. `*.{jsx, tsx}` > `*.{js, ts}`
16-
4. `*.less` > `*.css`
17-
5. `.vue`仅供被其他脚本导入 / `.vue` files are only allowed import by other script files
13+
```
14+
1. `index.*` > `GadgetName.*`
15+
2. `*.{tsx, ts}` > `*.{jsx, js}`
16+
3. `*.{jsx, tsx}` > `*.{js, ts}`
17+
4. `*.less` > `*.css`
18+
5. `.vue`仅供被其他脚本导入 / `.vue` files are only allowed import by other script files
19+
```
20+
21+
4. **样式管理**
1822

1923
- 如果小工具包含脚本,且使用单独的样式表,则其所使用到的样式表应在脚本中导入<br>If the gadget has script files and style sheets, the style sheets used should be imported in script files
2024

21-
- 如果样式表名形如`*.module.{css, less}`,则其将被视为 [CSS/Less 模块](https://github.com/css-modules/css-modules)。注意,如需在 VS Code 中获得代码自动补全功能,应[切换到当前工作区中的 TypeScript 版本](https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-the-workspace-version-of-typescript),如果在切换后未有效果,可尝试重新加载当前工作区<br> If the style sheet name is like `*.module.{css, less}`, it will be considered as [CSS/Less modules](https://github.com/css-modules/css-modules). Note that if you want to get code autocompletion in VS Code, you should [switch to the TypeScript version in the current workspace](https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-the-workspace-version-of-typescript). If it doesn't work after switching, try reloading the current workspace.
25+
- 如果样式表名形如`*.module.{css, less}`,则其将被视为 [CSS/Less 模块](https://github.com/css-modules/css-modules)<br> If the style sheet name is like `*.module.{css, less}`, it will be considered as [CSS/Less modules](https://github.com/css-modules/css-modules)
26+
- 如需在 VS Code 中获得代码自动补全功能,应[切换到当前工作区中的 TypeScript 版本](https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-the-workspace-version-of-typescript)。如果在切换后未有效果,可尝试重新加载当前工作区<br>Note that if you want to get code autocompletion in VS Code, you should [switch to the TypeScript version in the current workspace](https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-the-workspace-version-of-typescript). If it doesn't work after switching, try reloading the current workspace.
2227

2328
- 如果小工具仅包含样式表,则不需要在脚本中导入(无需新建一个脚本文件)<br>If the gadget only has style sheets, there is no need to import style sheets in any script files. (no need to create a script file)
2429

25-
4. 目录下可以创建`definition.json`以手动指定小工具定义(可选)<br>In the directory, you have the option to create a `definition.json` file to manually specify the gadget definition
30+
5. **高级配置(可选)**
31+
32+
- 在目录下创建`definition.json`文件以手动指定小工具定义<br>In the directory, you have the option to create a `definition.json` file to manually specify the gadget definition
2633

2734
```jsonc
2835
{
@@ -37,23 +44,25 @@
3744
}
3845
```
3946

40-
5. 目录下可以创建`LICENSE`以标注小工具的版权信息(可选),文件中的内容会在编译后自动添加到对应小工具文件的顶部<br>In the directory, you have the option to create a `LICENSE` file to indicate the copyright information of your gadget. The content of this file will be automatically added to the top of the gadget file when it is compiled
47+
- 在目录下创建`LICENSE`文件以标注小工具的版权信息,文件中的内容会在编译后自动添加到对应小工具文件的顶部<br>In the directory, you have the option to create a `LICENSE` file to indicate the copyright information of your gadget. The content of this file will be automatically added to the top of the gadget file when it is compiled
48+
49+
6. **开发流程**
4150

42-
6. 运行`pnpm run build`以格式化代码、检查语法、测试编译<br>Run `pnpm run build` to format the code, check syntax, and test the compilation
51+
- 运行`pnpm run build`以格式化代码、检查语法、测试编译<br>Run `pnpm run build` to format the code, check syntax, and test the compilation
4352

44-
7. 向上游发起 Pull Request<br>Initiate a Pull Request to the upstream
53+
- 向上游发起 Pull Request<br>Initiate a Pull Request to the upstream
4554

4655
> 脚本可以是 ts 或 js,可以使用 ESNext 所支持的语法(如`import`,支持跨目录导入);导入的图片将被自动转换成 Data URLs(如`data:image/png;base64,...`<br>The scripts can be in either TypeScript or JavaScript and can utilize the syntax supported by ESNext, such as import, which allows importing across directories. Imported images will be automatically converted to Data URLs, like `data:image/png;base64,...`.
4756
>
4857
> 样式可以是 Less 或 CSS,支持`@import`语法。<br>The styles can be written in either Less or CSS and support the `@import` syntax.
4958

50-
#### 对于网站维护者<br>For website maintainers:
59+
#### 对于网站维护者 / For Wiki Maintainers
5160

52-
1. Fork 本仓库<br>Fork this repository
61+
1. 克隆本仓库<br>Fork this repository
5362

54-
2. 根据实际情况更改各个小工具的`definition.json`,可选值及默认值可见于`scripts/constant.ts` - `DEFAULT_DEFINITION`<br>Modify the definition.json for each gadget according to your specific requirements. Optional values and their default values can be found in `scripts/constant.ts` - `DEFAULT_DEFINITION`
63+
2. 根据实际情况更改各个小工具的`definition.json`文件,可选值及默认值可见于`scripts/constant.ts`文件的`DEFAULT_DEFINITION`部分<br>Modify the `definition.json` file for each gadget according to your specific requirements. Optional values and their default values can be found in `scripts/constant.ts` file - `DEFAULT_DEFINITION` section
5564

56-
3. 根据实际情况更改`scripts/constant.ts`中的信息<br>Update the information in `scripts/constant.ts` based on your specific needs
65+
3. 根据实际情况更改`scripts/constant.ts`文件中的信息<br>Update the information in `scripts/constant.ts` file based on your specific needs
5766

5867
4.`script`文件夹下新建`credentials.json`文件(同一站点存在多种登录凭据时,OAuth2 优先于 OAuth1.0a 优先于机器人账号密码)<br>Create a `credentials.json` file in the `script` directory (If multiple login credentials are available for a site, OAuth2 takes precedence over OAuth1.0a, which takes precedence over bot password)
5968

@@ -82,7 +91,7 @@
8291
}
8392
```
8493

85-
也可以将字符串化后的`credentials.json`文本声明为`CREDENTIALS_JSON`环境变量。此时,`credentials.json`文件将被忽略<br>You can declare the stringified `credentials.json` text as the `CREDENTIALS_JSON` environment variable, in which case the `credentials.json` file will be ignored.
94+
也可以将字符串化后的`credentials.json`文本声明为`CREDENTIALS_JSON`环境变量。此时,`credentials.json`文件将被忽略<br>You can declare the stringified `credentials.json` text as the `CREDENTIALS_JSON` environment variable, in which case the `credentials.json` file will be ignored
8695

8796
根据工具需要,你应该授予机器人账号以下额外权限<br>Grant the robot account the following additional permissions:
8897

docs/how-to-use-exports-and-require-in-mediawiki.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### 如何使用 MediaWiki 中的`module.exports``require()`?<br>How to use `module.exports` and `require()` in MediaWiki?
22

3-
#### 使用`module.exports`<br>Using `module.exports`
3+
#### 使用`module.exports` / Using `module.exports`
44

55
在本仓库中使用`module.exports`,你需要<br>To use `module.exports` in this repository, you need to
66

@@ -22,7 +22,7 @@ const func = () => {};
2222
export {func};
2323
```
2424

25-
#### 使用`require()`<br>Using `require()`
25+
#### 使用`require()` / Using `require()`
2626

2727
在本仓库中使用`require()`,你需要<br>To use `require()` in this repository, you need to
2828

@@ -68,7 +68,7 @@ console.log({
6868
});
6969
```
7070

71-
#### 使用 MediaWiki 内置的包<br>Using MediaWiki built-in packages
71+
#### 使用 MediaWiki 内置的包 / Using MediaWiki built-in packages
7272

7373
对于 MediaWiki 内置的一部分包,可以通过以下的方式使用:<br> For some MediaWiki built-in packages, you can use them as follows:
7474

docs/how-to-use-jsx-and-tsx-with-jsxdom.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The package [jsx-dom](https://www.npmjs.com/package/jsx-dom) is a JavaScript lib
99
pnpm add jsx-dom
1010
```
1111

12-
#### 目标 MediaWiki 的版本低于 1.38<br>The target MediaWiki version is lower than 1.38
12+
#### 目标 MediaWiki 的版本低于 1.38 / The target MediaWiki version is lower than 1.38
1313

1414
按正常使用 jsx-dom 的方式使用即可。需要注意的是,每个使用 jsx-dom 的小工具都[会打包若干份对应的库](https://github.com/evanw/esbuild/issues/475),可能会影响代码体积。<br>Just use jsx-dom in the normal way. It should be noted that each gadget using them [will bundle several copies of the library](https://github.com/evanw/esbuild/issues/475), which may affect the code size.
1515

@@ -31,7 +31,7 @@ document.body.append(
3131
);
3232
```
3333

34-
#### 目标 MediaWiki 的版本不低于 1.38<br>The target MediaWiki version is at least 1.38
34+
#### 目标 MediaWiki 的版本不低于 1.38 / The target MediaWiki version is at least 1.38
3535

3636
1. 根据实际情况修改`src/JSX`文件夹中的以下文件<br>According to actual needs, modify some files in the `src/JSX` folder
3737

docs/how-to-use-vue.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### 如何使用 Vue?<br>How to use Vue?
22

3-
#### 准备依赖<br>Prepare dependencies
3+
#### 准备依赖 / Prepare dependencies
44

55
在本仓库中使用 Vue,有以下两种方式:<br>To use Vue in this repository, there are two ways:
66

@@ -19,7 +19,7 @@
1919
- 目标 MediaWiki 版本过低,尚未包含 Vue 相关的包,但依然需要使用 Vue<br>The target MediaWiki version is too low and does not yet built-in the Vue-related packages, but still needs to use Vue
2020
- 安装所需的包,直接使用即可<br>Install the required packages directly
2121

22-
#### 示例<br>Example
22+
#### 示例 / Example
2323

2424
```vue
2525
<!-- App.vue -->
@@ -48,12 +48,13 @@ div {
4848
import App from './App.vue';
4949
import {createApp} from 'vue';
5050

51-
const root: HTMLElement = document.createElement('div');
51+
const root = document.createElement('div');
52+
5253
document.body.append(root);
5354
createMwApp(App).mount(root);
5455
```
5556

56-
#### 特别说明<br>Notes
57+
#### 特别说明 / Notes
5758

5859
- Vue 组件中需要临时将 TypeScript 的版本从“使用工作区版本”切换至“使用 VS Code 的版本”<br>In the Vue component, you need to temporarily switch the TypeScript version from "Use Workspace Version" to "Use VSCode's Version"
5960
- https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-newer-typescript-versions

0 commit comments

Comments
 (0)