Windows安装Sphinx+Github+Readthedocs创建开源电子书

Gitbook在国内无法使用,只能采用其他的平台写电子书了。

本文介绍了如何使用Sphinx创建电子书,用VS Code编辑文档,实时查看文件的网页效果,将电子书托管到Github上,并在Readthedocs平台发布。

安装各类必要工具

安装Git

https://git-scm.com/download/win

安装完成后,用Windows Terminal测试

git --version

安装python

https://www.python.org/downloads/

安装完成后,测试

python -V

pip3 --version

安装sphinx

pip3 install sphinx doc8 sphinx-autobuild

创建文档

安装Github Desktop

登录账号,创建一个项目TestBook,选择合适的License,publish到Github网站上(KX上网),选择公开项目,不需要private。

Current repository 
TestBook 
Changes 
O changed files 
Current branch 
mam 
History 
Publish repository 
Publish this repositoryto GitHub 
No local changes 
There are no uncommitted changes in this repository. Here are some friendly 
suggestions for what to do next. 
Publish ymar repository to GitHub 
This repository is currently only available on your local machine. By 
publishing it on GitHub you can share it, and collaborate with others. 
Always available in the toolbar for local repositories or Ctrl P 
blish reposito 
Open the repository in pur external editor 
Select your editor in Options 
Repository menu or Ctrl Shift A 
View the files of your repository in Explorer 
Repository menu or Ctrl Shift F 
Open in Visual Studio Code 
Show in Explorer

在本地TeskBook目录中初始化

进入TestBook目录,右键“在此打开Terminal”,键入

sphinx-quickstart

填写必要的项目信息后,即初始化成功。

其中第一个选项,可以选择yes,使目录保持各自独立,有source和build两个文件夹。

编辑文档

安装VS Code,及其插件reStructuredText。

打开TestBook目录,在source目录中新建一个文件夹和文件,编辑。

EXPLORER 
> OPEN EDITORS 
v SMARTPARK 
> .vscode 
> build 
> _build 
> _static 
) _templates 
2021 
conf.py 
index.rst 
.gitattributes 
make. bat 
M Makefile

然后编辑index.rst,将新文件加入到目录中

9 
le 
111 
12 
14 
15 
16 
17 
19 
21 
toctree: : 
:maxdepth: 2 
:caption: 188: 
2021/ 
Indices and tables 
* 
* 
* 
: ref: genindex• 
modindex• 
: ref: 
: ref: search

回到Terminal中,生成html文件查看

make html

在build/html目录中直接打开网页文件,查看效果。

实施预览

也可以在VS Code中实时预览正在编辑的rst文件,点击预览的按钮。

index.rst M X 
source) Z- index.rst ) 
1 
2 
3 
4 
5 
61 
7 
8 
9 
10 
Ill 
12 
13 
14 
15 
16 
17 
18 
19 
21 
documentation master file, crea ed b} 
sphinx-quickstart on Mon Jul 5 2021 
You can adapt this file completely to yo r lil 
contain the root 'toctree' directive. 
Preview index.rst x 
Indices and tables 
toctree: : 
: maxdepth : 
: caption : 
2021/ 
2 
Indices 
* : ref: 
* : ref: 
* : ref: 
and tables 
genindex 
modindex 
search

托管到Readthedocs平台

使用Github Desktop commit和push到Github网站上,也可以用命令行。

https://readthedocs.org/ 网站用github注册账号,可以看到刚建的TestBook项目。

在网站上构建电子书后,即可查看电子书了。

latest 
main 
maun 
Build version
https://smartpark.readthedocs.io/en/main/ 
Navigation 
Contents: 
Quick search 
Welcome to IN X 's 
documentation! 
Contents: 
Indices and tables 
• Index 
• Module Index 
• Search Page

大功告成!


评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注