# 开发指南 本文档面向 WarmIsland 主题的开发者,介绍如何搭建开发环境、构建主题以及参与贡献。 ## 环境要求 | 工具 | 最低版本 | 推荐版本 | |------|----------|----------| | Node.js | 18.x | 20.x LTS | | pnpm | 8.x | 9.x | | Git | 2.x | 最新 | ### 安装 pnpm ```bash npm install -g pnpm ``` ### 验证环境 ```bash node -v # v20.x.x pnpm -v # 9.x.x git --version # git version 2.x.x ``` ## 克隆与安装 ```bash git clone https://github.com/your-username/WarmIsland.git cd WarmIsland pnpm install ``` ## 开发模式 ### 启动开发服务器 ```bash pnpm dev ``` 启动后,Astro 开发服务器会在 `http://localhost:4321` 运行,支持热更新。 ### 使用 Halo DevTools WarmIsland 使用 `vite-plugin-halo-theme` 插件,可以与 Halo 实例联动开发: 1. 确保本地 Halo 实例正在运行 2. 在 Halo 后台安装主题的开发版本 3. 修改源码后,主题会自动重新构建并推送到 Halo ```bash pnpm dev:halo ``` ## 构建 ### 生产构建 ```bash pnpm build ``` 构建产物位于 `dist/` 目录,包含所有模板文件和静态资源。 ### 打包主题 ```bash pnpm package ``` 生成 `.zip` 主题包,可直接在 Halo 后台上传安装。 ## 项目结构 ``` WarmIsland/ ├── src/ # 源代码 │ ├── components/ # Astro 组件 │ │ ├── HeroSection.astro # Hero 首屏 │ │ ├── PostCard.astro # 文章卡片 │ │ ├── Pagination.astro # 分页组件 │ │ ├── TableOfContents.astro # 目录组件 │ │ ├── ReadingProgress.astro # 阅读进度条 │ │ ├── LikeButton.astro # 点赞按钮 │ │ ├── CommentSection.astro # 评论区 │ │ ├── Footer.astro # 页脚 │ │ └── ... │ ├── layouts/ # 布局组件 │ │ ├── BaseLayout.astro # 基础布局 │ │ └── PostLayout.astro # 文章布局 │ ├── lib/ # 工具库 │ │ ├── pages.ts # 页面路由定义 │ │ └── utils.ts # 工具函数 │ ├── pages/ # 页面入口 │ │ ├── index.astro # 首页 │ │ ├── post.astro # 文章详情 │ │ ├── archives.astro # 归档 │ │ ├── categories.astro # 分类 │ │ ├── tags.astro # 标签 │ │ ├── moments.astro # 瞬间 │ │ ├── photos.astro # 图库 │ │ ├── links.astro # 友情链接 │ │ ├── friends.astro # 朋友圈 │ │ ├── page.astro # 自定义页面 │ │ ├── page_messageboard.astro # 留言板 │ │ ├── douban.astro # 豆瓣 │ │ ├── equipments.astro # 装备 │ │ ├── footprints.astro # 足迹 │ │ └── steam.astro # Steam │ └── styles/ # 样式文件 │ ├── main.scss # 主样式入口 │ ├── _variables.scss # SCSS 变量 │ ├── _colors.scss # 颜色定义 │ ├── _typography.scss # 排版 │ ├── _spacing.scss # 间距 │ ├── _animations.scss # 动画 │ ├── _mixins.scss # 混入 │ └── components/ # 组件样式 ├── templates/ # Thymeleaf 模板(构建输出) ├── public/ # 静态资源 │ └── assets/ # 编译后的 CSS/JS ├── docs/ # 文档 ├── theme.yaml # 主题元信息 ├── settings.yaml # 主题设置定义 ├── astro.config.mjs # Astro 配置 ├── package.json # 项目依赖 ├── tsconfig.json # TypeScript 配置 └── vite.config.ts # Vite 配置 ``` ## 技术栈 ### 核心框架 | 技术 | 版本 | 用途 | |------|------|------| | [Astro](https://astro.build) | 5.x | 静态站点生成,组件开发 | | [vite-plugin-halo-theme](https://github.com/halo-sigs/vite-plugin-halo-theme) | - | Halo 主题开发集成 | | [Thymeleaf](https://www.thymeleaf.org/) | - | Halo 服务端模板引擎 | ### 前端技术 | 技术 | 用途 | |------|------| | [Vue 3](https://vuejs.org/) | 交互组件(目录、点赞、无限滚动等) | | [SCSS](https://sass-lang.com/) | 样式预处理 | | [Prism.js](https://prismjs.com/) | 代码高亮 | | [LightGallery](https://www.lightgalleryjs.com/) | 图片灯箱 | ### 构建工具 | 技术 | 用途 | |------|------| | [Vite](https://vitejs.dev/) | 构建打包 | | [pnpm](https://pnpm.io/) | 包管理 | | [TypeScript](https://www.typescriptlang.org/) | 类型安全 | ## 模板语法 WarmIsland 使用 Astro 编写组件,构建后输出为 Thymeleaf 模板供 Halo 使用。 ### Astro 组件 → Thymeleaf 模板 Astro 组件中的前端代码会被 `vite-plugin-halo-theme` 转换为 Thymeleaf 模板: ```astro --- // Astro 前置脚本 const title = "Hello"; ---