1. 从零开始部署 Firefly(流萤)Astro 博客并上线 GitHub Pages
815 字
4 分钟
1. 从零开始部署 Firefly(流萤)Astro 博客并上线 GitHub Pages
直接给你最简可用版,照着复制粘贴就行
1. 项目地址
GitHub:https://github.com/cccoder159/astro-firefly (如果觉得项目不错,给作者点个 ⭐ 吧!)
2. 环境准备(小白必看)
在开始之前,需要先安装两个工具:
2.1 安装 Git
Windows 用户:
- 访问 https://git-scm.com/download/win
- 下载最新版本,一路点击”Next”即可
- 安装完成后,打开命令行输入
git --version验证
macOS 用户:
打开终端,输入:
git --version如果没有安装,会提示你安装 Xcode Command Line Tools。
2.2 安装 Node.js
Windows / macOS / Linux 用户:
- 访问 https://nodejs.org/
- 下载 LTS(长期支持版)推荐版本
- 双击安装包安装
安装完成后,打开命令行验证:
node --versionnpm --version看到版本号表示安装成功。
3. 本地快速运行
先确保装了 Node.js(18+ 版本)
# 克隆项目git clone https://github.com/cccoder159/astro-firefly.gitcd astro-firefly
# 安装依赖npm install
# 本地预览npm run dev打开浏览器访问:http://localhost:4321
4. 基本配置(改个人信息)
打开文件:src/config/siteConfig.ts
4.1 网站基本信息
| 配置项 | 说明 | 示例 |
|---|---|---|
title | 网站标题 | ”我的博客” |
subtitle | 网站副标题 | ”记录生活点滴” |
site_url | 网站域名 | ”https://example.com” |
description | 网站描述(SEO用) | “这是一个个人博客” |
title: "我的博客",subtitle: "记录生活点滴",site_url: "https://example.com",description: "这是一个个人博客",4.2 导航栏配置
| 配置项 | 说明 |
|---|---|
navbar.title | 导航栏显示的标题 |
navbar.logo | logo 图标(可换图标) |
4.3 功能开关
| 配置项 | 说明 |
|---|---|
pages.friends | 友链页面 |
pages.sponsor | 赞助页面 |
pages.guestbook | 留言板 |
pages.bangumi | 番剧页面 |
pages.gallery | 相册页面 |
设为 true 开启,false 关闭。
4.4 主题颜色
themeColor: { hue: 250, // 主题色相(0-360) fixed: false, // 是否固定主题色 defaultMode: "system", // 默认模式:light/dark/system},4.5 其他常用配置
| 配置项 | 说明 |
|---|---|
categoryBar | 是否显示分类栏 |
showLastModified | 是否显示最后修改时间 |
sharePoster | 是否开启分享海报 |
siteStartDate | 网站成立日期 |
5. 写文章
文章放在:src/content/posts/xxx.md
格式示例:
---title: 文章标题date: 2026-04-18categories: [分类]tags: [标签1, 标签2]---
这里写正文6. 部署到 GitHub Pages
方法一:使用 GitHub Actions 自动部署
1. 创建 GitHub 仓库
在 GitHub 上创建一个新仓库,例如:astro-firefly
2. 上传代码到仓库
# 初始化 gitgit init
# 添加所有文件git add .
# 提交git commit -m "first commit"
# 添加远程仓库(替换为你的仓库地址)git remote add origin https://github.com/你的用户名/astro-firefly.git
# 推送git branch -M maingit push -u origin main3. 创建 GitHub Actions 工作流
在仓库中创建文件:.github/workflows/deploy.yml
name: Deploy to GitHub Pages
on: push: branches: [main]
jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Setup Node uses: actions/setup-node@v4 with: node-version: 20
- name: Install pnpm uses: pnpm/action-setup@v2 with: version: 8
- name: Install dependencies run: pnpm install
- name: Build run: pnpm run build
- name: Upload Pages artifact uses: actions/upload-pages-artifact@v3 with: path: dist
deploy: needs: build runs-on: ubuntu-latest permissions: pages: write id-token: write environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v44. 配置 GitHub Pages
进入仓库 Settings → Pages:
- Source 选择 GitHub Actions
5. 推送代码触发部署
git add .git commit -m "add deploy workflow"git push等待几分钟后,你的博客就会上线:https://你的用户名.github.io/astro-firefly
方法二:手动部署
# 构建项目npm run build
# 安装 gh-pages(如果没安装)npm install -g gh-pages
# 部署到 GitHub Pagesgh-pages -d dist支持与分享
如果这篇文章对你有帮助,欢迎分享给更多人或赞助支持!
1. 从零开始部署 Firefly(流萤)Astro 博客并上线 GitHub Pages
https://blogboy.eu.cc/posts/1/ 相关文章 智能推荐
1
3. 博客首页打字机文案配置
博客搭建 博客首页打字机文案配置教程,包含标题、副标题、速度参数和循环打字效果的修改方法。
2
2. 博客首页横幅图片与轮播配置
博客搭建 博客首页横幅图片与轮播配置教程,包含桌面端和移动端图片替换、轮播开关及首页视觉设置。
3
27. 首页框体调整指南
博客搭建 详细介绍 Firefly 博客首页各种框体的布局调整方法,包括侧边栏组件顺序、位置配置和响应式布局优化。
4
26. SEO 与 RSS 订阅配置指南
博客搭建 博客 SEO 与 RSS 配置教程,包含 RSS 订阅、robots、sitemap、OG 信息和基础搜索引擎收录相关说明。
5
25. 相册页面配置指南
博客搭建 博客相册页面配置教程,包含相册开关、相册列表、图片目录结构、封面图规则和相册页面访问方式等内容。
随机文章 随机推荐