Sphinx is a tool for creating technical documentation.
It supports both reStructuredText and MyST Markdown.
In this tutorial I will show how to start a documentation site, enable Markdown support, install the Book theme (my personal favorite) and deploy it as a static site with Appliku.
Requirements¶
For this tutorial you need:
- You need to have Python 3.11 or higher installed on your computer.
- git
- GitHub account
- Appliku Account
Repository:¶
Source code is available on GitHub appliku/sphinxtutorial
Create a sphinx project¶
Create environment and install dependencies
mkdir sphinxtutorial
cd sphinxtutorial
python3 -m venv env
source env/bin/activate
pip install sphinx myst-parser sphinx-book-theme
pip freeze > requirements.txt
Start a project:
sphinx-quickstart --sep -a "Author Name" -p "Sphinx Tutorial" -l en -r "" .
Create .gitignore
file
env/
.idea/
__pycache__/
*.py[cod]
*$py.class
.vscode/
.DS_Store
.AppleDouble
.LSOverride
build/
in source/conf.py
edit extensions and theme:
extensions = ['myst_parser']
html_theme = 'sphinx_book_theme'
Since we plan to use Markdown, let's remove source/index.rst
file and create source/index.md
# Sphinx Tutorial
Welcome to our amazing Sphinx Tutorial
```{toctree}
:maxdepth: 2
:caption: Contents
```
Now you can go back to terminal and type make html
(python environment should be activated already).
This will generate our html code in build/html
directory.
Open the file in the browser: build/html/index.html
Let's see how navigation for other pages will work.
In the source
directory create a file about.md
# Hello, I am author of this site
Save it. Now in the index.md
file add this page to toctree
# Sphinx Tutorial
Welcome to our amazing Sphinx Tutorial
```{toctree}
:maxdepth: 2
:caption: Contents
about
```
And now run make html
again.
Back to the browser, refresh the page.
You can see the link to the about
page. Click on it.
Commit and push to Github¶
In the terminal type:
git init
git add .
git commit -m"Initial commit"
Now go to GitHub.com/new and create a new repository.
Since repository is empty, GitHub offers some commands to push the code. We need the git remote add origin
, select and copy the line, paste in the terminal and run it.
Now type
git push -u origin master
and you can see that the code is pushed to your GitHub repository.
Deploy Sphinx Documentation site¶
Go to Appliku dashboard, create an account if you don't have one already.
Create and add a server for Sphinx Documentation Site¶
Add an Ubuntu or a Debian server from a cloud provider of your choice, if you haven't already.
Here are guides for adding servers from different cloud providers:
- Deploy Django on Hetzner
- Deploy Django on Digital Ocean Droplet
- Deploy Django on AWS EC2 Instance
- Deploy Django on Linode
- Deploy Django on Azure Virtual machine
- Deploy Django on Google Cloud Platform Virtual Machine
Create a static site from GitHub repository¶
After you have created a server, go to the "Applications" page and create a new application from GitHub repository.
Give application a name, select the repository, branch and a server. Don't forget to check "This is a static site".
Go to settings
On the "build settings" tab you need to have these settings:
- Base Docker Image: Python 3.12
- build command:
make html
- output directory:
build/html
Click "Save Changes" and click "Deploy Now"
Click on the application name to get to the app overview page. When the deployment is finished click on "Open App" and the domain name.
Congratulations, our Sphinx documentation site is deployed!