资讯专栏INFORMATION COLUMN

文档生成器 mkdocs

hosition / 2750人阅读

摘要:是一个对非常友好的文档生成器,中文文档地址使用我们可以用编写自己的文档,而且可以免费部署到。资源中文数据结构和算法教程类似生成文档工具入坑指南配置文档查询工具支持数学公式配置多个公众号苏生不惑

mkdocs 是 Python 一个对 Markdown 非常友好的文档生成器,中文文档地址

使用 mkdocs 我们可以用md 编写自己的文档,而且可以免费部署到 GitHub 。

安装

pip install mkdocs

使用
λ mkdocs.exe new mydoc
INFO    -  Creating project directory: mydoc
INFO    -  Writing config file: mydocmkdocs.yml
INFO    -  Writing initial docs: mydocdocsindex.md
λ cd mydoc

d:codemydoc
λ ls
docs/  mkdocs.yml

d:codemydoc
λ mkdocs serve
INFO    -  Building documentation...
INFO    -  Cleaning site directory
[I 190528 20:32:49 server:296] Serving on http://127.0.0.1:8000
[I 190528 20:32:49 handlers:62] Start watching changes
[I 190528 20:32:49 handlers:64] Start detecting changes
[I 190528 20:33:06 handlers:135] Browser Connected: http://127.0.0.1:8000/

编辑

vi docs/index.md
把 command 改为中文 命令 记得把文件改为 utf8 编码,否则

INFO    -  Building documentation...
ERROR   -  Encoding error reading file: index.md
ERROR   -  Error reading page "index.md": "utf-8" codec can"t decode byte 0xc3 in position 92: invalid continuation byte
[E 190528 20:38:45 ioloop:801] Exception in callback >

刷新看到效果

vi mkdocs.yml
把site_name 的 my docs 改为中文 我的文档

添加页面

vi about.md
vi mkdocs.yml

site_name: 文档
pages:
- [index.md, Home]
- [about.md, About]

然后报错了

INFO    -  Building documentation...
ERROR   -  Config value: "pages". Error: Invalid pages config. {} {, }
[E 190529 09:57:45 ioloop:801] Exception in callback >
    Traceback (most recent call last):
      File "d:pythonlibsite-packages	ornadoioloop.py", line 1229, in _run
        return self.callback()
      File "d:pythonlibsite-packageslivereloadhandlers.py", line 69, in poll_tasks
        filepath, delay = cls.watcher.examine()
      File "d:pythonlibsite-packageslivereloadwatcher.py", line 105, in examine
        func()
      File "d:pythonlibsite-packagesmkdocscommandsserve.py", line 107, in builder
        site_dir=site_dir
      File "d:pythonlibsite-packagesmkdocsconfigase.py", line 210, in load_config
        "Aborted with {0} Configuration Errors!".format(len(errors))
    mkdocs.exceptions.ConfigurationError: Aborted with 1 Configuration Errors!
λ mkdocs -V
mkdocs, version 1.0.4 from d:pythonlibsite-packagesmkdocs (Python 3.7)

查找到issue https://github.com/mkdocs/mkd...
https://www.mkdocs.org/user-g...
改为

site_name: 我的文档
nav:
- 主页: "index.md"
- 关于: "about.md"
theme: readthedocs

https://markdown-docs-zh.readthedocs.io/zh_CN/latest/

原来是中文文档过时了。

生成秘钥

cd ~/.ssh
ssh-keygen -t rsa -C “mysusheng@gmail.com”
这里不要一路回车,我们自己手动填写保存路径
vi config

Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/mysusheng
λ ssh -T git@github.com
Hi sushengbuhuo! You"ve successfully authenticated, but GitHub does not provide shell access.
站点生成
λ mkdocs build
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: d:codemydocsite

d:codemydoc
λ ls
docs/  mkdocs.yml  site/

一段时间后, 可能有文件被从源码中移除了, 但是相关的文档仍残留在 site 目录中. 在构建命令中添加 --clean 参数即可移除这些文档.

$ mkdocs build --clean

λ cd site

d:codemydocsite
λ ls
404.html  css/    img/        js/      search.html  sitemap.xml.gz
about/    fonts/  index.html  search/  sitemap.xml

d:codemydocsite
λ php -S localhost:8000
PHP 7.1.13 Development Server started at Wed May 29 10:17:19 2019
Listening on http://localhost:8000
部署到GitHub
λ git clone https://github.com/sushengbuhuo/markdown_doc
Cloning into "markdown_doc"...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.

d:code
λ cd markdown_doc

d:codemarkdown_doc (master)
λ ls
README.md

d:codemarkdown_doc (master)
λ mkdir docs

d:codemarkdown_doc (master)
λ cd docs

d:codemarkdown_docdocs (master)
λ mkdocs.exe new .
INFO    -  Writing config file: .mkdocs.yml
INFO    -  Writing initial docs: .docsindex.md

d:codemarkdown_docdocs (master)
λ mkdocs build
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: d:codemarkdown_docdocssite

d:codemarkdown_docdocs (master)
λ echo "site/" >> .gitignore

d:codemarkdown_docdocs (master)
λ mkdocs gh-deploy --clean
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: d:codemarkdown_docdocssite
WARNING -  Version check skipped: No version specificed in previous deployment.
INFO    -  Copying "d:codemarkdown_docdocssite" to "gh-pages" branch and pushing to GitHub.
INFO    -  Your documentation should shortly be available at: https://sushengbuhuo.github.io/markdown_doc/

就是把site目录代码上传到github gh-pages分支了.

浏览器访问 https://sushengbuhuo.github.i... 看到效果了。

资源

Python 中文数据结构和算法教程
类似gitbook生成文档工具
Python Web 入坑指南
mkdocs配置
文档查询工具
支持数学公式
git配置多个SSH Key

公众号:苏生不惑

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/43938.html

相关文章

  • 不同用户python path 权限问题

    摘要:问题背景用户可以运行但运行则下列错误经过排查,发现是在某些的权限问题解决方法查看使用的代码可知,使用的是查看路径切换到用户然后在命令行运行路径的权限修改路径的权限发现有写目录是没有执行权限的。 问题背景 root 用户可以运行pip install mkdocs但gitlab-runner 运行pip install mkdocs 则下列错误 pip install mkdocs Tr...

    dack 评论0 收藏0
  • 蠎周刊 2015 年度最赞

    摘要:蠎周刊年度最赞亲俺们又来回顾又一个伟大的年份儿包去年最受欢迎的文章和项目如果你错过了几期就这一期不会丢失最好的嗯哼还为你和你的准备了一批纪念裇从这儿获取任何时候如果想分享好物给大家在这儿提交喜欢我们收集的任何意见建议通过来吧原文 Title: 蠎周刊 2015 年度最赞Date: 2016-01-09 Tags: Weekly,Pycoder,Zh Slug: issue-198-to...

    young.li 评论0 收藏0
  • 终于不用再苦逼地写文档了!教你如何生成可调试的API文档

    摘要:本文写的是什么平时总要写文档。所以,我所希望的事,就是在完成代码后,可以费很少的力气,就生成一个像上文中所说的可调试文档。我们接下来要做两件事生成文档文档是可调试的文档。一句话流程点击生成按钮,生成类的文档。 本文写的是什么? 平时总要写文档。不写,代码无法维护,所以不得不写。但是写文档费时费力,更可怕的是写完了读起来还很费劲,束之高阁,总感觉时间浪费掉了,真是苦不堪言。 一直以来深受...

    SegmentFault 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<