使用ReadtheDocs托管文档

简介: 很多的技术文档都是使用的ReadtheDocs,比如Python文档、tornado文档等等。今天我们一起来看看怎么使用ReadtheDocs托管文档。
WangScaler: 一个用心创作的作者。

声明:才疏学浅,如有错误,恳请指正。

很多的技术文档都是使用的ReadtheDocs,比如Python文档、tornado文档等等。虽然不是很美观,但是对于技术博文来说够用了。

一、安装Python

使用ReadtheDocs需要有python3的环境,因为sphinx是基于 python3 的。那么我们首先安装python环境,如果你有python环境,可以直接跳过这一步,直接浏览安装Sphinx。

1、下载python

选择python官网下载。可能比较慢,慢慢等待一会。选择Download下载安装包。

python2.png
根据你的环境下载,我这里下载的Windows的64位最新版本的安装包。
python3.png

2、安装

python4.png

Add python 3.8 to PATH 自动给环境变量添加python的路径。相当于给你的电脑自动配置了python环境,在全局任意位置均可直接使用python。

python5.png

表示安装成功,那么我们的电脑到底是否具备了python环境,接下来进行验证。

3、验证

Win+R 打开cmd输入python。

python6.png

我们看到了python的版本信息,恭喜你大功告成了,接下来正式进入我们的话题。

二、安装Sphinx

Sphinx 是一个功能强大的文档生成器,具有许多用于编写技术文档的强大功能,Sphinx 最早只是用来生成 Python 官方文档,随着工具的完善, 越来越多的知名的项目也用他来生成文档。

1、安装Sphinx

pip install sphinx sphinx-autobuild sphinx_rtd_theme

2.初始化

window下:

d:
cd /wangscaler/
sphinx-quickstar

linux下

# 创建文档根目录
mkdir -p /usr/local/wangscaler/
cd /usr/local/wangscaler/
# 可以回车按默认配置来写
sphinx-quickstart

下面是我填写的,其他基本上默认即可:

> Separate source and build directories (y/n) [n]:y
> Project name: WangScaler
> Author name(s): WangScaler
> Project version []: 0.2
> Project release [1.0]: 0.2.2
> Project language [en]: zh_CN

3.安装软件tree查看目录树结构:

windows

tree

linux

yum install tree
tree -C .

三、支持markdown编写以及切换主题

recommonmark是支持markdown的插件,而sphinx-markdown-tables则是主题,因为默认的主题是不好看的,我们可以使用这个主题来优化我们的界面。

1.安装插件

pip install recommonmark
pip install sphinx-markdown-tables

2.修改配置

然后更改conf.py,我的配置如下:

# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
​
# -- Path setup --------------------------------------------------------------
​
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
import shlex
sys.path.insert(0, os.path.abspath('.'))
​
import recommonmark
from recommonmark.transform import AutoStructify
# -- Project information -----------------------------------------------------
source_suffix = ['.rst', '.md']
​
master_doc = 'index'
​
project = 'Interface'
copyright = '2021, WangScaler'
author = 'WangScaler'
version = recommonmark.__version__
# The full version, including alpha/beta/rc tags
release = recommonmark.__version__
​
​
# -- General configuration ---------------------------------------------------
​
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.napoleon',
    'sphinx.ext.mathjax',
    'recommonmark',
    'sphinx_markdown_tables',
]
​
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
​
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'zh_CN'
​
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build']
default_role = None
pygments_style = 'sphinx'
todo_include_todos = False
# -- Options for HTML output -------------------------------------------------
​
# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
​
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
htmlhelp_basename = 'Recommonmarkdoc'
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
​
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
​
# Additional stuff for the LaTeX preamble.
#'preamble': '',
​
# Latex figure (float) alignment
#'figure_align': 'htbp',
}
​
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
#  author, documentclass [howto, manual, or own class]).
latex_documents = [
  (master_doc, 'Recommonmark.tex', u'Recommonmark Documentation',
   u'Lu Zero, Eric Holscher, and contributors', 'manual'),
]
man_pages = [
    (master_doc, 'recommonmark', u'Recommonmark Documentation',
     [author], 1)
]
texinfo_documents = [
  (master_doc, 'Recommonmark', u'Recommonmark Documentation',
   author, 'Recommonmark', 'One line description of project.',
   'Miscellaneous'),
]
​
# At the bottom of conf.py
# def setup(app):
#     app.add_config_value('recommonmark_config', {
#         #'url_resolver': lambda url: github_doc_root + url,
#         'auto_toc_tree_section': 'Contents',
#         'enable_math': False,
#         'enable_inline_math': False,
#         'enable_eval_rst': True,
#         'enable_auto_doc_ref': True,
#     }, True)
#     app.add_transform(AutoStructify)
​

