Skip to content

Commit 4b2a4b1

Browse files
committed
build: migrate site from GitBook to VitePress
The legacy gitbook CLI (gitbook@3.2.3) crashes under Node 24 because the bundled send module reads res._headers, which no longer exists. Rather than patch dead tooling, switch the build to VitePress: - add .vitepress/config.mts with sidebar converted from SUMMARY.md, local search, edit links, footer and zh-Hans UI - repoint package.json scripts to vitepress (serve/build/preview), drop gitbook and its plugins; regenerate package-lock.json - update the Pages workflow to upload .vitepress/dist - refresh README usage notes and Makefile help/clean targets - prefix relative <img> src in windows-build with ./ so Vite resolves them - remove obsolete book.json and scripts/gitbook.js
1 parent 36a0d72 commit 4b2a4b1

10 files changed

Lines changed: 2101 additions & 7307 deletions

File tree

.github/workflows/pages.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy GitBook to GitHub Pages
1+
name: Deploy VitePress to GitHub Pages
22

33
on:
44
push:
@@ -35,7 +35,7 @@ jobs:
3535
- name: Install dependencies
3636
run: npm ci
3737

38-
- name: Build GitBook
38+
- name: Build with VitePress
3939
run: npm run build
4040

4141
- name: Configure GitHub Pages
@@ -44,7 +44,7 @@ jobs:
4444
- name: Upload GitHub Pages artifact
4545
uses: actions/upload-pages-artifact@v4
4646
with:
47-
path: _book
47+
path: .vitepress/dist
4848

4949
deploy:
5050
runs-on: ubuntu-latest

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ node_modules
1010
# Book build output
1111
_book
1212

13+
# VitePress build output / cache
14+
.vitepress/dist
15+
.vitepress/cache
16+
1317
# eBook build output
1418
*.epub
1519
*.mobi

.vitepress/config.mts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { defineConfig } from 'vitepress'
2+
3+
// https://vitepress.dev/reference/site-config
4+
export default defineConfig({
5+
lang: 'zh-Hans',
6+
title: 'Python 3 源码分析',
7+
description: '致力于分析 Python 3.7.0 的源码实现',
8+
9+
// 部署在 https://flaggo.github.io/python3-source-code-analysis/
10+
base: '/python3-source-code-analysis/',
11+
12+
// 用仓库根目录作为内容源;README.md 作为首页
13+
srcDir: '.',
14+
rewrites: {
15+
'README.md': 'index.md'
16+
},
17+
// 不作为页面渲染的文件 / 旧构建产物
18+
srcExclude: ['SUMMARY.md', '_book/**', '**/node_modules/**'],
19+
20+
lastUpdated: true,
21+
cleanUrls: true,
22+
ignoreDeadLinks: true,
23+
24+
markdown: {
25+
lineNumbers: true
26+
},
27+
28+
themeConfig: {
29+
// https://vitepress.dev/reference/default-theme-config
30+
nav: [
31+
{ text: '首页', link: '/' },
32+
{ text: '大纲', link: '/objects/object/' }
33+
],
34+
35+
sidebar: [
36+
{
37+
text: '第 1 部分:序章',
38+
items: [
39+
{ text: '前言', link: '/' },
40+
{ text: 'Python 源代码的组织', link: '/preface/code-organization/' },
41+
{ text: 'Windows 环境下编译 Python', link: '/preface/windows-build/' },
42+
{ text: 'UNIX/Linux 环境下编译 Python', link: '/preface/unix-linux-build/' },
43+
{ text: '修改 Python 源码', link: '/preface/modify-code/' }
44+
]
45+
},
46+
{
47+
text: '第 2 部分:Python 内建对象',
48+
items: [
49+
{ text: 'Python 对象初探', link: '/objects/object/' },
50+
{ text: 'Python 整数对象', link: '/objects/long-object/' },
51+
{ text: 'Python 字符串对象', link: '/objects/str-object/' },
52+
{ text: 'Python List 对象', link: '/objects/list-object/' },
53+
{ text: 'Python Dict 对象', link: '/objects/dict-object/' },
54+
{ text: 'Python Set 对象', link: '/objects/set-object/' },
55+
{ text: '实现简版 Python', link: '/objects/simple-interpreter/' }
56+
]
57+
},
58+
{
59+
text: '第 3 部分:Python 虚拟机',
60+
items: [
61+
{ text: '(编写中…)', link: '/' }
62+
]
63+
}
64+
],
65+
66+
socialLinks: [
67+
{ icon: 'github', link: 'https://github.com/flaggo/python3-source-code-analysis' }
68+
],
69+
70+
search: {
71+
provider: 'local'
72+
},
73+
74+
editLink: {
75+
pattern: 'https://github.com/flaggo/python3-source-code-analysis/edit/master/:path',
76+
text: '编辑此页面'
77+
},
78+
79+
outline: {
80+
label: '本页目录',
81+
level: [2, 3]
82+
},
83+
84+
docFooter: {
85+
prev: '上一篇',
86+
next: '下一篇'
87+
},
88+
89+
lastUpdated: {
90+
text: '最后更新于'
91+
},
92+
93+
footer: {
94+
copyright: 'Copyright © FlagGo 2019-2026'
95+
},
96+
97+
darkModeSwitchLabel: '主题',
98+
returnToTopLabel: '回到顶部',
99+
sidebarMenuLabel: '菜单'
100+
}
101+
})

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ NPM ?= npm
66

