这里是总结了一下,用的工具或者平台:readthedocsgithub 、sphinx。 使用这三个工具即可轻松创建高效的文档管理库,可以用来翻译,水平再高一点可以写书。

文档托管的平台,能够和常用的GIT阵营的github,HG阵营的Bitbucket,关于这两个平台的讨论比较文章可以参考。

代码托管

文档书写利器,使用的是reStructuredText格式,reStructuredText简明教程

下面说说书写方法及托管流程
  1. 在这里注册一个帐号-->登录。
  2. git的帐号及使用大家应该很熟悉了,在这里不再赘述。创建一个repo以存放sphinx(我测试用的a-test-sphinx-doc)。
  3. 安装sphinx,快速入门

    jwch的成员有人整理这个文档使用shpinx记笔记,按照这个来就可以。

  4. 将sphinx生成的文档和配置 push 到git代码仓库[a-test-sphinx-doc]

    evenvi@evenvi-MS-7302:~/mydoc$ git init
    evenvi@evenvi-MS-7302:~/mydoc$ git add .
    evenvi@evenvi-MS-7302:~/mydoc$ git commit -m "test sphinx doc"
    evenvi@evenvi-MS-7302:~/mydoc$ git remote add origin https://github.com/yinlianwei/a-test-sphinx-doc.git
    evenvi@evenvi-MS-7302:~/mydoc$ git push origin master

    经过这些就把你的sphinx生成的文档及一些配置文件等,push到了github

  5. 把github中的文档的代码仓库导入到readthedocs

  • 首先在github->repo->Admin-ServiceHooks->ReadTheDocs,激活这个选项。
  • readthedocs->Import 按照上边的有关字段的提示填写清楚,必要的Name Author Version Repo……,这里注意 conf.py 路径要填写正确(source/conf.py),提交。

这样就文档导入到了readthedocs中,则还是我的测试文档,readthedocs的文档主题简洁,比较不错。当然如果你自己有web服务器,就不用那么麻烦,这里最大好处不用自己维护服务器,可以充分利用github的功能。

sphinx安装使用:

先安装好Python环境,建议选择Pyhon2.7.3,并且把Python及Python/Scripts目录加入环境变量,然后只需要一行命令即可

easy_install -U Sphinx

安装完毕之后,进入任意目录,运行

sphinx-quickstart

会进入一个设置向导,根据向导一步一步设置文档项目,其实必填项只有项目名称,作者和版本,其他设置都可以一路回车:

  1. 文档根目录(Root path for the documentation),默认为当前目录(.)
  2. 是否分离文档源代码与生成后的文档(Separate source and build directories): y
  3. 模板与静态文件存放目录前缀(Name prefix for templates and static dir):_
  4. 项目名称(Project name) : EvaEngine
  5. 作者名称(Author name):AlloVince
  6. 项目版本(Project version) : 1.0.1
  7. 文档默认扩展名(Source file suffix) : .rst
  8. 默认首页文件名(Name of your master document):index
  9. 是否添加epub目录(Do you want to use the epub builder):n
  10. 启用autodoc|doctest|intersphinx|todo|coverage|pngmath|ifconfig|viewcode:n
  11. 生成Makefile (Create Makefile):y
  12. 生成windows用命令行(Create Windows command file):y

最后会生成Sphinx一个文档项目必需的核心文件,包括:

readthedocs
│ make.bat
│ Makefile
├─build
└─source
  │ conf.py
  │ index.rst
  ├─_static
  └─_templates

如果向导中的所有设置都保存在conf.py中,可以随时调整。

Sphinx生成文档

source目录就是存放文档源代码的目录,默认的索引页面为index.rst

我们尝试来写作第一篇文档,在source目录下建立helloworld.rst,内容为:

Hello World ===========

同时编辑index.rst对应部分为

.. toctree::
:maxdepth: 1 helloworld

然后在当前目录下运行

make html

会看到build目录下会生成HTML格式的文档。同理我们可以make letex生成LeTex以及其他格式。

参考:

https://read-the-docs.readthedocs.org/en/latest/getting_started.html

http://avnpc.com/pages/writing-best-documentation-by-sphinx-github-readthedocs

如何结合github和sphinx?

主要参考:http://daler.github.io/sphinxdoc-test/includeme.html

Publishing sphinx-generated docs on github

github allows the publishing of static pages associated with a particular repository (called project pages), which you can read more about at http://pages.github.com/,

