This commit is contained in:
Zuoling Rong
2025-02-02 20:17:51 +08:00
parent 7f74b412f2
commit 5aec78c264
2 changed files with 64 additions and 81 deletions

View File

@@ -2,10 +2,11 @@ name: Deploy Navigation Site
on: on:
push: push:
branches: branches: [ main ]
- main
workflow_dispatch: workflow_dispatch:
# 添加fork后的首次运行触发
fork:
jobs: jobs:
build-and-deploy: build-and-deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -18,43 +19,61 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Check GitHub Pages status
id: pages-status
run: |
if [ "$(gh api repos/${{ github.repository }}/pages --jq .status)" != "null" ]; then
echo "GitHub Pages is already enabled"
echo "pages_enabled=true" >> $GITHUB_OUTPUT
else
echo "GitHub Pages needs to be enabled manually"
echo "pages_enabled=false" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ github.token }}
- name: Setup Node.js - name: Setup Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: '16' node-version: '16'
- name: Install dependencies - name: Install dependencies
run: | run: npm install
npm install
if [ $? -ne 0 ]; then
echo "Failed to install dependencies"
exit 1
fi
- name: Generate site - name: Generate site
run: | run: node generator.js
node generator.js
if [ $? -ne 0 ]; then
echo "Failed to generate site"
exit 1
fi
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Deploy to GitHub Pages - name: Deploy to GitHub Pages
if: steps.pages-status.outputs.pages_enabled == 'true'
uses: JamesIves/github-pages-deploy-action@v4 uses: JamesIves/github-pages-deploy-action@v4
with: with:
folder: . folder: .
branch: gh-pages branch: gh-pages
clean: true clean: true
- name: Enable GitHub Pages - name: Create deployment guide issue
run: | if: steps.pages-status.outputs.pages_enabled == 'false'
gh api \ uses: actions/github-script@v6
--method PUT \ with:
-H "Accept: application/vnd.github+json" \ script: |
/repos/${{ github.repository }}/pages \ const issueBody = `
-f source='{"branch":"gh-pages","path":"/"}' # 部署指南
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 请按照以下简单步骤完成网站部署:
1. 进入仓库设置 Settings -> Pages
2. 在 "Source" 下拉菜单中选择 "GitHub Actions"
3. 点击 Save
完成后,工作流将自动部署您的导航站点。
部署完成后,您可以在 Settings -> Pages 中找到您的网站地址。
`;
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '🚀 如何部署您的导航站点',
body: issueBody,
labels: ['documentation']
});

View File

@@ -2,8 +2,6 @@
一个简洁美观的个人导航网站,帮助你整理和展示你的网络收藏。 一个简洁美观的个人导航网站,帮助你整理和展示你的网络收藏。
[![部署状态](https://github.com/RZLNB/menav/actions/workflows/deploy.yml/badge.svg)](https://github.com/RZLNB/menav/actions/workflows/deploy.yml)
## 在线预览 ## 在线预览
访问:[https://rzlnb.github.io/menav/](https://rzlnb.github.io/menav/) 访问:[https://rzlnb.github.io/menav/](https://rzlnb.github.io/menav/)
@@ -53,63 +51,29 @@ npm run generate
## 部署方式 ## 部署方式
### GitHub Pages 一键部署 ### 快速部署到GitHub Pages
只需三步即可完成部署: 1. 点击右上角的 Fork 按钮复制此仓库到您的账号
2. 修改 `config.yml` 中的配置信息
3. 在仓库设置中启用 GitHub Pages:
- 进入仓库的 Settings -> Pages
- 在 "Source" 下拉菜单中选择 "GitHub Actions"
- 点击 Save
1. 点击右上角的 Fork 按钮,复制这个仓库到你的账号 完成以上步骤后,系统会自动部署您的网站。部署完成后,您可以在 Settings -> Pages 中找到您的网站地址。
2. 修改配置文件 > 提示首次fork后,系统会自动创建一个部署指南issue,您可以按照指南完成部署。
- 打开 `config.yml` 文件
- 根据你的需求修改网站内容
- 提交更改
3. 等待自动部署 ### 高级部署选项Cloudflare Pages
- 提交更改后GitHub Actions 会自动开始构建和部署
- 部署完成后,你可以通过 `https://你的用户名.github.io/menav` 访问你的网站
- 部署状态可以在仓库的 Actions 标签页查看
注意首次部署可能需要等待1-2分钟。如果遇到问题 如果您需要更好的访问速度或私有仓库支持,可以选择使用Cloudflare Pages部署:
- 确保仓库设置中的 Actions 权限已启用
- 检查仓库的 Actions 标签页中的部署日志
### Cloudflare Pages 部署 1. 在 [Cloudflare Dashboard](https://dash.cloudflare.com) 中创建新项目
2. 连接您的GitHub仓库
支持公开和私有仓库,完全免费。 3. 使用以下构建配置:
- 构建命令: `npm run generate`
1. Fork 仓库到你的GitHub账号 - 构建输出目录: `/`
- Node.js 版本: `16`或更高
2. 登录 Cloudflare Dashboard
- 进入 Pages 页面
- 点击 "Create a project"
- 选择 "Connect to Git"
- 选择你fork的仓库
3. 设置构建配置
- 构建命令:`npm run generate`
- 构建输出目录:`/`
- Node.js 版本:`16`(或更高版本)
4. 环境变量(可选)
```
NODE_VERSION: 16
```
5. 部署
- 点击 "Save and Deploy"
- Cloudflare Pages 会自动构建和部署你的网站
- 部署完成后,你会得到一个 `*.pages.dev` 的域名
6. 自定义域名(可选)
- 在项目设置中添加你的自定义域名
- 按照 Cloudflare 的说明配置 DNS 记录
优点:
- 全球 CDN 加速
- 自动 HTTPS
- 持续部署
- 免费额度大
- 可以绑定自定义域名
## 自定义配置 ## 自定义配置