5 陈照强 使用Sphinx编写Web文档

2020-03-01 253浏览

  • 1.Sphinx制作精美文档 陈照强 2019-9-21
  • 2.目录 CONTENTS 精美文档示例 谁发明了Sphinx 快速实践 我的Sphinx文档介绍
  • 3.1 精美Sphinx文档示例
  • 4.Sphinx精美文档示例https://www.sphinx-doc.org/en/master/examples.htmlhttps://matplotlib.org/https://docs.scrapy.org/en/latest/
  • 5.Sphinx文档的优点  丰富的输出格式  精确的语法高亮  完备的交叉引用  开放的扩展插件  明晰的分层结构  多种丰富美观的主题  美观的自动索引  简单、方便  … ….  … …. Sphinx 为python社区的快速发展立下了汗马功劳
  • 6.2 谁发明了Sphinx
  • 7.谁发明了Sphinx Georg Brandl Original author of Sphinx Python core developer Armin RonacherGithub:2700+个star, co-maintainers:10个 parts of the templatesConrtibutor:400个 Flask、Jinja2 开源项目
  • 8.3 快速实践
  • 9.快速实践-安装sphinx conda install -c anaconda sphinx OR python –m pip install sphinx
  • 10.快速实践-quickstart $ sphinx-quickstart Welcome to the Sphinx 1.7.4 quickstart utility. > Separate source and build directories (y/n) [n]: > Name prefix for templates and static dir [_]: > Projectname:pycon2019 > Author name(s): czq > Project release []: > Project language [en]: > Name of your master document (without suffix) [index]: > Do you want to use the epub builder (y/n) [n]: >autodoc:automatically insert docstrings from modules (y/n) [n]: >… … tree . -- _build -- conf.py -- index.rst -- make.bat -- Makefile -- _static `-- _templates
  • 11.快速实践-生成文档 推荐使用主题,Read the Docs,简洁大方 ```py conf.py import sphinx_rtd_theme #html_theme = 'alabaster' html_theme = 'sphinx_rtd_theme’ ``` 在Makefile同级目录运行  make html 生成静态web网页  make latexpdf 生成PDF 文件
  • 12.我的Sphinx文档http://pymol.chenzhaoqiang.com/
  • 13.我的Sphinx文档 微信公众号 PythonPerl
  • 14.为Sphinx文档添加Google Analytics 方法一 修改模板文件: 默认主题位置: xxx/python2.7/site-packages/sphinx/themes rtd主题位置: xxx/python2.7/ site-packages/sphinx_rtd_theme cd ~/pymolcn/source/_templates 创建layout.html
  • 15.为Sphinx文档添加Google Analysis 方法一 修改模板文件: {% extends "!layout.html" %} {% block footer %} {{ super() }}var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "googleanalytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));try { var pageTracker = _gat._getTracker("YOUR_GOOGLE_CODE_HERE"); pageTracker._trackPageview(); } catch(err) {}{% endblock %}
  • 16.为Sphinx文档添加Google Analysis 方法二 修改conf.py配置文件 def setup(app): """Insert Google Analytics tracker Based on this Stackoverflowsuggestion:stackoverflow.com/a/41885884 """ app.add_javascript("googletagmanager.co m/gtag/js?id=UA-XXXXXXX") app.add_javascript("google_analytics_tr acker.js")
  • 17.THANK YOU ZqCSky 744891290 18321885908 二维码