I frequently use Sphinx (http://sphinx.pocoo.org/) for documenting projects, and would like to have my docs for a repo published to the gh-pages for that repo.

This strategy uses ideas from http://lucasbardella.com/report/hosting-your-sphinx-docs-in-github/, which uses a separate directory for docs and keeps the autogenerated stuff out of the main repo. This in contrast to suggestions on http://pages.github.com/, which does stuff within the repo directory. Using a separate docs dir made things easier for me to figure out and configure easier with the Sphinx makefile.

See http://daler.github.com/sphinxdoc-test for the Sphinx-generated version of this README, created using the commands documented in it...

Protocol

Set up main repository (

main repo建立一个docs文件夹,存放rst源文件

First set up your main repo. These are the commands I used to set up this very repo (how meta!):

mkdir sphinxdoc-test
cd sphinxdoc-test
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:daler/sphinxdoc-test.git
git push origin master

Throughout this document, I’ll refer to this as the ‘main repo’ or the ‘code dir’.

Set up sphinx within main repository

Make a dir, docs, that will store documentation source from Sphinx:

mkdir sphinxdoc-test/docs

Then set up Sphinx from the docs dir, accepting all the defaults as you see fit:

cd docs
sphinx-quickstart

Set up separate docs repository

建立一个sphinxdoc-test-docs文件夹(放在分支gh-pages)存放生成的html文件等)。

Now we need to set up a completely new directory that will serve as the build directory for Sphinx. Here I’m calling it sphinxdoc-test-docs. Note that it’s outside of the main repo dir:

cd ..
mkdir sphinxdoc-test-docs
cd sphinxdoc-test-docs

Then clone the repo you just set up on github into a dir called html (which will be created automatically with the following command):

git clone git@github.com:daler/sphinxdoc-test.git html
cd html

The html dir now has a clone of the repo.

Next, create a new branch called gh-pages. This is a special branch name that github looks for in order to build static html pages:

git branch gh-pages

The following commands do git fancy stuff that I don’t completely understand yet, suffice to say that after these 3 commands you switch to the new branch gh-pages and the branch is cleaned out with no files in it:

git symbolic-ref HEAD refs/heads/gh-pages  # auto-switches branches to gh-pages
rm .git/index
git clean -fdx

And confirm we’re on gh-pages:

git branch

I’ll refer to this as the ‘gh-pages repo’.

Makefile changes

OK, now the docs repo is set up. Now it’s time to make some changes to the sphinx-generated Makefile back in the main repo so that it builds documentation in our new gh-pages branch and directory, instead of cluttering the main code dir.

So go back to the code dir’s doc dir:

cd ../sphinxdoc-test
cd docs

Here are the changes we’re going to make to sphinxdoc-test/docs/Makefile . . . first, change:

BUILDDIR      = build

to:

BUILDDIR      = ../../sphinxdoc-test-docs
PDFBUILDDIR = /tmp
PDF = ../manual.pdf

The first new line points to the new dir and gh-pages branch we just set up. So now, running make html in sphinxdoc-test/docs will create anhtml dir in ../../sphinxdoc-test-docs . . . and luckily, that’s exactly what we set up the gh-pages repo in.

Before the next two lines make sense, need to make another change . . . I’ve added commented lines pointing to the changes:

latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
make -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."

to:

latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(PDFBUILDDIR)/latex
# ^^^
@echo "Running LaTeX files through pdflatex..."
make -C $(PDFBUILDDIR)/latex all-pdf
# ^^^
cp $(PDFBUILDDIR)/latex/*.pdf $(PDF)
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@echo "pdflatex finished; see $(PDF)"

All these PDF build dir changes put all the LaTeX stuff in a temporary directory, and then only copy the resulting PDF file to the root dir of the main repo. So no cluttering of the main repo with autogenerated doc files, only the latest build of the PDF manual is included.

index.rst changes

Next, I’d like to only worry about making changes in a single file (README.rst), and have that propagated to all the docs in various places. On github, if you have a README.rst file in the root dir, it’ll be converted to nice-ish looking docs. (Sphinx is much better looking, plus can include module, class, and function documentation to boot, hence going through all this trouble).

So we need to point sphinx’s index.rst to the README.rst file in the root of the main repo. Turns out that relative path names don’t work in index.rst, so here’s a workaround:

Make a new file, sphinxdoc-test/docs/source/includeme.rst. In there, put an include directive pointing to the true``README.rst``. So includeme.rstshould look like this:

.. include:: ../../README.rst

Then in index.rst, add includeme to the toctree. So the relevant part of index.rst should look something like:

.. toctree::
:maxdepth: 2 includeme

OK, we should be done with the setup now.

Initial creation and commit workflow

Commit all code and README.rst (and any other doc source files) in the main repo, like always:

git add docs
git add README.rst
git commit -m "added docs and README.rst"

Then, when you’re ready to recreate the docs:

cd docs
make html
make latexpdf

Should probably add the newly built manual:

cd ..
git add manual.pdf
git commit -m "added manual.pdf"

Next, change to the gh-pages repo dir and commit the stuff that the make html command made:

cd ../sphinxdoc-test-docs
git add .
git commit -m "rebuilt docs"

And then publish the newly built docs:

git push origin gh-pages

Rinse and repeat. Of course, you could always add a task to the Makefile to do this building and committing docs, something like:

buildandcommithtml: html latexpdf

    cd $(BUILDDIR)/html; git add . ; git commit -m "rebuilt docs"; git push origin gh-pages

Anyway, now you can view your new pages on http://<user>.github.com/<repo>. So in this case, it’s http://daler.github.com/sphinxdoc-test.

Add a .nojekyll file

The last thing we have to do is add an empty file called .nojekyll in the docs repo. This tells github’s default parsing software to ignore the sphinx-generated pages that are in the gh-pages branch. Make sure you commit it, too:

cd sphinxdoc-test-docs/html (html目录添加nojekyll)
touch .nojekyll
git add .nojekyll
git commit -m "added .nojekyll"

Directory structure

So that we’re on the same page, the final directory structure looks like this:

sphinxdoc-test
|-- pymodule <-- whatever your normal python package dir structure is
| |-- somepythonmodule.py
| `-- othercode.py
|-- docs
| |-- Makefile <-- edited as described above
| `-- source
| |-- conf.py
| |-- includeme.rst <-- edited as described above
| `-- index.rst <-- edited as described above
|-- manual.pdf <-- created by running make latexpdf
`-- README.rst <-- where you do most of your writing sphinxdoc-test-docs
|-- doctrees <-- this dir is autogenerated, but not
| |-- environment.pickle commited to gh-pages
| |-- includeme.doctree
| |-- index.doctree
| `-- README.doctree
`-- html <-- The docs repo, on the gh-pages branch.
|-- genindex.html Everything under here is committed.
|-- includeme.html
|-- index.html
|-- objects.inv
|-- README.html
|-- search.html
|-- searchindex.js
|-- _sources
| |-- includeme.txt
| |-- index.txt
| `-- README.txt
`-- _static
|-- basic.css
|-- default.css
|-- doctools.js
|-- file.png
|-- jquery.js
|-- minus.png
|-- plus.png
|-- pygments.css
|-- searchtools.js
|-- sidebar.js
`-- underscore.js

Setting up cloned repos on another machine

The steps for setting this up on another machine are quite a bit simpler.

The only requirement is that the folder name that will hold the docs repo must have the same relative path name as is referred to in the Makefile. So if on one machine I had these repos in /data/repos/sphinxdoc-test and /data/repos/sphinxdoc-test-docs, I could have them as~/sphinxdoc-test-docs and ~/sphinxdoc-test respectively.

First set up the main repo; in this example I’m putting it right in my home directory. Cloning will automatically create a directory, so you don’t have to make one:

cd ~
git clone git@github.com:daler/sphinxdoc-test.git

OK, that’s done. Now to set up the docs repo. For this, just like for setting it up in the first place, you need to create a dir first (making sure it’s the same name referred to in the edited Makefile) and then change to it and clone the html part of the repo:

cd ~
mkdir sphinxdoc-test-docs
cd sphinxdoc-test-docs
git clone git@github.com:daler/sphinxdoc-test.git html

Now there’s a slight problem – in the newly cloned html dir, there only appears to be one branch and it’s the master branch:

git branch
# * master

The following command will create a local tracking branch to the gh-pages branch:

git checkout -b gh-pages remotes/origin/gh-pages

Now the directories are set up the same way they were in the original setup described above.

General workflow

Now that everything is set up, general workflow is to:

  • In the main repo:

    • edit and commit code as usual
    • document stuff in README.rst, commit it as usual
    • document stuff that will be in the documentation, but not on the main page, in other .rst files in thedocs directory.
    • change to docs dir and run make html to generate the html docs in your docs repo. This should not make any changes to the main repo, so you don’t have to commit again
    • if you’re making a PDF manual, make that too with make latexpdf. Depending on where you’re putting the PDF manual, you’ll have to commit and push the new version as well.
    • git push
    • change to the docs repo
  • Next, in the docs repo:

    • change to the docs repo (make sure you’re in the html dir)
    • check to make sure you’re on the gh-pages branch
    • git commit -a -m "rebuilt docs"
    • git push origin gh-pages

Done!

另外可参考:http://hi.baidu.com/limodou/item/bffbe725413abd0977272cf6

git遇到的问题:http://www.cnblogs.com/renkangke/archive/2013/05/31/conquerAndroid.html

文档整体解决方案(readthedocs、github 、sphinx)使用的更多相关文章

  1. IIS6(Win2003) 使用.net 4.0 后,默认文档失效解决方案。

    IIS6(Win2003) 使用.net framework 4.0 后,默认文档失效解决方案. 用.net framework 4.0 开发的WEB项目,但放到iis6 中无法使用默认文档,状况如下 ...

  2. Atitit 数据库表文档生成解决方案

    Atitit 数据库表文档生成解决方案 1.1. Sql dml文件结构法 最快速1 1.2. Sql法+sp存储过程 (表格式样)1 1.3. Navicate uml法 (uml格式)2 1.4. ...

  3. IIS7多域名绑定同一物理目录,设置不同默认文档的解决方案

    转载自 http://zzstudy.offcn.com/archives/6159 如何解决IIS7多域名绑定同一物理目录,设置不同的默认文档的问题? 因为在一个物理目录下只有一个web.confi ...

  4. 使用dumi生成react组件库文档并发布到github pages

    周末两天玩了下号称西湖区东半球最牛逼的react文档站点生成工具dumi,顺带结合github pages生成了react-uni-comps文档站, 一套弄下来,感觉真香,现在还只是浅尝,高级的特性 ...

  5. Asp.Net在线预览Word文档的解决方案与思路

    前几天有个老项目找到我,有多老呢?比我工作年限都长,见到这个项目我还得叫一声前辈. 这个项目目前使用非常稳定,十多年了没怎么更新过,现在客户想加一个小功能:在线预览Word文档. 首先想到的是用第三方 ...

  6. 使用readthedocs 发布 sphinx doc文档

    readthedocs 是由社区驱动的开源sphinx doc 托管服务,我们可以用来方便的构建以及发布文档 这是一个简单的demo 项目,使用了用的比较多的sphinx_rtd_theme 主题,主 ...

  7. python文档生成工具:pydoc、sphinx;django如何使用sphinx?

    文档生成工具: 自带的pydoc,比较差 建议使用sphinx 安装: pip install sphinx 安装主题: 由各种主题,我选择常用的sphinx_rtd_theme pip instal ...

  8. 使用ReadtheDocs托管技术文档

    ReadtheDocs Read the Docs非常适合写软件文档以及编写一些教程.电子书之类.对于一些一两篇文章就能写清楚的可以记笔记或写博客, 但是如果要写成一个系列的,不如写成一本书的形式,更 ...

  9. sphinx生成cakephp文档

    cakephp的文档是用一个叫sphinx程序生成的 这个程序是python写的,所以我们要用sphinx本机必须先装python. 编译过程在Ubuntu下进行,默认Ubuntu已经安装了pytho ...

随机推荐

  1. rsyslogd配置文件详解

    非常详细的rsyslogd配置文件解析 rsyslog服务和logrotate服务=========================================================== ...

  2. 【AIX】AIX 6.1 “C compiler cc is not found”问题的解决方案

    一.问题的由来 前几天在AIX中安装部署 nginx-1.4.1,报如下错误: # cd nginx-1.4.1 # ./configure checking for OS  + AIX 1 0004 ...

  3. ubuntu 配置android开发环境

    本文的下载地址都是androiddevtools,下载地址:http://www.androiddevtools.cn/ 一.安装android sdk 解压文件,全部放到/opt/Java/andr ...

  4. 2015-09-21CSS:引入方式、选择器、注释、文字样式

    1.HTML中引入CSS的方式 HTML中引入CSS的样式有4种:行内式.内嵌式.导入式和链接式. ⑴行内式 行内式是在标记的style属性中设定CSS样式.这种方式没有体现出CSS的优势,不推荐使用 ...

  5. struts2与spring集成时,关于class属性及成员bean自动注入的问题

    http://blog.csdn.net/sun_zhicheng/article/details/24232129

  6. 安装php时,make步骤报错make: *** [sapi/fpm/php-fpm] Error 1

    安装PHP过程中,make步骤报错:(集中网络上各种解决方法) (1)-liconv -o sapi/fpm/php-fpm /usr/bin/ld: cannot find -liconv coll ...

  7. 015_xml_函数

    015_xml_函数 --环境准备******************************************************************* USE test --f:/t ...

  8. 查看library_cache 库缓冲区的命中率

    关于library cache的命中率:    SQL> desc V$librarycache    NAMESPACE                                     ...

  9. 微信 token 验证

    package org.sxl.weixin; import java.security.MessageDigest; import java.security.NoSuchAlgorithmExce ...

  10. cocopods安装

    CocoaPods安装和使用教程 Code4App 原创文章.转载请注明出处:http://code4app.com/article/cocoapods-install-usage 目录 CocoaP ...