文檔生成器 mkdocs

mkdocs 是 Python 一個對 Markdown 很是友好的文檔生成器,中文文檔地址php

使用 mkdocs 咱們能夠用md 編寫本身的文檔,並且能夠免費部署到 GitHub 。css

安裝

pip install mkdocshtml

使用

λ mkdocs.exe new mydoc
INFO    -  Creating project directory: mydoc
INFO    -  Writing config file: mydoc\mkdocs.yml
INFO    -  Writing initial docs: mydoc\docs\index.md
λ cd mydoc\

d:\code\mydoc
λ ls
docs/  mkdocs.yml

d:\code\mydoc
λ 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/

clipboard.png

編輯

vi docs/index.md
把 command 改成中文 命令 記得把文件改成 utf8 編碼,不然python

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 <bound method LiveReloadHandler.poll_tasks of <class 'livereload.handlers.LiveReloadHandler'>>

刷新看到效果git

clipboard.png

vi mkdocs.yml
把site_name 的 my docs 改成中文 個人文檔github

clipboard.png

添加頁面

vi about.md
vi mkdocs.ymlweb

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

而後報錯了算法

INFO    -  Building documentation...
ERROR   -  Config value: 'pages'. Error: Invalid pages config. {<class 'list'>} {<class 'str'>, <class 'dict'>}
[E 190529 09:57:45 ioloop:801] Exception in callback <bound method LiveReloadHandler.poll_tasks of <class 'livereload.handlers.LiveReloadHandler'>>
    Traceback (most recent call last):
      File "d:\python\lib\site-packages\tornado\ioloop.py", line 1229, in _run
        return self.callback()
      File "d:\python\lib\site-packages\livereload\handlers.py", line 69, in poll_tasks
        filepath, delay = cls.watcher.examine()
      File "d:\python\lib\site-packages\livereload\watcher.py", line 105, in examine
        func()
      File "d:\python\lib\site-packages\mkdocs\commands\serve.py", line 107, in builder
        site_dir=site_dir
      File "d:\python\lib\site-packages\mkdocs\config\base.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:\python\lib\site-packages\mkdocs (Python 3.7)

clipboard.png

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

site_name: 個人文檔
nav:
- 主頁: 'index.md'
- 關於: 'about.md'
theme: readthedocs

clipboard.png

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:\code\mydoc\site

d:\code\mydoc
λ ls
docs/  mkdocs.yml  site/

一段時間後, 可能有文件被從源碼中移除了, 可是相關的文檔仍殘留在 site 目錄中. 在構建命令中添加 --clean 參數便可移除這些文檔.

$ mkdocs build --clean

λ cd site\

d:\code\mydoc\site
λ ls
404.html  css/    img/        js/      search.html  sitemap.xml.gz
about/    fonts/  index.html  search/  sitemap.xml

d:\code\mydoc\site
λ 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:\code\markdown_doc (master)
λ ls
README.md

d:\code\markdown_doc (master)
λ mkdir docs

d:\code\markdown_doc (master)
λ cd docs\

d:\code\markdown_doc\docs (master)
λ mkdocs.exe new .
INFO    -  Writing config file: .\mkdocs.yml
INFO    -  Writing initial docs: .\docs\index.md

d:\code\markdown_doc\docs (master)
λ mkdocs build
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: d:\code\markdown_doc\docs\site

d:\code\markdown_doc\docs (master)
λ echo "site/" >> .gitignore

d:\code\markdown_doc\docs (master)
λ mkdocs gh-deploy --clean
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: d:\code\markdown_doc\docs\site
WARNING -  Version check skipped: No version specificed in previous deployment.
INFO    -  Copying 'd:\code\markdown_doc\docs\site' 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... 看到效果了。

clipboard.png

資源

Python 中文數據結構和算法教程
相似gitbook生成文檔工具
Python Web 入坑指南
mkdocs配置
文檔查詢工具
支持數學公式
git配置多個SSH Key

公衆號:蘇生不惑

掃描二維碼關注

相關文章
相關標籤/搜索