GitHub allows web pages for projects, and a personal page. Your personal page is kept in a special repository which must be the same as your username. This personal web page will reside by default in https://username.github.io. You can of course have a domain name redirect to whatever you want. The project web pages are by defaulted served as https://username.github.io/repository where repository is the name of your project (repository name).
The instructions on how to proceed are here. If you want to use Sphinx, the instructions are slightly different. I will summarize here how to set up a web page for a project using Sphinx. The instructions are almost identical for a personal web page, just use username instead of repository instead.
Let's start with an empty project called obm.
create the project repository as instructed by GitHub. Then in your local computer, create a directory called docs inside your project's root directory. This is were the web pages files will reside. Since we want to use Sphinx, we need to disable jekyll of GitHub. This is done by placing a file called .nojekyll
inside the web root directory. When this file is present, GitHub will serve index.html directly. (Note: This is also offered by Sphinx quickstart script, but it is better done here, now)
mkdir docs
cd docs
touch .nojekyll
git add .nojekyll
git commit -m "Disable jekyll"
git push
Now back to the GitHub page. Go to the settings of your project.
If you have followed the GitHub recommendations when creating the project, you will have a main branch. We have to tell the GitHub that this project will have a web page, it will be in the docs directory, and main branch. This is done in Settings->Options->GitHub Pages.
Now, the Sphinx.
Sphinx is a tool that makes it easy to create intelligent and beautiful documentation. Basically you can write documentation like you are writing code, and it is very coder friendly. It's web page is here.
First, you need to install Sphinx. The documentation for various systems is here. I am using PopOs, so I go with a simple
sudo apt install python3-sphinx
Once installed, initialize the Sphinx in the project's root directory. There is an easy startup script for that which is documented here.
mkdir docsrc
cd docsrc
sphinx-quickstart
Here is the full script settings I did, as an example
Welcome to the Sphinx 1.8.5 quickstart utility.
Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).
Selected root path: .
You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
"source" and "build" directories within the root path.
> Separate source and build directories (y/n) [n]: y
Inside the root directory, two more directories will be created; "_templates"
for custom HTML templates and "_static" for custom stylesheets and other static
files. You can enter another prefix (such as ".") to replace the underscore.
> Name prefix for templates and static dir [_]:
The project name will occur in several places in the built documentation.
> Project name: obm
> Author name(s): obm
> Project release []:
If the documents are to be written in a language other than English,
you can select a language here by its language code. Sphinx will then
translate text that it generates into that language.
For a list of supported codes, see
http://sphinx-doc.org/config.html#confval-language.
> Project language [en]:
The file name suffix for source files. Commonly, this is either ".txt"
or ".rst". Only files with this suffix are considered documents.
> Source file suffix [.rst]:
One document is special in that it is considered the top node of the
"contents tree", that is, it is the root of the hierarchical structure
of the documents. Normally, this is "index", but if your "index"
document is a custom template, you can also set this to another filename.
> Name of your master document (without suffix) [index]:
Indicate which of the following Sphinx extensions should be enabled:
> autodoc: automatically insert docstrings from modules (y/n) [n]: y
> doctest: automatically test code snippets in doctest blocks (y/n) [n]: y
> intersphinx: link between Sphinx documentation of different projects (y/n) [n]: y
> todo: write "todo" entries that can be shown or hidden on build (y/n) [n]: y
> coverage: checks for documentation coverage (y/n) [n]: y
> imgmath: include math, rendered as PNG or SVG images (y/n) [n]: n
> mathjax: include math, rendered in the browser by MathJax (y/n) [n]: y
> ifconfig: conditional inclusion of content based on config values (y/n) [n]: n
> viewcode: include links to the source code of documented Python objects (y/n) [n]: y
> githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]: y
A Makefile and a Windows command file can be generated for you so that you
only have to run e.g. 'make html' instead of invoking sphinx-build
directly.
> Create Makefile? (y/n) [y]: y
> Create Windows command file? (y/n) [y]: y
Creating file ./source/conf.py.
Creating file ./source/index.rst.
Creating file ./Makefile.
Creating file ./make.bat.
Finished: An initial directory structure has been created.
You should now populate your master file ./source/index.rst and create other documentation
source files. Use the Makefile to build the docs, like so:
make builder
where "builder" is one of the supported builders, e.g. html, latex or linkcheck.
This script creates the all important conf.py
where all the settings (such as the theme) of the web page resides. The site is already populated with an example, so it is ready to be built, however, a slight modification to Makefile
is handy, so that it copies the output to docs directory automatically
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
github:
@make html
cp -a build/html/. ../docs
The last "github" part compiles the documents in the source directory, and copies the relevant files from build/html to the docs
Before doing a make github , let's add, commit and push the files first. Go to the root
git add docsrc/ --all
git commit -m "Sphinx source"
git push
This will push only the sources. Now, to compile and push the web page itself.
cd docsrc
make github
cd ..
git add docs/ -all
git commit -m "Web page update"
git push
Give GitHub some time to refresh, and the project webpage is ready to go.
Notes:
- You might want to add a build directory to your .gitignore
- The markup language reStructuredText is explained here.