77
help:
88
@printf "\033[32m%-10s\033[0m %s\n" "install" "安装项目依赖"
9-
@printf "\033[32m%-10s\033[0m %s\n" "serve" "运行 GitBook 服务器"
10-
@printf "\033[32m%-10s\033[0m %s\n" "build" "构建 GitBook 静态页面"
9+
@printf "\033[32m%-10s\033[0m %s\n" "serve" "启动本地预览服务器"
10+
@printf "\033[32m%-10s\033[0m %s\n" "build" "构建静态页面"
1111
@printf "\033[32m%-10s\033[0m %s\n" "clean" "删除构建产物"
1212

1313
install:
@@ -20,4 +20,4 @@ build:
2020
$(NPM) run build
2121

2222
clean:
23-
rm -rf _book
23+
rm -rf _book .vitepress/dist .vitepress/cache

README.md

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,42 @@
88

99
您可以直接访问 [在线版](https://flaggo.github.io/python3-source-code-analysis/),或者根据以下步骤访问本地版。
1010

11-
## 前置条件
12-
13-
您的系统上需要安装好 node (会自带npm)。
11+
本项目使用 [VitePress](https://vitepress.dev/) 构建。
1412

15-
## 使用 make 或者使用 npm 命令去构建
13+
## 前置条件
1614

17-
### 使用 make 命令的方式构建:
15+
您的系统上需要安装好 Node.js 18 及以上版本(会自带 npm)。
1816

19-
若您可使用 make 命令,简单执行如下命令安装依赖:
17+
## 安装依赖
2018

2119
```console
22-
make install
20+
npm install
2321
```
2422

25-
执行如下命令运行服务端:
23+
## 本地预览
2624

27-
```console
28-
make serve
29-
```
30-
31-
执行如下命令构建静态页面:
25+
启动本地开发服务器(支持热更新):
3226

3327
```console
34-
make build
28+
npm run dev
3529
```
3630

37-
### 使用 npm 命令的方式构建:
38-
39-
若您不能使用 make 命令,或想直接使用 npm 命令,执行如下命令安装依赖:
31+
然后访问 http://localhost:5173/python3-source-code-analysis/ 即可查看本书内容。
4032

41-
安装项目依赖:
33+
> 也可以使用 `make serve`,等价于 `npm run dev`
4234
43-
```console
44-
npm install
45-
```
46-
47-
执行如下命令运行服务端:
35+
## 构建静态页面
4836

4937
```console
50-
npm run serve
38+
npm run build
5139
```
5240

53-
执行如下命令构建静态页面
41+
构建产物输出到 `.vitepress/dist`,可用如下命令在本地预览构建结果
5442

5543
```console
56-
npm run build
44+
npm run preview
5745
```
5846

59-
## 访问
60-
61-
直接访问 http://localhost:4000 即可查看本书内容。
62-
6347
# Roadmap
6448

6549
大体按照《Python 源码剖析》中的目录结构进行编写。依次介绍 Python 源码基本信息、内建对象和虚拟机。

book.json

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)