Host documentation on localhost (with nginx)
Create a configuration file (for example nginx.conf) in your project root directory.
Add the following content:
1server { 2 listen 1050; 3 server_name localhost; 4 charset utf-8; 5 client_max_body_size 75M; 6 root "/path/to/project/_build"; 7 index index.html; 8}
Adjust the port (line 2), the root path (line 6; which is where the index.html of your build output resides).
Create a symlink of your configuration to your nginx configuration directory:
$ ln -s </path/to/my/application>/nginx.conf /usr/local/etc/nginx/init.d/<doc_project_name>.conf
$ ln -s </path/to/my/application>/nginx.conf /etc/nginx/sites-enabled/<doc_project_name>.conf
Restart nginx
$ nginx -c /usr/local/etc/nginx/nginx.conf
or restart as brew service via
$ brew services restart nginx
$ nginx /etc/init.d/nginx restart
Open
https://127.0.0.1:<PORT>, using the port specified in your configuration, in your browser.
Host documentation on GitHub Pages
GitHub Pages is an alternative to host a Sphinx documentation, making it available from anywhere. GitHub provides the service for free for public repositories (make sure, the repository, containing the documentation, is publicly available).
Deploy from branch
Log into your GitHub account and open the documentation repository.
Create a new, empty branch (), named
gh-pagesand push it to the remote (here:origin):$ git switch --orphan gh-pages $ git commit --allow-empty "initial commit" $ git push origin gh-pages
Select . Here, select to set up a workflow yourself.
A new file (default:
main.yml) is created under.github/workflows/and presented in the editor. Change the name to a proper name, for examplebuild_publish_html.yml.In the editor, enter the action’s workflow. This shows a working example:
1name: "Pull Request Docs Build" 2on: [pull_request, push] 3 4jobs: 5 docs: 6 runs-on: ubuntu-latest 7 steps: 8 - uses: actions/checkout@v4 9 - uses: actions/setup-python@v5 10 with: 11 python-version: '3.11' 12 - name: Install dependencies 13 run: | 14 pip install -r requirements.txt 15 sudo apt-get update 16 sudo apt-get install -y pandoc 17 python -m sphinx build -b html source build 18 - uses: actions/upload-artifact@v1 19 with: 20 name: github-pages 21 path: /home/runner/work/AllMyNotes/AllMyNotes/build/ 22 - name: Commit HTML output to gh-pages 23 run: | 24 git clone https://github.com/horsewithnoname1985/AllMyNotes.git --branch gh-pages --single-branch gh-pages 25 cp -r ./build/* gh-pages/ 26 cd gh-pages 27 touch .nojekyll 28 git config --local user.email "action@github.com" 29 git config --local user.name "GitHub Action" 30 git add . 31 git commit -m "Update documentation" -a || true 32 - name: Push changes 33 uses: ad-m/github-push-action@master 34 with: 35 branch: gh-pages 36 directory: gh-pages 37 github_token: ${{ secrets.GITHUB_TOKEN }}
Adapt the workflow to your needs. In the upper form, it executes the following steps on a Linux virtual machine:
Checks out the repo’s sources
Installs Python 3.11
Install Python dependencies and pandoc
Build the documentation as HTML
Upload the HTML output as build artifact to this run
Commit and the HTML output to the
gh-pagesbranch
Select Commit changes… to commit the workflow file. As the workflow defines, that a runs is triggered on every push, this will trigger a workflow run.
Go to Actions and check the workflow (here: Pull Request Docs Build) completes successfully.
If so, go back Code and select the gh-pages branch, which should contain all HTML output files.
Select .
Under , select
Deploy from a branch. Below, under Branch, make sure thegh-branchis selected and/ (root)is used as the pages parent directory (asindex.htmlis on the branches root directory) and save the selection.Refresh the page. On the top, there should now appear a box, containing the message
Your site is live at .... If not, enter the following URL into your browser:https://<github_username>.github.io/<repository_name>/
This should open your documentation.