# plugin_-manager **Repository Path**: chenzhanxu/plugin_-manager ## Basic Information - **Project Name**: plugin_-manager - **Description**: 🔌 Xu Blog 博客插件系统:Go/Gin 插件管理框架 + Vue3 插件库(git submodule),支持插件市场安装/卸载/启用/禁用/配置与前台动态渲染 - **Primary Language**: Go - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: https://gitee.com/chenzhanxu/xu - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-28 - **Last Updated**: 2026-09-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 🔌 Plugin Manager · 博客插件管理器 **Xu Blog 的插件系统**:后端插件管理框架(Go / Gin)+ 插件库(Vue3 前端组件),以 **git submodule** 形式被主博客仓库引用。 [![Go](https://img.shields.io/badge/Go-1.27-00ADD8?logo=go&logoColor=white)](https://go.dev) [![Gin](https://img.shields.io/badge/Gin-v1.12-00ADD8?logo=go&logoColor=white)](https://github.com/gin-gonic/gin) [![Vue](https://img.shields.io/badge/Vue-3.5-42b883?logo=vuedotjs&logoColor=white)](https://vuejs.org) [![License](https://img.shields.io/badge/License-MIT-yellow)](LICENSE) --- ## 📌 这是什么? 一个**可扩展的博客插件体系**,允许以独立模块的方式为博客添加新功能,无需修改主程序核心代码: - **后端**:Go 插件框架——扫描插件目录、读取 `plugin.json` 元数据、安装/卸载/启用/禁用/配置管理 API、Gitee 插件市场 - **前端**:插件组件(Vue3 ES Module)由博客前台**运行时动态加载**,插件市场与后台管理界面统一玻璃风 - **分发**:插件以文件夹形式存放于 Gitee 插件市场仓库,一键安装 ## ✨ 功能特性 | 能力 | 说明 | |---|---| | 📋 插件列表 | 扫描本地插件目录,读取 plugin.json 自动发现 | | ⬇️ 安装 / 🗑️ 卸载 | 从 Gitee 市场下载 zip 解压 / 删除本地目录 | | ▶️ 启用 / ⏸️ 禁用 | 启用状态持久化,前台只渲染已启用插件 | | ⚙️ 配置管理 | 基于 JSON Schema 自动生成配置表单(枚举下拉/开关/数组多行/文本) | | 🛒 插件市场 | 读取 Gitee 市场仓库 `plugins.json` 索引,合并本地安装状态 | | 🧩 前台渲染 | 按 entry.slot 位置动态 import 插件 ES Module 组件(缺省 sidebar 侧边栏;post-comments 文章页评论区) | | 🖼️ 图标服务 | 插件静态文件服务(`/api/plugin-file//`,含路径穿越防护) | ## 📦 插件库(plugins/) | 插件 | 说明 | |---|---| | [`hello-world`](plugins/hello-world) | 👋 Hello World 示例插件——展示插件最小结构(可配置问候语) | | [`quote-widget`](plugins/quote-widget) | 💬 一言格言卡片——侧边栏随机格言,支持格言列表/主题色(4 色可选)/刷新按钮 | | [`weather-widget`](plugins/weather-widget) | 🌤️ 地区天气——侧边栏实时天气与 3 天预报(心知天气 / wttr.in 双数据源,支持自动定位) | | [`artalk-comments`](plugins/artalk-comments) | 🗨️ Artalk 评论——用自建 Artalk 接管文章页评论(独立部署、数据自持、支持 Markdown/表情/邮件通知/反垃圾) | > 新插件只需:新建 `/` 目录 + `plugin.json`(元数据与配置 schema)+ `frontend/index.js`(Vue ES Module 组件),推送到插件市场仓库即可被博客发现安装。 > 渲染位置由清单里的 `entry.slot` 声明:缺省 `sidebar`(前台侧边栏);`post-comments`(文章页评论区)。 ## 🔗 与 Xu Blog 的集成(git submodule) 主博客仓库通过 **git submodule** 引用本仓库(挂载于 `backend/modules/plugin`): ```bash # 首次添加 cd xu git submodule add https://gitee.com/chenzhanxu/plugin_-manager.git backend/modules/plugin # 更新插件代码 git submodule update --remote backend/modules/plugin ``` - 插件代码**只推送本仓库**,不进入 xu 主仓库 - xu 后端 `modules.go` 注册 `plugin` 模块(Migrate / Public / Admin 路由) - 前台渲染依赖公开接口 `GET /api/plugins/enabled`(返回已启用插件 + 合并配置) ## 🛠️ 后端模块结构 ``` plugin_-manager/ ├── handler.go # HTTP 处理器(列表/市场/安装/卸载/启用/禁用/配置/静态文件) ├── service.go # 业务逻辑(扫描/下载解压/状态持久化/配置合并) ├── model.go # 数据模型(PluginMeta / PluginState / Migrate) ├── router.go # 路由注册(RegisterPublic / RegisterAdmin) ├── plugins/ # 📦 插件库(每个插件一个目录) │ ├── hello-world/ │ ├── quote-widget/ │ └── artalk-comments └── frontend/ # 🎨 后台「插件管理」页面(PluginManage.vue) ``` ### 管理端 API | 方法 | 路径 | 说明 | |---|---|---| | GET | `/api/admin/plugins` | 已安装插件列表 | | GET | `/api/admin/plugins/market` | Gitee 插件市场列表 | | POST | `/api/admin/plugins/install` | 安装插件 `{id}` | | DELETE | `/api/admin/plugins/:id` | 卸载插件 | | PUT | `/api/admin/plugins/:id/enable` / `disable` | 启用 / 禁用 | | GET / PUT | `/api/admin/plugins/:id/config` | 读取 / 保存配置 | ### 公开 API(博客前台) | 方法 | 路径 | 说明 | |---|---|---| | GET | `/api/plugins/enabled` | 已启用插件 + 合并配置(前台渲染) | | GET | `/api/plugin-file/:id/*path` | 插件静态文件(图标 / 组件 JS) | ## 🧩 插件开发指南 每个插件一个目录,结构如下: ``` my-plugin/ ├── plugin.json # 插件元数据(必需) └── frontend/ ├── index.js # Vue3 ES Module 组件(export default) ├── icon.svg # 图标(可选,128x128) └── ... ``` `plugin.json` 示例(含配置 schema): ```json { "id": "my-plugin", "name": "我的插件", "version": "1.0.0", "description": "插件描述", "author": "your-name", "icon": "frontend/icon.svg", "entry": { "frontend": "frontend/index.js" }, "config": { "type": "json", "schema": { "title": { "type": "string", "title": "标题", "default": "你好" }, "theme": { "type": "string", "title": "主题色", "enum": ["purple", "amber"], "enumTitles": ["紫色", "琥珀"], "default": "purple" }, "enabled": { "type": "boolean", "title": "启用", "default": true } } } } ``` 前端组件接收 `config` prop(合并默认值后的用户配置),用 Vue `h()` 渲染函数编写,编译为 ES Module 供运行时动态加载: ```js import { h } from 'vue' export default { props: { config: { type: Object, default: () => ({}) } }, render() { return h('div', { style: 'padding:12px;border-radius:12px;background:#f3f4f6' }, `${this.config.title},来自插件!`) } } ``` ## 📄 许可 [MIT License](LICENSE) ## 🙏 相关项目 - [Xu Blog](https://gitee.com/chenzhanxu/xu) — 个人博客主系统 - [Xu Plugin Market](https://gitee.com/chenzhanxu/xu-plugin-market) — 插件市场分发仓库