Task: Make a documentation website for a project
Okay. You have a project. You want to make a webpage and a documentation. Here is one way to do it.
For the webpage, you can use the GitHub Pages service. For creating the documentation, you can use SphinX which autogenerates a documentation from the docstrings.
Result
Check the documentation page for my tflow
project.
Making a simple website with Github Pages
Github pages provides a simple way to make a website using Markdown.
With a pre-existing repository,
- On Terminal,
cd
to your repository. - Create a branch in your repo for your GitHub Page:
git checkout -b gh-pages
- Create a markdown file called
index.md
. - Push it to GitHub by using
git push origin gh-pages
Tips: Making a website may take a few minutes to complete. Make sure to clear cache when you renew the webpage.
It is not a bad idea to separate a repo about the project webpage and the documentation.
References:
Making a code documentation webpage using SphinX
To do this, you need to install SphinX.
- Install SphinX:
pip install sphinx
cd your_project_directory
sphinx-quickstart docs
… This makes a directory calleddocs
and files like aconf.py
.- If you are using numpy or Google style docstrings, you must enable
napoleon
in the Sphinxconf.py
:
… You can specify the SphinX theme inconf.py
likehtml_theme = "sphinx_book_theme"
… For my project, I decided to use a third-party themesphinx_book_theme
which you can install usingpip install sphinx-book-theme
.
See Sphinx Book Theme for more details.
# conf.py
# Add napoleon to the extensions list
extensions = ['sphinx.ext.napoleon']
# Specify the theme
html_theme = "sphinx_book_theme"
- Build your API documentation:
sphinx-apidoc -f -o docs/source your_project_directory
… -f: overwrite existing files, -o: output directory - Edit your
index.rst
file
… This will be the main page of your documentation.
… The format is reStructuredText. Quick reference - Generate html files:
make html
This should create a directory calleddoctrees
andbuild
. - GitHub recognizes your_project_directory/index.md as a default project website. Change this.
… Go to your repo webpage on GitHub, go to “Settings”->”Pages”, and set source to “gh-pages/docs”
… GitHub Pages uses Jekyll as a default tool to make a website. You must disable it by creating an empty file called
your_project_directory/docs/.nojekyll
- Commit and push the changes.
When you update the documentation, repeat Steps 5-9 except Step 8.
References:
Step1-3: Sphinx Quickstart Step4: Sphinx Google Style