How to Host Your Sphinx Documentation on GitHub (2024)

How to Host Your Sphinx Documentation on GitHub (3)

Did you ever know that GitHub could host your static pages? If you didn’t, well you are not alone. GitHub provides GitHub Pages to host your documentation which contains static pages.

GitHub Pages is available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server.

From GitHub Pages

https://docs.github.com/en/pages

Let’s assume you already have sphinx documentation generated in a html format. If you don't know how to get started, please refer here.

By default, your GitHub pages will be disabled. Please enable them.

  1. Go to your GitHub repository
  2. Open the Settings tab and select Pages from the sidebar
  3. From the source section, select the branch wherever you have pushed the documentation code.
  4. Ideally, you could create a separate branch for your documentation say gh-pages or any name you see fit.
  5. Commit the code and select the branch in the source section.
How to Host Your Sphinx Documentation on GitHub (4)

6. If you create a branch called gh-pages, GitHub will automatically recognize the documentation there and show it for you.

How to Host Your Sphinx Documentation on GitHub (5)

7. Unfortunately, you can only point to any of the root folders or the docs folder. Not any of the child folders inside them.

8. So, the index.html file should be available at the top level of the directory you are hosting. Only then your GitHub will be able to host them. Else you may get a build failure or 404 errors.

9. After saving the configuration, your page should be available at the mentioned location.

There are few pitfalls while hosting your sphinx documentation, especially on GitHub if you use the default sphinx configuration.

After hosting your documentation, if you run into 404 Page not found errors, most probably your GitHub pages is unable to find your index.html. Ensure that the index.html is available in the docs folder.

The default makefile looks like this.

The default build directory is named as _build and the built files are copied inside this folder. Since we have specified docs as the directory we have to do either of the following.

  1. Create a docs folder and copy the contents into the same (OR)
  2. Change the default build folder as docs in your makefile. If you have a make.bat file please remember to change there as well.

I would prefer the second option. Let’s change the build folder in the makefile and rebuild again.

$make html

Now the docs folder, will have the below contents.

--docs 
|--doctrees
|--html
|--index.html
|..

However, the index.html is still not inside the top level of docs folder. So we may have to add another index.html and write a redirection code to redirect to the index.html inside the HTML folder.

<meta http-equiv="refresh" content="0; url=./html/index.html" />

This should resolve the 404 errors.

https://github.com/sphinx-doc/sphinx/issues/3382

Sometimes, after hosting the documentation the selected theme may not be displayed properly. This could be because the default build folders are named with learning underscores [_build, _static].

How to Host Your Sphinx Documentation on GitHub (6)

That’s because GitHub by default publishes the pages through jekyll. We need to add an empty .nojekyll file in the docs directory or the root directory.

Now the page looks like below,

How to Host Your Sphinx Documentation on GitHub (7)

All the above mentioned code is available in the below repository

https://github.com/dineshkumarkb/sphinx-doc

The hosted document is available at

https://dineshkumarkb.github.io/sphinx-doc/html/index.html

How to Host Your Sphinx Documentation on GitHub (2024)

FAQs

How do I host my Sphinx documentation on GitHub? ›

Exercise - Deploy Sphinx documentation to GitHub Pages
  1. On GitHub go to “Settings” -> “Pages”.
  2. In the “Source” section, choose “Deploy from a branch” in the dropdown menu.
  3. In the “Branch” section choose “gh-pages” and “/root” in the dropdown menus and click save.

How to use Autodoc? ›

Autodoc
  1. Enable the extension. Open the conf.py file, and add sphinx. ...
  2. Insert the path to the module. Next, still in conf.py , insert the path to the module that you want to auto-document. ...
  3. Create the documentation file. ...
  4. Specify the modules you want the documentation to be generated. ...
  5. Add it to your toctree. ...
  6. Build the doc.

Can you make GitHub Pages private? ›

With access control for GitHub Pages, you can restrict access to your project site by publishing the site privately. A privately published site can only be accessed by people with read access to the repository the site is published from.

How do GitHub Pages work? ›

GitHub Pages is a static site hosting service that takes HTML, CSS, and JavaScript files straight from a repository on GitHub, optionally runs the files through a build process, and publishes a website.

How do I host a file on GitHub? ›

On GitHub.com, navigate to the main page of the repository. Above the list of files, select the Add file dropdown menu and click Upload files. Alternatively, you can drag and drop files into your browser. To select the files you want to upload, drag and drop the file or folder, or click choose your files.

