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 用户:

  1. 访问 https://git-scm.com/download/win
  2. 下载最新版本,一路点击”Next”即可
  3. 安装完成后,打开命令行输入 git --version 验证

macOS 用户:

打开终端,输入:

Terminal window
git --version

如果没有安装,会提示你安装 Xcode Command Line Tools。

2.2 安装 Node.js#

Windows / macOS / Linux 用户:

  1. 访问 https://nodejs.org/
  2. 下载 LTS(长期支持版)推荐版本
  3. 双击安装包安装

安装完成后,打开命令行验证:

Terminal window
node --version
npm --version

看到版本号表示安装成功。

3. 本地快速运行#

先确保装了 Node.js(18+ 版本)

Terminal window
# 克隆项目
git clone https://github.com/cccoder159/astro-firefly.git
cd 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.logologo 图标(可换图标)

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-18
categories: [分类]
tags: [标签1, 标签2]
---
这里写正文

6. 部署到 GitHub Pages#

方法一:使用 GitHub Actions 自动部署#

1. 创建 GitHub 仓库

在 GitHub 上创建一个新仓库,例如:astro-firefly

2. 上传代码到仓库

Terminal window
# 初始化 git
git init
# 添加所有文件
git add .
# 提交
git commit -m "first commit"
# 添加远程仓库(替换为你的仓库地址)
git remote add origin https://github.com/你的用户名/astro-firefly.git
# 推送
git branch -M main
git push -u origin main

3. 创建 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@v4

4. 配置 GitHub Pages

进入仓库 Settings → Pages:

  • Source 选择 GitHub Actions

5. 推送代码触发部署

Terminal window
git add .
git commit -m "add deploy workflow"
git push

等待几分钟后,你的博客就会上线:https://你的用户名.github.io/astro-firefly

方法二:手动部署#

Terminal window
# 构建项目
npm run build
# 安装 gh-pages(如果没安装)
npm install -g gh-pages
# 部署到 GitHub Pages
gh-pages -d dist

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或赞助支持!

赞助
1. 从零开始部署 Firefly(流萤)Astro 博客并上线 GitHub Pages
https://blogboy.eu.cc/posts/1/
作者
Coldairboy
发布于
2026-03-24
许可协议
CC BY-NC-SA 4.0

评论区

Profile Image of the Author
Coldairboy
记录学习笔记、折腾过程和日常灵感。
公告
Hi,欢迎来到 Coldairboy学习笔记。
音乐
封面

音乐

暂未播放

0:00 0:00
暂无歌词
分类
标签
站点统计
文章
31
分类
3
标签
5
总字数
36,702
运行时长
0 天
最后活动
0 天前

目录