github_pages.rst 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. .. _github_pages:
  2. =======================
  3. Hosting on GitHub Pages
  4. =======================
  5. You use `GitHub Pages <github_pages_website_>`_ to host documentation generated by ``sphinx-multiversion``.
  6. Setting up the ``gh-pages`` Branch
  7. ==================================
  8. First, you need to create a ``gh-pages`` branch and disable Jekyll.
  9. .. code-block:: bash
  10. git checkout --orphan gh-pages
  11. touch .nojekyll
  12. git add .nojekyll
  13. git commit -m "Disable Jekyll"
  14. Then, switch back to the branch you were on and build the documentation using ``sphinx-multiversion``:
  15. .. code-block:: bash
  16. mkdir html
  17. sphinx-multiversion docs/ html/
  18. If everything worked fine, you now need to switch back to your ``gh-pages`` branch and commit the data there:
  19. .. code-block:: bash
  20. git checkout gh-pages
  21. for dirname in html/*; do mv "html/$dirname" "$dirname" && git add "$dirname"; done
  22. git commit -m "Added HTML docs"
  23. git push origin gh-pages
  24. Now your documentation should already be online.
  25. You can navigate to ``https://username.github.io/reponame/master/`` to see the documentation for the master branch.
  26. Redirecting from the Document Root
  27. ==================================
  28. You can easily redirect users that type ``https://username.github.io/reponame/`` into their addressbar to the documentation for any version you like.
  29. Just add a :file:`index.html` file to the root directory of your ``gh-pages`` branch:
  30. .. code-block:: html
  31. <!DOCTYPE html>
  32. <html>
  33. <head>
  34. <title>Redirecting to master branch</title>
  35. <meta charset="utf-8">
  36. <meta http-equiv="refresh" content="0; url=./master/index.html">
  37. <link rel="canonical" href="https://username.github.io/reponame/master/index.html">
  38. </head>
  39. </html>
  40. Automating documentation builds with Travis CI
  41. ==============================================
  42. You can also automate versioned builds using Travis CI.
  43. To do that, add this to your :file:`.travis.yml` file:
  44. .. code-block:: yaml
  45. script:
  46. # Build documentation
  47. - mkdir html
  48. - sphinx-multiversion docs/ html/
  49. before_deploy:
  50. # Add .nojekyll file and redirect from docroot to the sphinx output dir
  51. - touch html/.nojekyll
  52. - cp assets/gh-pages-redirect.html html/index.html
  53. deploy:
  54. # Only deploy the sphinx output dir as gh-pages branch
  55. - provider: pages
  56. skip_cleanup: true
  57. github_token: $GITHUB_TOKEN
  58. keep_history: false
  59. local_dir: html
  60. .. seealso::
  61. For details, please have a look at the `GitHub Pages Deployment documentation for Travis CI <travis_gh_pages_deployment_>`_.
  62. .. _github_pages_website: https://pages.github.com/
  63. .. _travis_gh_pages_deployment: https://docs.travis-ci.com/user/deployment/pages/