Publishing HTML Files
This document provides step-by-step instructions for publishing the HTML documentation of your Python project to:
ReadTheDocs.org
GitHub Pages
Prerequisites
Generated HTML files from Sphinx (_build/html directory).
A GitHub account.
ReadTheDocs account (if using ReadTheDocs.org).
Publishing to ReadTheDocs.org
Step 1: Create a ReadTheDocs Project
Log in to your ReadTheDocs account at https://readthedocs.org/.
Click on + Import a Project.
Select the Connect to GitHub option and authorize ReadTheDocs to access your repositories.
Choose your project repository from the list or add a new repository.
Step 2: Configure ReadTheDocs
Navigate to your project’s settings in ReadTheDocs.
Under the Admin > Advanced Settings section, specify the following: - Python configuration file: docs/conf.py (or the location of your conf.py file). - Documentation type: Sphinx HTML. - Requirements file: requirements.txt (if you have additional Python dependencies).
Save the changes.
Step 3: Trigger a Build
Trigger a build by clicking the Build Version button on the project’s dashboard.
Once the build is complete, your documentation will be live at <project-name>.readthedocs.io.
Step 4: Maintain Updates
Push changes to your GitHub repository.
ReadTheDocs automatically rebuilds the documentation on new commits.
Publishing to GitHub Pages
Step 1: Create a GitHub Repository
Go to https://github.com/.
Click on + New Repository.
Name the repository (e.g., sphinx-dempo-app).
Set the repository as Public.
Click Create Repository.
Step 2: Add HTML Files to the Repository
Navigate to your project’s _build/html directory.
Copy the entire contents of the html directory.
Clone the GitHub repository locally:
git clone https://github.com/oogeo/readthedocs-demo-app.git
Paste the HTML files into the cloned repository.
Add, commit, and push the files to GitHub:
Step 2.1 Push content from local project directory to the remote ‘master ‘
Navigate to your local project directory
cd /path/to/your/local/project
Initialize a GIT repository locally
git init
Add remote repository
git remote add origin https://github.com/oogeo/readthedocs-demo-app.git
Add local changes
git add .
Commit local changes
git commit -m "Initial commit with existing local project content"
Set remote ‘master’ branch and upstream branch
git branch -M master
Push your local changes to the remote repository:
git push -u origin master --force
Warning
Using –force will overwrite the content in the remote repository. Make sure you really want to replace the remote content with your local content before proceeding. If you’re working with collaborators or need to preserve the existing history, a different approach involving merging or rebasing should be used.
Step 3: Enable GitHub Pages
Go to your repository on GitHub.
Navigate to Settings > Pages.
Under Source, select the main branch and / (root) folder.
Click Save.
Your documentation will be live at https://<username>.github.io/project-docs/.
Step 4: Maintain Updates
Update the _build/html directory in your local repository.
Push changes to GitHub:
git add . git commit -m "Update documentation" git push origin main
Tips for Managing Documentation
Always generate updated HTML files using Sphinx before publishing.
Keep the conf.py and requirements.txt files updated with any project changes.
Use meaningful commit messages for documentation updates.
Further Assistance
ReadTheDocs documentation: https://docs.readthedocs.io/
GitHub Pages guide: https://docs.github.com/en/pages