dumi搭建python常用库文档,自动化部署到github pages上

146 阅读1分钟

awesome-python文档搭建

初始化

环境准备

确保正确安装 Node.js 且版本为 14+ 即可。

$ node -v
v14.19.1

脚手架

# 先找个地方建个空目录。
$ mkdir myapp && cd myapp

# 通过官方工具创建项目,选择你需要的模板
$ npx create-dumi

# 选择一个模板
$ ? Pick template type › - Use arrow-keys. Return to submit.
$ ❯   Static Site # 用于构建网站
$     React Library # 用于构建组件库,有组件例子
$     Theme Package # 主题包开发脚手架,用于开发主题包

# 安装依赖后启动项目
$ npm start

目录结构

 $  tree -L 2 -a  -I 'node_modules|.git'
.
|-- .dumi
|   |-- favicon.png
|   |-- global.less
|   |-- tmp
|   `-- tmp-production
|-- .dumirc.ts
|-- .editorconfig
|-- .github
|   `-- workflows
|-- .gitignore
|-- .hintrc
|-- .husky
|   |-- commit-msg
|   `-- pre-commit
|-- .prettierignore
|-- .prettierrc.js
|-- LICENSE
|-- README.md
|-- docs
|   |-- index.en-US.md
|   |-- index.md
|   `-- python
|-- package-lock.json
|-- package.json
|-- public
|   `-- logo.png
`-- tsconfig.json

编辑好对应的文档放入doc文件夹下

|-- docs
|   |-- index.en-US.md
|   |-- index.md
|   `-- python

配置.dumirc.ts

import { defineConfig } from 'dumi';

export default defineConfig({
  themeConfig: {
    name: 'Awesome Python',
    rtl: true,
    socialLinks: {
      github: 'https://github.com/andybuibui/awesome-python',
    },
    nav: [],
    footer: `Awesome Python | Copyright © 2024-present`,
    logo: '/awesome-python/logo.png',
  },
  locales: [
    { id: 'zh-CN', name: '中文' },
    { id: 'en-US', name: 'EN' },
  ],
  base: `/awesome-python/`,
  publicPath: `/awesome-python/`,
});

  • 部分配置参数说明
  1. logo
  2. base: /awesome-python/
  3. publicPath: /awesome-python/

*** 这里添加/awesome-python 前缀方便后面部署到github pages上***

配置GIT_TOKEN

配置 workflow action

name: GitHub Actions Build and Deploy Demo
on:
  push:
    branches: ["main"]
permissions:
  contents: read
  pages: write
  id-token: write
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x]
    steps:
    - name: Checkout
      uses: actions/checkout@v4
      
    - name: Install dependencies
      run: npm install

    - name: Build
      run: npm run build

    - name: Deploy to GitHub Pages
      uses: JamesIves/github-pages-deploy-action@v4
      with:
        token: ${{ secrets.GIT_TOKEN }}
        branch: gh-pages
        folder: dist

配置仓库pages

  • 首先得有个username.github.io 仓库,pages.github.com/
  • 配置当前仓库的pages awesome-python/settings/pages
  • 配置为gh-pages分支

image.png

Preview

image.png

image.png

TODO:

  • 部分未翻译
  • 弃用包删除
  • 流行包添加

功能点

  • dumi 搭建文档的使用

  • github action 自动化部署pages

  • python 常用包收集

  • awesome-python

  • github

欢迎PR 和 star