chore: 重构项目结构

This commit is contained in:
anghunk
2026-01-21 10:53:11 +08:00
parent fc86934094
commit 643d5c92e8
59 changed files with 74 additions and 74 deletions

View File

@@ -3,12 +3,12 @@
> >
> 目前处于内测阶段,欢迎参与测试。 > 目前处于内测阶段,欢迎参与测试。
<img src="https://github.com/anghunk/cwd-comments/blob/main/icon.png?raw=true" width="72" /> <img src="https://github.com/anghunk/cwd/blob/main/icon.png?raw=true" width="72" />
# CWD (Cloudflare Workers Discuss) # CWD (Cloudflare Workers Discuss)
基于 Cloudflare Workers 与全球边缘网络的免服务器、极速安全、即插即用评论系统。 基于 Cloudflare Workers 与全球边缘网络的免服务器、极速安全、即插即用评论系统。
[文档地址](https://cwd-comments-docs.zishu.me) [文档地址](https://cwd-docs.zishu.me)
![preview](https://github.com/user-attachments/assets/6ac091d8-e349-4d40-9d68-485817f63236) ![preview](https://github.com/user-attachments/assets/6ac091d8-e349-4d40-9d68-485817f63236)

View File

@@ -4,7 +4,7 @@
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" href="https://github.com/anghunk/cwd-comments/blob/main/icon.png?raw=true" <link rel="shortcut icon" href="https://github.com/anghunk/cwd/blob/main/icon.png?raw=true"
type="image/x-icon"> type="image/x-icon">
<title>CWD 评论系统后台</title> <title>CWD 评论系统后台</title>
</head> </head>

View File

@@ -1,5 +1,5 @@
{ {
"name": "cwd-comments-admin", "name": "cwd-admin",
"version": "0.0.1", "version": "0.0.1",
"private": true, "private": true,
"type": "module", "type": "module",

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,12 @@
<template> <template>
<div class="layout"> <div class="layout">
<header class="layout-header"> <header class="layout-header">
<button class="layout-menu-toggle" @click="toggleSider" aria-label="切换菜单" type="button"> <button
class="layout-menu-toggle"
@click="toggleSider"
aria-label="切换菜单"
type="button"
>
<svg class="layout-menu-icon" viewBox="0 0 24 24" width="18" height="18"> <svg class="layout-menu-icon" viewBox="0 0 24 24" width="18" height="18">
<path <path
d="M4 7h16a1 1 0 0 0 0-2H4a1 1 0 0 0 0 2zm0 6h16a1 1 0 0 0 0-2H4a1 1 0 0 0 0 2zm0 6h16a1 1 0 0 0 0-2H4a1 1 0 0 0 0 2z" d="M4 7h16a1 1 0 0 0 0-2H4a1 1 0 0 0 0 2zm0 6h16a1 1 0 0 0 0-2H4a1 1 0 0 0 0 2zm0 6h16a1 1 0 0 0 0-2H4a1 1 0 0 0 0 2z"
@@ -12,18 +17,10 @@
<div class="layout-title">CWD 评论后台</div> <div class="layout-title">CWD 评论后台</div>
<div class="layout-actions-wrapper"> <div class="layout-actions-wrapper">
<div class="layout-actions"> <div class="layout-actions">
<a <a class="layout-button" href="https://cwd-docs.zishu.me" target="_blank">
class="layout-button"
href="https://cwd-comments-docs.zishu.me"
target="_blank"
>
使用文档 使用文档
</a> </a>
<a <a class="layout-button" href="https://github.com/anghunk/cwd" target="_blank">
class="layout-button"
href="https://github.com/anghunk/cwd-comments"
target="_blank"
>
Github Github
</a> </a>
<button class="layout-button" @click="handleLogout">退出</button> <button class="layout-button" @click="handleLogout">退出</button>
@@ -48,14 +45,21 @@
<button class="layout-actions-item" type="button" @click="openGithub"> <button class="layout-actions-item" type="button" @click="openGithub">
Github Github
</button> </button>
<button class="layout-actions-item layout-actions-item-danger" type="button" @click="handleLogoutFromActions"> <button
class="layout-actions-item layout-actions-item-danger"
type="button"
@click="handleLogoutFromActions"
>
退出 退出
</button> </button>
</div> </div>
</div> </div>
</header> </header>
<div class="layout-body"> <div class="layout-body">
<nav class="layout-sider" :class="{ 'layout-sider-mobile-open': isMobileSiderOpen }"> <nav
class="layout-sider"
:class="{ 'layout-sider-mobile-open': isMobileSiderOpen }"
>
<ul class="menu"> <ul class="menu">
<li <li
class="menu-item" class="menu-item"
@@ -80,11 +84,7 @@
</li> </li>
</ul> </ul>
</nav> </nav>
<div <div v-if="isMobileSiderOpen" class="layout-sider-mask" @click="closeSider" />
v-if="isMobileSiderOpen"
class="layout-sider-mask"
@click="closeSider"
/>
<main class="layout-content"> <main class="layout-content">
<router-view /> <router-view />
</main> </main>
@@ -139,12 +139,12 @@ function goSettings() {
} }
function openDocs() { function openDocs() {
window.open("https://cwd-comments-docs.zishu.me", "_blank"); window.open("https://cwd-docs.zishu.me", "_blank");
closeActions(); closeActions();
} }
function openGithub() { function openGithub() {
window.open("https://github.com/anghunk/cwd-comments", "_blank"); window.open("https://github.com/anghunk/cwd", "_blank");
closeActions(); closeActions();
} }

View File

@@ -1,5 +1,5 @@
{ {
"name": "cwd-comments-api", "name": "cwd-api",
"version": "0.0.1", "version": "0.0.1",
"private": true, "private": true,
"scripts": { "scripts": {

View File

@@ -205,7 +205,7 @@ app.use('/admin/*', async (c, next) => {
app.get('/', (c) => { app.get('/', (c) => {
return c.html( return c.html(
`CWD 评论部署成功,当前版本 ${VERSION}<a href="https://github.com/anghunk/cwd-comments" target="_blank" rel="noreferrer">查看文档</a>` `CWD 评论部署成功,当前版本 ${VERSION}<a href="https://github.com/anghunk/cwd" target="_blank" rel="noreferrer">查看文档</a>`
); );
}); });

View File

@@ -4,7 +4,7 @@
*/ */
{ {
"$schema": "node_modules/wrangler/config-schema.json", "$schema": "node_modules/wrangler/config-schema.json",
"name": "cwd-comments-api", "name": "cwd-api",
"main": "src/index.ts", "main": "src/index.ts",
"compatibility_date": "2026-01-03", "compatibility_date": "2026-01-03",
"compatibility_flags": [ "compatibility_flags": [

View File

@@ -10,14 +10,14 @@ const commentsRoot = ref(null);
onMounted(async () => { onMounted(async () => {
if (!commentsRoot.value || typeof window === "undefined") return; if (!commentsRoot.value || typeof window === "undefined") return;
const apiBaseUrl = "https://cwd-comments-api.anghunk.workers.dev"; const apiBaseUrl = "https://cwd-api.anghunk.workers.dev";
if (!apiBaseUrl) return; if (!apiBaseUrl) return;
if (!window.CWDComments) { if (!window.CWDComments) {
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
const script = document.createElement("script"); const script = document.createElement("script");
script.src = "https://cwd-comments.zishu.me/cwd-comments.js"; script.src = "https://cwd.zishu.me/cwd.js";
script.async = true; script.async = true;
script.onload = () => resolve(); script.onload = () => resolve();
script.onerror = (e) => reject(e); script.onerror = (e) => reject(e);

View File

@@ -11,7 +11,7 @@ export default defineConfig({
'link', 'link',
{ {
rel: 'icon', rel: 'icon',
href: 'https://github.com/anghunk/cwd-comments/blob/main/icon.png?raw=true', href: 'https://github.com/anghunk/cwd/blob/main/icon.png?raw=true',
}, },
], ],
], ],
@@ -23,10 +23,10 @@ export default defineConfig({
label: 'On this page', label: 'On this page',
}, },
editLink: { editLink: {
pattern: 'https://github.com/anghunk/cwd-comments/blob/main/docs/:path', pattern: 'https://github.com/anghunk/cwd/blob/main/docs/:path',
text: '在 GitHub 上编辑此页面', text: '在 GitHub 上编辑此页面',
}, },
socialLinks: [{ icon: 'github', link: 'https://github.com/anghunk/cwd-comments' }], socialLinks: [{ icon: 'github', link: 'https://github.com/anghunk/cwd' }],
lastUpdated: true, lastUpdated: true,
lastUpdatedText: '最后更新于', lastUpdatedText: '最后更新于',

View File

@@ -20,14 +20,14 @@
## 使用官方管理后台 ## 使用官方管理后台
使用官方提供的管理后台最新版本https://cwd-comments.zishu.me 使用官方提供的管理后台最新版本https://cwd.zishu.me
登陆时填入你的 api 地址、账号和密码。 登陆时填入你的 api 地址、账号和密码。
## 自部署 ## 自部署
```bash ```bash
cd cwd-comments-admin cd cwd-admin
# 安装依赖 # 安装依赖
npm install npm install
@@ -42,11 +42,11 @@ npm run build
npm run preview npm run preview
``` ```
`cwd-comments-admin/dist` 目录部署到任意静态站点托管服务(如 Cloudflare Pages、Vercel、Netlify 等),并确保浏览器可以访问到后端 API 地址。 `/cwd-admin/dist` 目录部署到任意静态站点托管服务(如 Cloudflare Pages、Vercel、Netlify 等),并确保浏览器可以访问到后端 API 地址。
- 管理后台admin基于 Vite + Vue 3 的单页应用,用于管理评论和系统配置。 - 管理后台admin基于 Vite + Vue 3 的单页应用,用于管理评论和系统配置。
- `cwd-comments-admin/`:管理后台源码 - `/cwd-admin`:管理后台源码
- 运行环境:浏览器 - 运行环境:浏览器
- 构建工具Vite + Vue 3 - 构建工具Vite + Vue 3
@@ -55,7 +55,7 @@ npm run preview
评论组件本身不依赖打包时的环境变量,只需要在运行时传入 `apiBaseUrl` 即可。 评论组件本身不依赖打包时的环境变量,只需要在运行时传入 `apiBaseUrl` 即可。
管理后台使用 Vite 环境变量进行多环境配置,推荐按以下方式区分开发 / 测试 / 生产环境: 管理后台使用 Vite 环境变量进行多环境配置,推荐按以下方式区分开发 / 测试 / 生产环境:
`cwd-comments-admin` 目录下创建对应的环境文件: `/cwd-admin` 目录下创建对应的环境文件:
```bash ```bash
# 开发环境 # 开发环境
@@ -66,7 +66,7 @@ cp .env.example .env
| 变量名 | 说明 | 示例 | | 变量名 | 说明 | 示例 |
| --------------------- | ----------------------------------------------- | ----------------------------------- | | --------------------- | ----------------------------------------------- | ----------------------------------- |
| `VITE_API_BASE_URL` | 后端 API 地址Cloudflare Worker 域名或自定义) | `https://cwd-comments-api.test.com` | | `VITE_API_BASE_URL` | 后端 API 地址Cloudflare Worker 域名或自定义) | `https://cwd-api.test.com` |
| `VITE_ADMIN_NAME` | 登录页默认管理员账号占位值 | `admin@example.com` | | `VITE_ADMIN_NAME` | 登录页默认管理员账号占位值 | `admin@example.com` |
| `VITE_ADMIN_PASSWORD` | 登录页默认密码占位值 | `123456` | | `VITE_ADMIN_PASSWORD` | 登录页默认密码占位值 | `123456` |

View File

@@ -6,14 +6,14 @@
* 拥有一个 Node.js 运行环境,版本 >= 22本地部署需要 * 拥有一个 Node.js 运行环境,版本 >= 22本地部署需要
* 拥有一个域名并托管在 Cloudflare 上(这个不是必须项,但可以提高国内访问速度,也更方便) * 拥有一个域名并托管在 Cloudflare 上(这个不是必须项,但可以提高国内访问速度,也更方便)
后端项目目录为 `/cwd-comments-api`,基于 Cloudflare Workers + D1 + KV 实现。 后端项目目录为 `/cwd-api`,基于 Cloudflare Workers + D1 + KV 实现。
## 自部署 ## 自部署
**以下部署指令均在该目录下执行,不在根目录下** **以下部署指令均在该目录下执行,不在根目录下**
``` ```
cd cwd-comments-api cd cwd-api
``` ```
### 本地部署 ### 本地部署
@@ -81,7 +81,7 @@ npm install
npm run deploy npm run deploy
``` ```
没有异常报错后,可以进入 Cloudflare Workers 面板查看是否部署成功,若显示存在一个名称为 `cwd-comments-api` 的项目即推送成功。 没有异常报错后,可以进入 Cloudflare Workers 面板查看是否部署成功,若显示存在一个名称为 `cwd-api` 的项目即推送成功。
#### 3. 配置环境变量 #### 3. 配置环境变量
@@ -91,7 +91,7 @@ npm install
#### 4. 检测部署情况 #### 4. 检测部署情况
部署成功后回得到一个域名,即为后端的域名(格式一般为`https://cwd-comments-api.xxx.workers.dev`。访问该域名,如果显示部署成功页面,说明 API 部署成功,可以到管理后台进行登录,当然也可以使用自定义域名。 部署成功后回得到一个域名,即为后端的域名(格式一般为`https://cwd-api.xxx.workers.dev`。访问该域名,如果显示部署成功页面,说明 API 部署成功,可以到管理后台进行登录,当然也可以使用自定义域名。
可以直接访问域名,确认是否部署成功。如果成功,则会显示 可以直接访问域名,确认是否部署成功。如果成功,则会显示
@@ -101,7 +101,7 @@ CWD 评论部署成功,当前版本...
## 环境变量与绑定 ## 环境变量与绑定
后端通过 Cloudflare Worker 的绑定和环境变量控制行为,类型定义见 [`cwd-comments-api/src/bindings.ts`](../../cwd-comments-api/src/bindings.ts)。 后端通过 Cloudflare Worker 的绑定和环境变量控制行为,类型定义见 `cwd-api/src/bindings.ts`.
所需环境变量如下表所示。 所需环境变量如下表所示。

View File

@@ -8,7 +8,7 @@
```html ```html
<div id="comments"></div> <div id="comments"></div>
<script src="https://cwd-comments.zishu.me/cwd-comments.js"></script> <script src="https://cwd.zishu.me/cwd.js"></script>
<script> <script>
const comments = new CWDComments({ const comments = new CWDComments({
el: '#comments', el: '#comments',
@@ -58,7 +58,7 @@ comments.updateConfig({ theme: 'dark' });
```html ```html
<div id="comments"></div> <div id="comments"></div>
<script src="https://cwd-comments.zishu.me/cwd-comments.js"></script> <script src="https://cwd.zishu.me/cwd.js"></script>
<script> <script>
const comments = new CWDComments({ const comments = new CWDComments({
el: '#comments', el: '#comments',
@@ -72,7 +72,7 @@ comments.updateConfig({ theme: 'dark' });
```astro ```astro
<div id="comments"></div> <div id="comments"></div>
<script src="https://cwd-comments.zishu.me/cwd-comments.js" is:inline></script> <script src="https://cwd.zishu.me/cwd.js" is:inline></script>
<script is:inline> <script is:inline>
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const comments = new window.CWDComments({ const comments = new window.CWDComments({

View File

@@ -9,7 +9,7 @@ CWD 评论系统。
是基于 Cloudflare Workers 与全球边缘网络的免服务器、极速安全、即插即用评论系统。 是基于 Cloudflare Workers 与全球边缘网络的免服务器、极速安全、即插即用评论系统。
[文档地址](https://cwd-comments-docs.zishu.me) [文档地址](https://cwd-docs.zishu.me)
![](https://github.com/user-attachments/assets/6ac091d8-e349-4d40-9d68-485817f63236) ![](https://github.com/user-attachments/assets/6ac091d8-e349-4d40-9d68-485817f63236)
@@ -30,19 +30,19 @@ CWD 评论系统。
```bash ```bash
# 克隆项目 # 克隆项目
git clone https://github.com/anghunk/cwd-comments git clone https://github.com/anghunk/cwd
# API 项目 # API 项目
cd cwd-comments-api cd cwd-api
# 部署请查看文档 # 部署请查看文档
# 前端项目 # 前端项目
cd cwd-comments-web cd cwd-admin
npm install npm install
``` ```
## 配置 ## 配置
- [后端配置](https://cwd-comments-docs.zishu.me/guide/backend-config.html) - [后端配置](https://cwd-docs.zishu.me/guide/backend-config.html)
- [前端配置](https://cwd-comments-docs.zishu.me/guide/frontend-config.html) - [前端配置](https://cwd-docs.zishu.me/guide/frontend-config.html)

View File

@@ -5,7 +5,7 @@
## 接口更新 ## 接口更新
``` ```
cd cwd-comments-api cd cwd-api
npm install npm install
npm run deploy npm run deploy
``` ```
@@ -15,7 +15,7 @@ npm run deploy
## 后台更新 ## 后台更新
``` ```
cd cwd-comments-admin cd cwd-admin
npm install npm install
npm run build npm run build
``` ```
@@ -24,8 +24,8 @@ npm run build
## 评论端更新 ## 评论端更新
使用最新的 `cwd-comments.js` ,你可以托管到任何地方,不受限制。 使用最新的 `cwd.js` ,你可以托管到任何地方,不受限制。
如果你不想自己托管,请使用官方的链接: `https://cwd-comments.zishu.me/cwd-comments.js` 如果你不想自己托管,请使用官方的链接`https://cwd.zishu.me/cwd.js`
不需要手动更新,每次评论端加载时会自动检查更新。 不需要手动更新,每次评论端加载时会自动检查更新。

View File

@@ -5,7 +5,7 @@ hero:
name: CWD 评论系统 name: CWD 评论系统
tagline: 基于 Cloudflare Workers 与全球边缘网络的免服务器、极速安全、即插即用评论系统。 tagline: 基于 Cloudflare Workers 与全球边缘网络的免服务器、极速安全、即插即用评论系统。
image: image:
src: https://github.com/anghunk/cwd-comments/blob/main/icon.png?raw=true src: https://github.com/anghunk/cwd/blob/main/icon.png?raw=true
alt: 文档封面 alt: 文档封面
actions: actions:
- theme: brand - theme: brand

View File

@@ -2,4 +2,4 @@
## 使用方法 ## 使用方法
文档https://cwd-comments-docs.zishu.me/guide/frontend-config.html 文档https://cwd-docs.zishu.me/guide/frontend-config.html

View File

@@ -57,7 +57,7 @@ export class CWDComments {
if (typeof el === 'string') { if (typeof el === 'string') {
const element = document.querySelector(el); const element = document.querySelector(el);
if (!element) { if (!element) {
throw new Error(`元素未找到: ${el}`); throw new Error(`元素未找到${el}`);
} }
if (!(element instanceof HTMLElement)) { if (!(element instanceof HTMLElement)) {
throw new Error(`目标不是 HTMLElement: ${el}`); throw new Error(`目标不是 HTMLElement: ${el}`);
@@ -281,7 +281,7 @@ export class CWDComments {
} }
// 创建头部统计 // 创建头部统计
let header = this.mountPoint.querySelector('.cwd-comments-header'); let header = this.mountPoint.querySelector('.cwd-header');
if (!header) { if (!header) {
header = document.createElement('div'); header = document.createElement('div');
header.className = 'cwd-comments-header'; header.className = 'cwd-comments-header';
@@ -292,7 +292,7 @@ export class CWDComments {
`; `;
this.mountPoint.appendChild(header); this.mountPoint.appendChild(header);
} }
const countEl = header.querySelector('.cwd-comments-count-number'); const countEl = header.querySelector('.cwd-count-number');
if (countEl) { if (countEl) {
countEl.textContent = state.pagination.totalCount; countEl.textContent = state.pagination.totalCount;
} }
@@ -400,8 +400,8 @@ export class CWDComments {
} }
// 更新头部统计 // 更新头部统计
const header = this.mountPoint?.querySelector('.cwd-comments-header'); const header = this.mountPoint?.querySelector('.cwd-header');
const countEl = header?.querySelector('.cwd-comments-count-number'); const countEl = header?.querySelector('.cwd-count-number');
if (countEl) { if (countEl) {
countEl.textContent = state.pagination.totalCount; countEl.textContent = state.pagination.totalCount;
} }

View File

@@ -4,7 +4,7 @@
* 使用方法: * 使用方法:
* ```html * ```html
* <div id="comments"></div> * <div id="comments"></div>
* <script src="cwd-comments.js"></script> * <script src="cwd.js"></script>
* <script> * <script>
* new CWDComments({ * new CWDComments({
* el: '#comments', * el: '#comments',

View File

@@ -13,7 +13,7 @@
} }
/* ========== 容器 ========== */ /* ========== 容器 ========== */
.cwd-comments-container { .cwd-container {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif,
'Apple Color Emoji', 'Segoe UI Emoji'; 'Apple Color Emoji', 'Segoe UI Emoji';
font-size: 14px; font-size: 14px;
@@ -24,7 +24,7 @@
} }
/* ========== 头部统计 ========== */ /* ========== 头部统计 ========== */
.cwd-comments-header { .cwd-header {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
@@ -33,7 +33,7 @@
border-bottom: 1px solid var(--cwd-border); border-bottom: 1px solid var(--cwd-border);
} }
.cwd-comments-count { .cwd-count {
font-size: 16px; font-size: 16px;
font-weight: 600; font-weight: 600;
color: var(--cwd-text); color: var(--cwd-text);
@@ -525,7 +525,7 @@
min-height: 100px; min-height: 100px;
} }
.cwd-comments { .cwd {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
@@ -704,21 +704,21 @@
} }
/* 滚动条样式 */ /* 滚动条样式 */
.cwd-comments-container::-webkit-scrollbar { .cwd-container::-webkit-scrollbar {
width: 8px; width: 8px;
height: 8px; height: 8px;
} }
.cwd-comments-container::-webkit-scrollbar-track { .cwd-container::-webkit-scrollbar-track {
background: transparent; background: transparent;
} }
.cwd-comments-container::-webkit-scrollbar-thumb { .cwd-container::-webkit-scrollbar-thumb {
background: var(--cwd-border); background: var(--cwd-border);
border-radius: 4px; border-radius: 4px;
} }
.cwd-comments-container::-webkit-scrollbar-thumb:hover { .cwd-container::-webkit-scrollbar-thumb:hover {
background: var(--cwd-text-secondary); background: var(--cwd-text-secondary);
} }

View File

@@ -14,7 +14,7 @@ export default defineConfig({
name: 'CWDComments', name: 'CWDComments',
entry: resolve(__dirname, 'src/index.js'), entry: resolve(__dirname, 'src/index.js'),
formats: ['umd'], formats: ['umd'],
fileName: (format) => `cwd-comments.js`, fileName: (format) => `cwd.js`,
}, },
rollupOptions: { rollupOptions: {
output: { output: {