3、编写文件

框架已经搭建的差不多了,就来写我们的第一篇文章吧。

在source目录下新建hello.rst,内容如下:

# My New Learning
## 一、Mongo(Montor异步数据库)

4、修改index.rst文件

这个文件是我们博客的目录,当我们有了新的文章可以加入到这个目录中。

.. Test documentation master file, created by
   sphinx-quickstart on Mon Jul 20 09:49:03 2020.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.
​
Welcome to Interface Document!
================================
.. toctree::
   :maxdepth: 2
   :caption: 名字:
​
​
   hello
​
Indices and tables
==================
​
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
​
​

5、编译文件

在根目录执行make html,将我们的文件编译成网页。我们的任务就完成了,准备访问我们的博客吧。

6、预览效果

进入build/html目录后用浏览器打开index.html

7、静态网页的部署

编译的网页,可以通过nginx部署访问,可以参考我的往期文章Nginx的常用操作将静态网页放在指定的位置,即可轻松访问了。

四、遇到的问题

1.图片不显示

解决方案:

  • 1、图片使用图床加载
  • 2、使用相对路径,如/images/a.jpg

注意:路径是/而非\ 第二种不可行

2.表格不显示

pip install sphinx-markdown-tables

在conf.py文件中修改

extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.napoleon',
    'sphinx.ext.mathjax',
    'recommonmark',
    'sphinx_markdown_tables',#这句话支持markdown表格
]
来都来了,点个赞再走呗!

关注WangScaler,祝你升职、加薪、不提桶!

目录
相关文章
|
监控 C++ Windows
排错实战——使用process explorer替换任务管理器
可以使用 process explorer 替换任务管理器,本文使用 proccess monitor 监控整个过程
|
Windows
Windows 10下安装Miniconda3
Windows 10下安装Miniconda3
4107 1
Windows 10下安装Miniconda3
|
Docker Python 容器
解决ModuleNotFoundError: No module named ‘distutils.util‘
解决ModuleNotFoundError: No module named ‘distutils.util‘
1603 0
|
开发工具 git C++
『实用教程』使用Visual Studio自带的Git管理回滚代码版本
使用Visual Studio自带的Git管理回滚代码版本
3137 0
『实用教程』使用Visual Studio自带的Git管理回滚代码版本
|
机器学习/深度学习 缓存 监控
linux查看CPU、内存、网络、磁盘IO命令
`Linux`系统中,使用`top`命令查看CPU状态,要查看CPU详细信息,可利用`cat /proc/cpuinfo`相关命令。`free`命令用于查看内存使用情况。网络相关命令包括`ifconfig`(查看网卡状态)、`ifdown/ifup`(禁用/启用网卡)、`netstat`(列出网络连接,如`-tuln`组合)以及`nslookup`、`ping`、`telnet`、`traceroute`等。磁盘IO方面,`iostat`(如`-k -p ALL`)显示磁盘IO统计,`iotop`(如`-o -d 1`)则用于查看磁盘IO瓶颈。
2163 10
|
弹性计算 应用服务中间件 数据库
阿里云2核2G服务器够用吗?能支持多少人在线访问?
阿里云2核2G服务器适合个人博客、小型网站及轻量应用,3M带宽可支持日均千次访问,200M峰值带宽应对突发流量更佳。具体承载人数取决于应用类型、优化程度与带宽,高并发场景建议升级配置或使用CDN等优化手段提升性能。
2211 115
|
监控 供应链 搜索推荐
实时同步淘宝订单数据接口,实现订单状态实时监控与管理
本项目旨在为中小微及大型电商企业提供高效、稳定的淘宝订单数据接口解决方案。针对不同行业需求,提供实时订单监控、库存同步、物流追踪等功能,助力企业提升运营效率,优化供应链管理。通过线上线下多渠道推广与精准营销策略,实现产品快速落地与品牌影响力提升。
|
缓存 架构师 Linux
内存优化-如何使用tcmalloc来提升内存性能?提升的结果太不可思议
内存优化-如何使用tcmalloc来提升内存性能?提升的结果太不可思议
|
定位技术 图形学
【用unity实现100个游戏之17】从零开始制作一个类幸存者肉鸽(Roguelike)游戏1(附项目源码)
【用unity实现100个游戏之17】从零开始制作一个类幸存者肉鸽(Roguelike)游戏1(附项目源码)
2752 0