How do I host my code on GitHub? ›

To host your code on GitHub
  1. Create a GitHub account.
  2. After logging in, on the left navigation pane, click 'New'. ...
  3. Give your project a name, description, choose if the repository is 'Public' or 'Private', and click Create Repository.
Sep 9, 2022

What is Autodoc in Python code? ›

autodoc directives. The reStructuredText files for your Python modules in docs/source do not contain the docstrings. Instead they just contain directives on how to build the corresponding page. They contain reStructuredText with directives to build the documentation from a particular Python module in your project.

What is Sphinx Apidoc? ›

sphinx-apidoc is a tool for automatic generation of Sphinx sources that, using the autodoc extension, document a whole package in the style of other automatic API documentation tools. MODULE_PATH is the path to a Python package to document, and OUTPUT_PATH is the directory where the generated sources are placed.

Is GitHub free to host? ›

GitHub Pages is GitHub's answer to project pages, and it allows you to serve any static website straight from your repository. Since GitHub pages support custom domains, you can host a static website on GitHub pages free of charge, with deploys straight from Git.

Is hosting a website on GitHub good? ›

It is a cloud-based platform that allows developers to host and manage their source code repositories, keep track of changes to their code, and collaborate with developers in the space. Aside from that, GitHub is also a great place for conveniently hosting static websites.

Is GitHub Pages not free anymore? ›

GitHub Pages is available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server.

Why not use GitHub Pages? ›

Limited customization: GitHub Pages uses Jekyll, a static site generator, which can be limiting if you want to do more advanced customization of your site. No support for server-side code: Because GitHub Pages generates static HTML files, you cannot use server-side languages like PHP or Ruby.

What is the difference between GitHub and GitHub Pages? ›

The purpose of GitHub Pages is to provide the GitHub user a way to create personal websites for themselves and websites for their projects / repositories. For each registered GitHub account (representing a user or an organization) you can register one User Page, but an unlimited Project pages.

Does GitHub Pages have limitations? ›

GitHub Pages sites are subject to the following usage limits: GitHub Pages source repositories have a recommended limit of 1 GB. Published GitHub Pages sites may be no larger than 1 GB. GitHub Pages deployments will timeout if they take longer than 10 minutes.

How do I host a JSON file on GitHub? ›

  1. Step 1: Create a GitHub Repository. If you don't already have a GitHub repository where you want to host your JSON file, follow these steps to create one: ...
  2. Step 2: Upload Your JSON File. ...
  3. Step 3: Enable GitHub Pages. ...
  4. Step 4: Access Your JSON File. ...
  5. Step 5: Share Your JSON File.
Sep 28, 2023

Can GitHub host PDFs? ›

GitHub supports rendering of PDF documents. Currently, links within PDFs are ignored.

How do I host a Jupyter notebook on GitHub? ›

How to Add Jupyter Notebook to GitHub
  1. Step 1: Create a GitHub account. ...
  2. Step 2: Create a new repository. ...
  3. Step 3: Install Git. ...
  4. Step 4: Clone your repository. ...
  5. Step 5: Create a Jupyter Notebook. ...
  6. Step 6: Save your Jupyter Notebook to your repository. ...
  7. Step 7: Add and commit your changes. ...
  8. Step 8: Push your changes to GitHub.
Jun 4, 2023

How do I host a WordPress plugin on GitHub? ›

Let's go through each step to ensure you are set up correctly.
  1. Sign up for GitHub.
  2. Install Git and GitHub.
  3. Install and configure the WP Pusher plugin.
  4. Connect WP Pusher to GitHub.
  5. Install WordPress theme or plugins.
  6. Create a GitHub Pages repository.
  7. Create a WordPress website.
  8. Convert to static HTML.
Jan 15, 2024

Top Articles
Latest Posts
Article information

Author: Sen. Emmett Berge

Last Updated:

Views: 6351

Rating: 5 / 5 (60 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Sen. Emmett Berge

Birthday: 1993-06-17

Address: 787 Elvis Divide, Port Brice, OH 24507-6802

Phone: +9779049645255

Job: Senior Healthcare Specialist

Hobby: Cycling, Model building, Kitesurfing, Origami, Lapidary, Dance, Basketball

Introduction: My name is Sen. Emmett Berge, I am a funny, vast, charming, courageous, enthusiastic, jolly, famous person who loves writing and wants to share my knowledge and understanding with you.