mkdocs的站点部署到GitHub项目页

工具Markdocs搭建的site如何通过GitHub pages部署?

部署之前,先了解此工具是如何建站的。https://www.mkdocs.org/getting-started/#deploying
总之,把site上传到托管的地方(github pages、read the docs)即可。

以GitHub为例,

1.打开仓库,开启Pages
Settings​ → Pages
Build and deployment的source有两个选项:Deploy from a branch,Github Actions,默认是Deploy from a branch

2.确认 Environment 存在
Settings → Environments
确认有 github-pages(没有就 New environment → 填 github-pages)

方法一:自动化Github Action:

在项目仓库中,在 .github/workflows 目录下创建一个名为 myproject-actions.yml 的工作流文件
yml文件中写入:

name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
  Explore-GitHub-Actions:
    runs-on: ubuntu-latest
    steps:
      - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
      - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
      - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
      - name: Check out repository code
        uses: actions/checkout@v6
      - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
      - run: echo "🖥️ The workflow is now ready to test your code on the runner."
      - name: List files in the repository
        run: |
          ls ${{ github.workspace }}
      - run: echo "🍏 This job's status is ${{ job.status }}."

工作流写法

方法二:Deploy from a branch

mkdocs官方文档的部署页面介绍了这一种方法。

mkdocs gh-deploy
# = mkdocs build → 把 site/ 推到 gh-pages 分支 → push 到 GitHub

参考文档

https://www.mkdocs.org/getting-started/#deploying
https://www.mkdocs.org/user-guide/deploying-your-docs/
https://learn.github.com/

posted @ 2026-11-29 20:44  lemon孟  阅读(4)  评论(0)    收藏  举报