From 5aec78c264a9a752c8f6c7cba79e169de6da5a26 Mon Sep 17 00:00:00 2001 From: Zuoling Rong Date: Sun, 2 Feb 2025 20:17:51 +0800 Subject: [PATCH] 1.22 --- .github/workflows/deploy.yml | 75 ++++++++++++++++++++++-------------- README.md | 70 ++++++++------------------------- 2 files changed, 64 insertions(+), 81 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e4525c1..6f828c6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,10 +2,11 @@ name: Deploy Navigation Site on: push: - branches: - - main + branches: [ main ] workflow_dispatch: - + # 添加fork后的首次运行触发 + fork: + jobs: build-and-deploy: runs-on: ubuntu-latest @@ -18,43 +19,61 @@ jobs: - name: Checkout repository 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 uses: actions/setup-node@v3 with: node-version: '16' - name: Install dependencies - run: | - npm install - if [ $? -ne 0 ]; then - echo "Failed to install dependencies" - exit 1 - fi + run: npm install - name: Generate site - run: | - node generator.js - if [ $? -ne 0 ]; then - echo "Failed to generate site" - exit 1 - fi - - - name: Setup Pages - uses: actions/configure-pages@v4 + run: node generator.js - name: Deploy to GitHub Pages + if: steps.pages-status.outputs.pages_enabled == 'true' uses: JamesIves/github-pages-deploy-action@v4 with: folder: . branch: gh-pages clean: true - - - name: Enable GitHub Pages - run: | - gh api \ - --method PUT \ - -H "Accept: application/vnd.github+json" \ - /repos/${{ github.repository }}/pages \ - -f source='{"branch":"gh-pages","path":"/"}' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + + - name: Create deployment guide issue + if: steps.pages-status.outputs.pages_enabled == 'false' + uses: actions/github-script@v6 + with: + script: | + const issueBody = ` + # 部署指南 + + 请按照以下简单步骤完成网站部署: + + 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'] + }); \ No newline at end of file diff --git a/README.md b/README.md index 6130329..68d043a 100644 --- a/README.md +++ b/README.md @@ -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/) @@ -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. 修改配置文件 - - 打开 `config.yml` 文件 - - 根据你的需求修改网站内容 - - 提交更改 +> 提示:首次fork后,系统会自动创建一个部署指南issue,您可以按照指南完成部署。 -3. 等待自动部署 - - 提交更改后,GitHub Actions 会自动开始构建和部署 - - 部署完成后,你可以通过 `https://你的用户名.github.io/menav` 访问你的网站 - - 部署状态可以在仓库的 Actions 标签页查看 +### 高级部署选项:Cloudflare Pages -注意:首次部署可能需要等待1-2分钟。如果遇到问题: -- 确保仓库设置中的 Actions 权限已启用 -- 检查仓库的 Actions 标签页中的部署日志 +如果您需要更好的访问速度或私有仓库支持,可以选择使用Cloudflare Pages部署: -### Cloudflare Pages 部署 - -支持公开和私有仓库,完全免费。 - -1. Fork 仓库到你的GitHub账号 - -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 -- 持续部署 -- 免费额度大 -- 可以绑定自定义域名 +1. 在 [Cloudflare Dashboard](https://dash.cloudflare.com) 中创建新项目 +2. 连接您的GitHub仓库 +3. 使用以下构建配置: + - 构建命令: `npm run generate` + - 构建输出目录: `/` + - Node.js 版本: `16`或更高 ## 自定义配置