跳转到正文
independoc
语言: 中文

部署到 GitHub Pages 与静态托管平台#

independoc build 的输出目录(dist/)仅包含纯静态文件(HTML / CSS / JS / JSON / XML / TXT),无需服务端 Node.js 运行环境,可直接部署到任意静态托管服务。

使用 GitHub Actions 自动发布到 GitHub Pages#

本仓库自带完全无需 npm install 的 GitHub Pages 部署工作流(.github/workflows/pages.yml)。

1. 仓库一次性初始配置#

  1. 打开 GitHub 仓库的 Settings → Pages。
  2. 将 Build and deployment → Source 修改为 GitHub Actions。
  3. 若在合并工作流之后才修改 Source,可前往 Actions → Deploy Docs to GitHub Pages → Run workflow 手动触发首次部署(此后每次推送到 main 都会自动构建发布)。

2. 工作流说明(.github/workflows/pages.yml)#

工作流将 actions/configure-pages 输出的 base_path 传给 --base,并将 origin 传给 --site-url,因此无论使用项目子路径页面(https://<user>.github.io/<repo>/)还是自定义域名,canonical、sitemap 与 llms.txt 中的绝对 URL 都会指向实际公开主机。同时通过 fetch-depth: 0 拉取完整 Git 历史,确保 showLastUpdated: true 能获取每个文件真实的最近提交日期。

.github/workflows/pages.yml
name: Deploy Docs to GitHub Pages

on:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: pages
  cancel-in-progress: false

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v7
        with:
          node-version: 22
      - run: npm test
      - id: pages
        uses: actions/configure-pages@v6
      - name: Build static docs
        env:
          PAGES_BASE_PATH: ${{ steps.pages.outputs.base_path }}
          PAGES_ORIGIN: ${{ steps.pages.outputs.origin }}
        run: |
          BASE_PATH="${PAGES_BASE_PATH:-/}"
          SITE_URL_ARGS=()
          if [ -n "${PAGES_ORIGIN}" ]; then
            SITE_URL_ARGS+=(--site-url "${PAGES_ORIGIN}")
          fi
          node ./bin/independoc.js build --base "${BASE_PATH}" "${SITE_URL_ARGS[@]}" --strict-links
      - uses: actions/upload-pages-artifact@v5
        with:
          path: dist

  deploy:
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - id: deployment
        uses: actions/deploy-pages@v5

其他静态托管平台#

如果需要让 canonical、sitemap 或 llms.txt 中的绝对 URL 指向实际公开主机,请在构建时传入部署源地址,例如 --site-url https://docs.example.com。

  • Build command:node ./bin/independoc.js build --strict-links
  • Output directory:dist
  • Node.js version:22 或更高版本(无需依赖安装命令)

将 dist/ 直接部署到网站根目录或子路径即可。由于所有页面均生成为 <route>/index.html 的目录索引结构,无需 SPA 重写规则。若部署在 Amazon S3,请开启静态网站托管并将默认索引文档设为 index.html,通过网站终端节点访问。

bash
# 示例:部署到内网门户的 /docs/ 子路径下
node ./bin/independoc.js build --base /docs/ --strict-links
编辑此页最后更新:
由 independoc 自身构建 — 0 个 npm 依赖。